How to Create Resizable Dialogs in MFC

Example 1: Using Paulo Messina’s Code Project sample

A minimalist use of the CResizeableDialog class as described by Paulo Messina at CodeProject .   Hope you find the following recipe useful. Visual Studio 2003 source code is downloadable from here.

1. Create a new MFC Project


2.  In the resource editor, add a simple edit control that will be used to demonstrate how this resizing works:


3. Download the CodeProject library to a location of your choice.

4. Add this downloaded project to the same dialog project you are working on.  To do this, right-click the topmost solution folder and select Add Existing Project:


So that the extra project is added:


5. Right-click on the Dialog (or whatever you called your project)  folder and select “Set Project Dependencies”, making sure ResizableLib is checked:


6. In the Dialog code make sure CDialog is replaced with CResizeableDialog at the following appropriate points.

(i) In the Dialog class (header file) be sure to insert #include “ResizableDialog.h”. In this Dialog class, replace CDialog with CResizableDialog:

#include "ResizableDialog.h"

// CDialogDlg dialog
class CDialogDlg : public CResizableDialog

// Construction
	CDialogDlg(CWnd* pParent = NULL);	// constructor

// Dialog Data


        // DDX/DDV support
	virtual void DoDataExchange(CDataExchange* pDX);	

// Implementation

	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);

	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();


Basically replace all instances of CDialog with CResizableDialog, except in CAboutDlg of course.

7. Add the dependencies needed to build the project. In Project Properties-> C/C++ -> General -> Additional Include Directories:


8. Finally, In OnInitDialog() add the extra initialization needed make the gripper visible, set maximum dialog size, add anchors to control items etc and we’re done.

// Initialize anchor points


// Set max tracking size to half a screen
CRect rc;
SetMaxTrackSize(CSize(rc.Width(), rc.Height()));

// Set max. position and size on top of the screen
rc.bottom = 200;
SetMaximizedRect( rc );


Example 2: Stack Overflow posting

Courtesy of Mark Ransom.  Some things things needed to use this class are:

1. Set your dialog style to include WS_THICKFRAME:

CAPTION "DialogResize"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
    LISTBOX         IDC_LIST1,35,35,143,99,LBS_SORT |
                    LBS_NOINTEGRALHEIGHT |
                    WS_VSCROLL | WS_TABSTOP

2. Make your dialog class derive from the CResizableDialog base class instead of CDialog or CDialogEx:

// CDialogResizeDlg dialog
class CDialogResizeDlg : public CResizableDialog

3. In your OnInitDialog function call the AutoMove function for each child control to define how much it should move and how much it should resize relative to the parent dialog. Use this example to ‘stretch’ the dialog child controls from a fixed position:

AutoMove( IDC_LIST1, 0, 0, 100, 100 );

4. In the dialog class you are using (not the CResizable base class), replace all instances of CDialog with CBaseDialog.

Example VS2003 code downloadable from here.

Example VS2010 code downloadable from here.

Another VS2010 project is available this time incorporating a list control that is resized and repositioned upon stretching the dialog and a button control that is repositioned only. We achieve this by specifying how much we wish to allow the button control to be repositioned, while leaving its resizing parameters set to zero:

AutoMove( IDC_LIST1, 0, 0, 100, 100 );
AutoMove( IDC_BUTTON1, 100, 100, 0, 0 );

This is the dialog before repositioning:


And this is the dialog after repositioning:


Updated VS2010 code downloadable from here.


  1. The links to the VS2003 code are broken, by the way. (Not that it’s much of a problem, since the “hand-holding” {grin} is so well done for the examples – I built the two examples in VC6 anyway.)

  2. Getting an linker error as shown below. Please advise as needed.

    2>rF2RaceControl_MMIDlg.obj : error LNK2001: unresolved external symbol “protected: virtual int __thiscall CResizableState::ReadState(wchar_t const *,class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT > > &)” (?ReadState@CResizableState@@MAEHPB_WAAV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@@Z)
    2>rF2RaceControl_MMIDlg.obj : error LNK2001: unresolved external symbol “protected: virtual int __thiscall CResizableState::WriteState(wchar_t const *,wchar_t const *)” (?WriteState@CResizableState@@MAEHPB_W0@Z)

  3. Thanks.

    Worked with the updated files. Just had to change the include statement and the Projects Configuration type from application to static library.

    Thanks for the fast update.

  4. Another question. Seems that the most recent version just provides one method?

    Could you please explain a little more how to use AutoMove?

    void AutoMove(int iID, double dXMovePct, double dYMovePct, double dXSizePct, double dYSizePct);

    When using the AutoMove method a Tab-Control seems to become a simple listbox and I was not able to simply move the the OK and CANCEL button.

    • Hi Merlin
      I literally opened the VS2003 project in VS2010 and just let it do the conversion.
      I had similar experiences to yours when trying to incorporate a button.
      In addition to the first parameter defining the control ID, the other arguments passed to AutoMove enable you to define

      i. how much the child control is repositioned.
      ii. how much the child control is resized.

      Another thing I noticed is that as soon as you add another control like a button, the WS_THICKFRAME mask that you need to insert disappears! You need to go and re-instate this value otherwise the ability to resize and reposition the controls is lost.

      Anyways, I have created yet another download, to incorporate a button control which does not get resized, but is re-positioned only. It’s available at the same Download location, renamed to

      Let me know what you think.

  5. Very thanks for sharing that code. Currently, I am delevoping a window form that has text, two buttons and two picture controls. I want to apply your code for my problem. However, it does not work for two picture controls. Let see my edit code and please give me some comment.
    I set
    AutoMove( IDC_STATIC, 50, 50, 50, 50 );
    AutoMove( IDC_STATIC2, 0, 0, 100, 100 );
    AutoMove( IDC_BUTTON1, 100, 100, 0, 0 );
    AutoMove( IDC_BUTTON2, 100, 100, 0, 0 );
    AutoMove( IDC_TEXT, 0, 0, 100, 100 );
    This is before resizing
    After resizing
    This is my edit source code

        • Yes. I would like to share the source code
          AutoMove( IDC_IMG, 20, 0, 80, 100 );
          AutoMove( IDC_VIDEO, 0, 0, 20, 20 );
          AutoMove( IDC_BUTTON1, 100, 100, 0, 0 );
          AutoMove( IDC_BUTTON2, 100, 100, 0, 0 );

          That means the IDC_VIDEO will not move in left side. It only zoom in with limited value.
          However, I meet new problem. That is show image in picture control IDC_IMG. I cannot show image in picture control because we use
          CStatic pic1;
          DDX_Control(pDX, IDC_IMG, pic1);

          Do you tried to show the image in picture control with above code? Thank in advance

  6. Yes. Picture control can be used for show image or video. Currently, I am using it to display image and detect face using opencv 2.4.10. However, I found some bugs when I used within 1 minute and closing app:
    ” Unhandled exception at at 0x760C4598 in DialogResize.exe: Microsoft C++ exception: cv::Exception at memory location 0x01A5EFB8.”
    I think the problem is free memory problem or detect face try to detect a empty image. I am not sure. Could you find my problem in above code. For full code, you can download at
    If you are interesting in that control. Let see and find the solution. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *