Reputation: 79
I want to make a modeless dialog box that shows itself without being activated.
I tried
m_ReminderDialog = new CReminderDialog();
m_ReminderDialog->Create(CReminderDialog::IDD, GetDesktopWindow());
with the dialog template
IDD_REMINDER DIALOGEX 0, 0, 318, 269
STYLE DS_SETFONT | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_TOPMOST | WS_EX_NOACTIVATE | WS_EX_APPWINDOW
...
But it still comes up activated.
I tried making a window directly, not in MFC and using CreateWindowEx
, with
WS_EX_NOACTIVATE | WS_EX_APPWINDOW
That worked. The window comes up inactive, but it can be activated by clicking on the taskbar button.
I read that the call to Create
activates the window. Is that true, and if so is there a way to create the modeless dialog box that doesn't override WS_EX_NOACTIVATE
?
Upvotes: 2
Views: 492
Reputation: 79
It turns out that the code I posted does create the dialog box, without giving it the input focus.
I just thought it had the input focus, for two reasons -
CreateWindowEx
in a separate program, using that same WS_EX_NOACTIVATE
flag, it could only be activated by clicking on the taskbar button. So WS_EX_NOACTIVATE
acts differently when used in the dialog template than it does when calling CreateWindowEx
.I tried the code as written, with a call to Sleep
before creating the dialog window, so I had time to set focus to a text document. Then I waited until the dialog box was created.
After the dialog box was created, I was able to keep typing into the text document, so the dialog box did not have input focus. I was also able to put the dialog box on top of other windows with a couple calls to SetWindowPos
, still without giving it the input focus.
However, WS_EX_NOACTIVATE
does not work when DS_SETFOREGROUND
is also used in the dialog template. Not surprisingly.
Upvotes: 0
Reputation: 11321
Remove WS_VISIBLE
style from your template, then add (after Create()
):
m_ReminderDialog->ShowWindow(SW_SHOWNOACTIVATE);
Reference info: ShowWindow
.
Upvotes: 1