Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mfc modal / modeless dialog and minimize / restore problem

Posted on 2008-10-28
6
Medium Priority
?
1,588 Views
Last Modified: 2013-12-14
Hi,
so here's my problem in short:
i use AfxGetMainWnd->EnableWindow(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
0
Comment
Question by:stev75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
alb66 earned 1197 total points
ID: 22823969
I think you can use a GUI element of the main window and then call a method on the modeless dialog than perform the minimiza action.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 22829300
The main window must be enabled in order to get taskbar commands such as Close and Restore.  When you decide whether or not to disable, you can use:
   AfxGetMainWnd()->GetWindowPlacement()
   http://msdn.microsoft.com/en-us/library/w69bxfc4.aspx
...to see if the main windiw is currently minimized.
0
 

Author Closing Comment

by:stev75
ID: 31510753
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!
0
 

Author Comment

by:stev75
ID: 22848245
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.

// 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);
}

Open in new window

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 22848655
Thanks.  Having a detailed description of the solution will help the next person who reads this.
-- Dan
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question