-2

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?

Lion King
  • 32,851
  • 25
  • 81
  • 143
  • 3
    Step one would be to locate the documentation for the framework you are using and then *read it*. If it's possible in that framework, the documentation is almost guaranteed to tell you how. Please do a bit of research.. – Jesper Juhl Aug 08 '19 at 16:16
  • @JesperJuhl: Firstly, I don't use a framework I use the native Win32Api. Secondly, I have already researched before writing my question and I did not reach anything so tell me what can I do then? – Lion King Aug 08 '19 at 16:32
  • 1
    "Firstly, I don't use a framework I use the native Win32Api" - That *is* a framework in my book, and it *does* have documentation. – Jesper Juhl Aug 08 '19 at 16:34
  • @JesperJuhl: I said previously I have already researched before writing my question and I did not reach anything whether the documentation or other. And about Win32Api is a framework or not this is no our subject. – Lion King Aug 08 '19 at 16:39
  • @JesperJuhl [Framework vs API](https://stackoverflow.com/questions/724380/framework-vs-api) – Michael Chourdakis Aug 08 '19 at 16:39
  • @LionKing *"resize a window msdn"* would find for you `SetWindowPos` already. – Michael Chourdakis Aug 08 '19 at 16:41
  • @MichaelChourdakis Sure, whatever. – Jesper Juhl Aug 08 '19 at 16:41
  • @MichaelChourdakis: thank you, but I was thinking that function is just working with non dialog-based window. – Lion King Aug 08 '19 at 16:48
  • 2
    @LionKing a dialog is exactly the same as a normal HWND with a special class handler. All the functions that take a HWND can take a dialog. – Michael Chourdakis Aug 08 '19 at 16:51
  • 1
    A dialog is a window and SetWindowPos lets you resize windows, including dialogs. But Win32 doesn't have a dialog layout engine. Any controls in the dialog that you want to move or resize when the dialog size changes you'll have to do manually. – Jonathan Potter Aug 08 '19 at 21:08

1 Answers1

1

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.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78
  • No need to resize all the child controls, only the ones that make sense. You wouldn't resize buttons for example. – Jonathan Potter Aug 08 '19 at 21:06
  • @JonathanPotter You would have to reposition them inside the dialog box and this isn't trivial, depending on the contents. Most dialog boxes need no resizing and having a dialog box resizable makes an inconsistent Windows gui. If you want to resize the contents, a dialog box is not a good choice. – Michael Chourdakis Aug 08 '19 at 21:10
  • Not necessarily. Imagine a dialog with a bunch of checkboxes at the top and then an edit field. Only the edit field needs to be resized, the checkboxes can be ignored. If there's an OK/Cancel button then they need to be moved. Obviously depends on the dialog layout but it's just maths, it's not rocket science. – Jonathan Potter Aug 08 '19 at 21:29
  • @JonathanPotter that would be a very badly designed dialog - instead, you could use a listview with checkboxes. Windows users want consistent designs. – Michael Chourdakis Aug 08 '19 at 21:30
  • 2
    Very badly designed dialogs are those that open up 300 pixels high when my screen is 2880 pixels high and won't let me resize them. – Jonathan Potter Aug 09 '19 at 02:14