I have an application that uses dialogs from two DLLs. The code for the dialogs in the two DLLs is almost identical:
DS_SETFONT |
DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
.ShowWindow(SW_SHOW)
.The only differences are that:
AFX_MANAGE_STATE()
is called before the dialog constructor, where as for dialog B it is called at the start of the constructor.I don't see that any of these differences should make any difference and yet, when I show the dialogs, dialog A does NOT have an icon in the task bar and dialog B, and furthermore, bringing the main window to the front brings dialog A to the front (and visa versa) whereas dialog B behaves independently.
I want to make dialog B behave like dialog A. Can anyone tell me why this difference of behaviour is there and how to fix it so that dialog B behaves the same as A?
I know you would love sample code, but that would take some time (which I don't have) to craft. The existing code is all company commercial and also a huge app from which extracting the key parts would be very difficult indeed.
** UPDATE **
If I call ::AfxGetMainWnd()
in dialog B's contrustor before I call AFX_MANAGE_STATE()
I can get a pointer to the main window's pointer. Yay! When I then pass it to Create()
, the program crashes. Boo!
It looks like I cannot set the main window as the owner of dialog B, which I think would solve my problem, presumably because dialog B is in a DLL. What I don't understand is why this works for dialog A.
The DLL that implements dialog A instantiates an instance of CWinApp. The DLL that implements dialog B doesn't.
To fix this simply add the following line to a CPP file, possibly a standalone "the_app.cpp" file:
CWinApp dummy;
I.e. "the_app.cpp":
#include "stdafx.h"
CWinApp dummy;