简体   繁体   中英

MFC dialog shows in task bar

I have an application that uses dialogs from two DLLs. The code for the dialogs in the two DLLs is almost identical:

  1. Both dialogs have the same style in the RC file: DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU .
  2. Both dialogs are shown using ShowWindow(SW_SHOW) .
  3. Both dialogs are created on demand and not when the application starts.
  4. Both dialogs have a NULL parent.
  5. Both dialogs inherit from CDialog.

The only differences are that:

  1. In dialog A, 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;

Ie "the_app.cpp":

#include "stdafx.h"

CWinApp dummy;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM