Sizing Framework

Environment:VC++ 6.0, NT 4.0, Win95/98, W2K

Introduction

The WTL possibilities to build sizeable graphical user interface exists but was not fitting my needs so I decided to port the excellent framework from Paul DiLascia 'Windows UI: Our WinMgr Sample Makes Custom Window Sizing Simple' published in the July 2001 issue of MSDN Magazine. To understand all the principle of the framework, please read the original article.

The port was almost straightforward. I just added the gripper to the dialog.

Usage

To use the framework you need first to add those files to your project:
  • WinMgr.h
  • WinMgr.cpp
  • WinRect.cpp
  • SizeableDlg.h

Your dialog needs then to inherit from the class CDialogSizeable like this:

class CTestDlg : 
    public CDialogSizeable<CTestDlg>,
    public CDialogImpl<CTestDlg>

In the OnInitDialog() event handler, add as first line the following:

LRESULT CTestDlg::OnInitDialog( HWND hwnd, LPARAM  lParam)
{
    BOOL bRet = 
       CDialogSizeable<CTestDlg>::OnInitDialog(hwnd,
                                                     lParam);
   ...
}

Add the following macro to your main message map:

BEGIN_MSG_MAP_EX(CTestDlg)
    ...
    MESSAGE_HANDLER_EX(WM_WINMGR, OnWinMgr)
    ...
END_MSG_MAP()

And the the method to your dialog class (get more information on the original article):

///////////////////
// Handle WM_WINMGR: return min size for OK/Cancel buttons
//
LRESULT CTestDlg::OnWinMgr(UINT uMsg, WPARAM wp, LPARAM lp)
{
   ATLASSERT(lp);
   NMWINMGR& nmw = *(NMWINMGR*)lp;

   if ( nmw.code == NMWINMGR::GET_SIZEINFO )
   {
       if ( wp==IDOK || wp==IDCANCEL )
       {
           nmw.sizeinfo.szMin = m_szMinButton;
           return TRUE;
       }
   }
   return 0;
}

Build the Window map in the cpp file of your dialog class, i.e.:

BEGIN_WINDOW_MAP(TestDlgMap)
BEGINROWS(WRCT_REST,0,RCMARGINS(8,8))
 BEGINCOLS(WRCT_REST,0,0)
  BEGINROWS(WRCT_REST,4,RCMARGINS(-4,-4))
   RCTOFIT(IDC_STATIC1)
   RCSPACE(-4)
    BEGINROWS(WRCT_TOFIT,IDC_GROUP1,RCMARGINS(-8,-8))
     RCSPACE(-10)
    RCTOFIT(IDC_RADIO1)
    RCTOFIT(IDC_RADIO2)
    ENDGROUP()
  ENDGROUP()
  RCPERCENT(IDC_EDIT1,50)
 ENDGROUP()
 RCSPACE(-4)
 RCTOFIT(IDC_STATIC2)
 RCTOFIT(IDC_SLIDER1)
 BEGINCOLS(WRCT_TOFIT,0,0)
  RCREST(-1)
  BEGINROWS(WRCT_TOFIT,0,0)
    RCTOFIT(IDOK)
    RCSPACE(-2)
    RCTOFIT(IDCANCEL)
  ENDGROUP()
 ENDGROUP()
ENDGROUP()
END_WINDOW_MAP()

Add finally the following to the constructor of your dialog:

CTestDlg::CTestDlg( ) : 
    CDialogSizeable<CTestDlg>( TestDlgMap )
{
    ...

Now enjoy your sizing dialog.

Faced Problems

None (at the moment).

About Laurent Kempi

I am originally from Mulhouse, east of France, and currently searching for a new job. In 1995, I was graduated Software Engineer in ESSAIM Higher School of Engineering. I develop mainly in C++ for Windows platforms and I have a strong knowledge of the Windows security/logging system. I am currently digging in XML, SOAP and actively learning C# and .Net platform. I have knowledge in Object Oriented Design, UML, Design Patterns and be familiar with COM/COM+, DCOM, ATL/WTL, STL, MFC.

Click here to visit Tech Head, Laurent Kempi's homepage.

Downloads



Comments

  • Using CWinMgr in a COM object

    Posted by MoAz on 04/19/2006 09:45am

    Hello, I have a question about how can I use CWinMgr in a COM object. I am new in COM en MFC. what I am trying to do is making a COM object that first makes a connnection with a database in FoxPro and then viewing the information from that database in a dialog. this connection and creating of dialog and his controls must be done dynamically. how can I use CWinMgr to create dynamically a dialog and his controls and resizing them also dynamically? any idea? Thank you

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds