开发者

MFC modeless and modal dialog

I have an application with tray icon. There is a hidden main window (CMainFrm), which is used to process tray icon messages. The tray icon has a context menu: Settings, Help, Exit commands.

When user chooses Settings, the modeless settings dialog is displayed (parent: 开发者_开发问答GetDesktopWindow()). Settings dialog has a browse button which displays MyBrowseFolderDialog as modal! So, there is a problem when this dialog is displayed and user tries to close application using Exit command from the tray menu.

Does anyone know how to gracefully close the application with all these dialogs? tray menu => Settings dialog (modeless) => BrowseDialog (modal)


Add CDialog* m_pModaldDlg member to Settings dialog class, initialize it to NULL in constructor. When MyBrowseFolderDialog is shown, set it to this dialog pointer:

MyBrowseFolderDialog dlg();
m_pModaldDlg = &dlg;
dlg.DoModal();
m_pModaldDlg = NULL;

In Exit message handler:

if ( m_pModaldDlg )
    m_pModaldDlg->EndDialog(0);
// Close settings dialog


Alex answer is still good - you have to store the m_pModalDlg in the CMainFrm so both Settings and Exit handlers can get to it as needed.

Some other possible solutions:

  1. Settings handler disables Exit option when Folder browse is active

  2. Register a custom message - have the Exit handler send this message to the browse folder (although you are still going to need some kind of window handle)

I like Alex's answer the best - just store the pointer somewhere in CMainFrm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜