dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2004
    Location
    Rochester, NY
    Posts
    7

    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 ---

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Well...what is the worker thread doing? CPU-intensive calculations? Running an endless loop?

  3. #3
    Join Date
    Aug 2004
    Location
    Rochester, NY
    Posts
    7
    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 ).

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Well...you don't happen to have a small example program which recreates this behaviour?

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    Are you handling paint messages in the dialog by any chance ? Any custom drawing you are doing. Have you modified the message loop ?

  6. #6
    Join Date
    Aug 2005
    Location
    Łódź, Poland
    Posts
    124

    Exclamation 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...

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: DoModal hangs until press ALT key

    Do you have a project you can upload here ?

  8. #8
    Join Date
    Aug 2005
    Location
    Łódź, Poland
    Posts
    124

    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? :/

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: DoModal hangs until press ALT key

    Quote 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...

  10. #10
    Join Date
    Aug 2005
    Location
    Łódź, Poland
    Posts
    124

    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???

  11. #11
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    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 ?

  12. #12
    Join Date
    Aug 2005
    Location
    Łódź, Poland
    Posts
    124

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.