Search code examples
c++winapiwin32gui

How to change the size & position of a dialog-based window programmatically?


I have code which creates a dialog-based window:

m_window = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, 0);
ShowWindow(m_window, SW_SHOW);

How to change the size and the position of that dialog-based window programmatically not from the resource(.rc) file?


Solution

  • The size of the dialog can be changed with SetWindowPos(), but it's unlikely that you want to do that for a dialog - or you have also to resize all its children. Usually I do that only when the dialog contains one control to take it's full size, usually a listview or a HTML.

    The same function can change the position with SWP_NOSIZE option.