Solved

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

Posted on 2009-04-01
17
1,724 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
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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now