Solved

DoModal - window not at front?  (Alt fixes it!)

Posted on 2009-04-01
17
1,854 Views
Last Modified: 2013-11-20
Hi Experts,

I'm popping up the simplest little window with DoModal - I don't see it, but if I simply press the "Alt" button, and just the Alt button, my window comes to the top of the z-order.  I'm using Visual C++ 9.0 with Vista.  What gives??
0
Comment
Question by:thready
[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
17 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 24045986
You may need to show your code...
But my first guess is that you have set the parent of the dialog to be the desktop rather than your main wiindow.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 24046945
>>> I'm popping up the simplest little window with DoModal

from where?  A thread, a dll ?

(Sounds like a bug you have there)
0
 
LVL 1

Author Comment

by:thready
ID: 24048779
It's from a simple dialog based app - no threads except the main thread.  I agree - does sound like a hidden bug somewhere......  just grasping at straws because of the weird fact that it works - just that Alt brings the window to front!

Mike
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 1

Author Comment

by:thready
ID: 24048786
However, there are 3 OpenGL windows in this app (right on the main frame of the dialog based app - the same window I'm popping up the new CDialog).......  not so simple I guess...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24054916
Show the code that you use to to open/display the dialog.  In what object does that code reside?
0
 
LVL 1

Author Comment

by:thready
ID: 24059828
Hi Dan,

It's just a really simple CDialog derived class.  I do the following:

CMyDialog dlg;
dlg.DoModal();

I'm sure it has more to do with the OpenGL windows that are just behind it.  They are constantly grabbing the drawing context (because they are all "competing" for OpenGL draw commands)...  Somehow the z order of even a modal window is being affected....  (CMyDialog has to edit controls in it - it's really a teeny tiny window that has nothing to do with the problem).....

I'd provide more code, but I'd have to include the whole project..  It's too big...

Thanks,
Mike
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24066144
The code you showed did not indicate what object that code was in.  That can be important because the parent window is based on the parent object when the default constructor is used.  
Yes, it is probably related in some way to the OpenGL windows.  But parent/child relationships are very often at the root of these things.
Another possibility:  In OnInitDialog(), do you set the focus?  If so, that fn should return FALSE.
0
 
LVL 1

Author Comment

by:thready
ID: 24066244
The CDialog is instantiated in the main CDialog of the application.  The main CDialog contains 3 OpenGL custom controls - there is also a button that calls my the code that invokes the DoModal...

Although I am not calling SetFocus in OnInitDialog, I tried returning FALSE instead, no luck.

Another interesting point - when I click the button that invokes the DoModal, the window is of course present, but invisible.  Pressing Alt at this point brings it to the front.  However, if instead of Alt, I press escape, it does also have focus, control comes back to the dialog that it was invoked from (i.e., escape closes the dialog and exits the DoModal state)....

I know it's not easy to try to help me with this - it's all shots in the dark for you, I appreciate your help.  I was sure your last comment would be the solution....  (until I tried it)...

Mike
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24069365
Diagnostic thought:  Arrange the OpenGL windows so that there i a gap at the point where the small modal dialog will appear.  Does a part of the popup dialog box appear in the gap (without needing to press Alt)?
Diagnotic:
Run Spy++ and monitor all messages sent to both the main dialog and the popup.  See what sequence occurs when you press Alt.  Might yeild a clue
There should be a normal/simple way to do this... Obviously, DoModal() normally displays the dialog immediately.  But there are a number of things you can try to force the display.  For instance, call Invalidate() on the parent window (main dialog) right before returning from OnInitDialog of the popup.  Or maybe a SetWindoePos or MoveWindow on the popup will shake things up.
 
0
 
LVL 1

Author Comment

by:thready
ID: 24077548
Hi Dan,

I tried moving the window below so that it wasn't above an OpenGL window.  I also tried Invalidate at the end of the new window's initdialog - and SetWindowPos - no luck.  I didn't see anything special wih Spy++ either....  :-(      all good ideas, but just not lucky.

Thanks,
Mike
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24080773
Check the parenting of OpenGL windows.  Are these ActiveX controls?  Are they defined as child windows of the main dialog?
0
 
LVL 1

Author Comment

by:thready
ID: 24081206
The parent of COpenGL windows are CWnd.   I used CStatic controls to position them on my main CDialog window....
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24081490
There might be an assumed parameter that sets the parent to the wrong window.  
Please show the code you use to create one of the OpenGL windows.  
0
 
LVL 1

Accepted Solution

by:
thready earned 0 total points
ID: 24100553
I found the problem - it has to do with any window- basically, my OpenGL window processes the WM_PAINT message.  In my OnPaint function, I call my virtual function DrawGLScene and return.  The fix was to call the __super::OnPaint....  My dialog boxes simply were not being painted because I handled the WM_PAINT without passing it on...

0
 

Expert Comment

by:mashey
ID: 24991728
I have a question on this. I have a main_UI dialog box, whose InitDialog() spawns a thread which calls an other dialog box (login dialog box). The login dialog box calls the DoModal(), however, both the Main_UI and the login dialog box act as two separate windows.
My question is 1. How to establish a parent-child relationship between the Main_UI and the login dialog box.

2. How to make the login dialogbox truly Modal?

I am using Visual Studio 9.0.
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

624 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