winapimfc

How to create a resizable CDialog in MFC?


I have to create a dialog based application, instead of old CFormView type of design. But CDialog produces fixed-size dialogs. How can I create dialog based applications with resizable dialogs?


Solution

  • In the RC resource file if the dialog has this style similar to this it will be fixed size:

    IDD_DIALOG_DIALOG DIALOGEX 0, 0, 320, 201
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    

    If the dialog has this style it will be sizeable:

    IDD_DIALOG_DIALOG DIALOGEX 0, 0, 320, 201
    STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
    

    With these sizable frame options the dialog will be re-sizeable but you will still need to do a lot of work handling the WM_SIZE message to manage the sizing an positioning of the controls within the dialog.