none
How to set size for a dialog at runtime RRS feed

  • Question

  • Hi,
              When I create a project in MFC it gives me a basic dialog with a default. But instead of changing the dialog size statically, I wanted to change window size at runtime. Like before showing the base dialog I need to define its size through code. My application will have only one dialog. Is there any predefined function to do this. I tried it by overloading Create() function. But it is not giving me the system menu items like minimize and close. Help me out.

    MFC
    Wednesday, February 4, 2009 8:27 AM

Answers

  • Perhaps you could SetWindowPos in the OnInitDialog?

    SetWindowPos(NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);

    Of course you'd need to reposition any controls within the dialog.

    You could use one of several control resizers to help with that:
    http://www.codeproject.com/KB/toolbars/AutoResizingControls.aspx
    http://www.codeproject.com/KB/dialog/easysize.aspx

    etc
    http://www.codeproject.com/info/search.aspx?artkw=resizing&sbo=kw

    Thanks.
    Wednesday, February 4, 2009 8:57 AM

All replies

  • Perhaps you could SetWindowPos in the OnInitDialog?

    SetWindowPos(NULL, -1, -1, cx, cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);

    Of course you'd need to reposition any controls within the dialog.

    You could use one of several control resizers to help with that:
    http://www.codeproject.com/KB/toolbars/AutoResizingControls.aspx
    http://www.codeproject.com/KB/dialog/easysize.aspx

    etc
    http://www.codeproject.com/info/search.aspx?artkw=resizing&sbo=kw

    Thanks.
    Wednesday, February 4, 2009 8:57 AM
  • Hi Mark,
                  Thanks for the help.

    MFC
    Wednesday, February 4, 2009 9:04 AM