-
August 9th, 2004, 10:41 AM
#1
DoModal hangs until press ALT key
I commonly have come across this problem, but find no mention of it in the codeguru discussions. If I call DoModal on a CDialog derived object, occasionally the main window title bar loses focus, but the modal dialog does not come up. The GUI is fully responsive, but acts as if the modal window is up, but invisible. The only way to force it to show up is to press the ALT key ( came across that accidentallly). This problem seems to occur in CFormView based apps that consume a lot of CPU in a worker thread.
The OnInitDialog() gets called, but the internal Windows MFC code responsible for making the window show up doesn't make this window visible, it does however, give the invisible window mouse and keyboard focus.
I have found that if I suspend worker thread activity before calling DoModal(), that the problem goes away. Does windows have a timeout mechanism, or do messages get dropped?
This may be related - I have perused through MFC CFileDialog code, and the DoModal() code has some pretty strange "bug" fixes code in it that seems to address just this problem, but it is so convoluted and calls undocumented Afx___ functions that I am hesitant to copy it blindly.
Any else come across this problem and have a solution?
--- Fishyrama ---
-
August 9th, 2004, 12:21 PM
#2
Well...what is the worker thread doing? CPU-intensive calculations? Running an endless loop?
-
August 10th, 2004, 09:18 AM
#3
Well, I've seen this problem in 3 separate programs. In all cases there was a worker thread processing data I/O. Case 1) Worker thread communicating with third party DLL, which in turn was reading USB data ( in the same thread as worker thread).
Case 2) Worker thread was receiving USB data via Windows ReadFile() command.
Case 3) Worker thread was receiving serial port data - also via ReadFile() command.
In all cases the worker thread is sprinkled with Sleep() statements to give the GUI a chance to run, and I've tried lowering the worker thread priority but that has no effect. As far as I can tell, it seems that if there is too much latency the GUI thread seems to lose one of the many messages needed to correctly display a new modal window. Everything else seems to run correctly: the modal message pump, OnInitdialog gets called. And why pressing the ALT key does make the window appear is a mystery as well ( F10 also works ).
-
August 10th, 2004, 09:55 AM
#4
Well...you don't happen to have a small example program which recreates this behaviour?
-
August 10th, 2004, 10:43 AM
#5
Are you handling paint messages in the dialog by any chance ? Any custom drawing you are doing. Have you modified the message loop ?
-
December 12th, 2005, 02:57 PM
#6
Re: DoModal hangs until press ALT key
Hi, I have the same problem... :/ Does anyone have a solution to this problem? It's very important for me...
-
December 12th, 2005, 03:05 PM
#7
Re: DoModal hangs until press ALT key
Do you have a project you can upload here ?
-
December 13th, 2005, 09:34 AM
#8
Re: DoModal hangs until press ALT key
Hmmm.. no The project is a bit commercial Besides... my girlfirend noticed this bug... and the project is now about 5000 lines long... so even if i could upload it... it would be... troublesome...
but i can tell you that:
- in my main widow i draw an animation (every 10ms)
- on my computer (2.0Gh) this problem dosen't occur...
- on her computer (1.0Gh) this problem occurs...
any idea how can I solve this problem? :/
-
December 13th, 2005, 11:58 AM
#9
Re: DoModal hangs until press ALT key
Originally Posted by Miechu
any idea how can I solve this problem? :/
Well....based on your description...yes....don't draw the animation every 10 ms...
In other words...more than guesses aren't possible...
-
December 13th, 2005, 01:25 PM
#10
Re: DoModal hangs until press ALT key
can't do that... :/ the program is supposed to draw the next frame of animation every 10 ms.... isn't there a way to force windows to draw that freaking window???
-
December 13th, 2005, 01:41 PM
#11
Re: DoModal hangs until press ALT key
Please explain what the worker thread is doing ? what the GUI thread is doing ?
Also, when you invoke taskmanager when your app is running, what does the CPU show for your app ?
-
December 14th, 2005, 07:07 AM
#12
Re: DoModal hangs until press ALT key
ok, every 10ms my app is calling 'Invalidate(false);' and in 'OnPaint' i draw OpenGl window with updated animation...
my taskmanager shows 0-3% cpu usage
my grilfriends 3-14%
help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|