stev75
asked on
mfc modal / modeless dialog and minimize / restore problem
Hi,
so here's my problem in short:
i use AfxGetMainWnd->EnableWindo w(FALSE) from within a modeless dialog, which makes it actually look modal (and that is really appreciated and good working)
I like the minimize feature, because it is comfortable to the user having the application working in background.
problem: In minimized state, the system menu is unavailable, because i used "EnableWindow(FALSE)"
I'm searching for a solution to make the modeless dialog have its modal behaviour again, and also the ability to get minimized and restored.
Anyone has an idea ? Thanks
so here's my problem in short:
i use AfxGetMainWnd->EnableWindo
I like the minimize feature, because it is comfortable to the user having the application working in background.
problem: In minimized state, the system menu is unavailable, because i used "EnableWindow(FALSE)"
I'm searching for a solution to make the modeless dialog have its modal behaviour again, and also the ability to get minimized and restored.
Anyone has an idea ? Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I like the very simple idea by alb66, both comments have been helpful. Now I use IsIconic() to see if the window is minimized. Thanks!
ASKER
Hi Dan,
the modeless dialog is a temporary dialog. It shows a progress bar and lasts as long as a database access is active.
You should act only on the modeless dialog, that's why it disables the main. When you minimize it, it enables the main again, to have the system menu.
I use the idea of the accepted solution:
Not by controlling the modeless dialog by an UI element of the main, but by pushing a flag from the modeless dialog to the main, with the aim of resuming initial behaviour.
That's not actually the solution posted here but I had this idea reading the solution!
So here's little explanation:
Actually there's a modal dialog, that is between the modeless and the main(!)
When main is restored / maximized from the taskbar again, it checks the flag and resumes the modal state of the dialog, by disabling itself!
If I didn't do that, both main and dialog are user-responsive, which is not wanted.
the modeless dialog is a temporary dialog. It shows a progress bar and lasts as long as a database access is active.
You should act only on the modeless dialog, that's why it disables the main. When you minimize it, it enables the main again, to have the system menu.
I use the idea of the accepted solution:
Not by controlling the modeless dialog by an UI element of the main, but by pushing a flag from the modeless dialog to the main, with the aim of resuming initial behaviour.
That's not actually the solution posted here but I had this idea reading the solution!
So here's little explanation:
Actually there's a modal dialog, that is between the modeless and the main(!)
When main is restored / maximized from the taskbar again, it checks the flag and resumes the modal state of the dialog, by disabling itself!
If I didn't do that, both main and dialog are user-responsive, which is not wanted.
// this funcion is called by the modeless dialog, to let the main resume its
// behaviour when modal dialog should become active again
void SetContinueModalDialogWhenRestored(CDialog* pModalDlg, bool state)
{
m_pModalDlg = pModalDlg;
m_bContModalWhenRestored = state;
};
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
if( (nID & 0xFFF0) == SC_RESTORE ||
(nID & 0xFFF0) == SC_MAXIMIZE )
{
if(m_bContModalWhenRestored && m_pModalDlg)
{
// process base class first
CMDIFrameWnd::OnSysCommand(nID, lParam);
EnableWindow(FALSE);
// for child windows: call AFTER CMainFrame::EnableWindow(FALSE),
// EnableWindow(FALSE) disables also all child windows.
m_pModalDlg->EnableWindow(TRUE);
m_bContModalWhenRestored = FALSE;
return;
}
}
CMDIFrameWnd::OnSysCommand(nID, lParam);
}
Thanks. Having a detailed description of the solution will help the next person who reads this.
-- Dan
-- Dan
AfxGetMainWnd()->GetWindow
http://msdn.microsoft.com/
...to see if the main windiw is currently minimized.