0

I have created a modeless dialog as a main window, but the window procedure isn't being sent WM_INITDIALOG messages.

Here's what I've done.

  1. Created a dialog template using Visual Studio's resource editor, and set its class name to a custom class.
  2. Used WNDCLASSEX to register the class, window procedure, as well as some icons and brush etc.
  3. Used CreateDialog() with the last two parameters set to NULL, (Parent window, and window procedure).
  4. Created the message loop using IsDialogMessage(), TranslateMessage() and DispatchMessage();
  5. Returned DefDlgProc() in the window procedure as the default if no messages were processed.

I can't think of anything else significant. Everything works well except for not receiving WM_INITDIALOG messages. I've done it this way so the app minimises to the task bar, and I can have a menu if needed.

So my first question is, Have I done anything stupid?

Secondly, should I expect to receive WM_INITDIALOG messages using this system? And if not, what is a good way to initialise say a combobox with strings. (I've looked at things like WM_ACTIVATE, WM_ACTIVATEAPP etc, but nothing seems appropriate. And the combobox isn't created yet at WM_CREATE.) Thanks in advance.

  • Before creating the child window, ensure that it's parent is fully created – seccpur May 18 '21 at 10:27
  • Be sure to distinguish a *dialog procedure* and the window procedure. For a dialog, the window procedure is implemented in Windows itself. It invokes the dialog procedure whenever something relevant to the dialog happens, like WM_INITDIALOG. It is the one that calls DefDlgProc(). So now you know that step 3 was wrong, you don't have a dialog procedure. Example [is here](https://stackoverflow.com/a/10233086/17034). – Hans Passant May 18 '21 at 10:36
  • Thanks seddpur and Hans. Hans, that example doesn't minimize to the taskbar, and you can't have a menu, I think. That's why I used a custom dialog box. – Ron Francis May 18 '21 at 10:58
  • Some windows documentation says that if I'm using a dialog as a main window, the procedure has to call DefDlgProc. But I have found an answer to my question which I'll post shortly. It is definitely a window procedure rather than a dialog procedure. (I thought I had copied the dialog class (GetClassInfo()) and used that to create a new class, but that must have been another app. Anyway, it's all working as expected now. – Ron Francis May 18 '21 at 11:09
  • `WM_INITDIALOG` is sent directly to your dialog procedure by `DefDlgProc()`. It's not posted to your message queue. You need a dialog procedure to receive it. – Jonathan Potter May 18 '21 at 11:09
  • `CreateDialog()` with `NULL` dialog procedure doesn't make sense unless you subclass it, because you wouldn't get any messages from it (so you wouldn't even know when to end message loop). And I don't think that subclassing would that good solution, just use normal dialog procedure. – Daniel Sęk May 19 '21 at 06:54
  • I know it looks odd, but I set the callback procedure in the WINCLASSEX structure when creating the window. I'm getting all the normal dialog functionality. – Ron Francis May 20 '21 at 08:26

1 Answers1

0

I realised the answer shortly after posting. As mentioned in the comments above, it's a window procedure, not a dialog procedure, so I shouldn't have been trying to initialize child windows within the procedure.

So I initialized them outside the procedure, after creating the dialog box and before the message loop. All the dialog features are working as expected, but it's a main window that can have a menu and minimizes to the taskbar.