CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2008
    Posts
    2,477

    Why do modal dialogs that are opened through a menu item’s click event process all wi

    So for the past day or so I have been fixing a bug that is caused by a modal dialog. I work on an application which communicates with the server through the Windows message pump. When I use ShowDialog() to show a modal form, the message pump is blocked and none of my messages are processed, yet they do build up in the queue (expected behavior).

    However, I recently noticed that if a modal form is opened through a menu item's click event, the messages are pumped to the main form and processed. Does anyone know why these messages are not blocked when a modal form is shown through a menu item's click event?

  2. #2
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    Try opening the modal dialog like this:

    Code:
    form.ShowDialog(this);

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    So, I suppose I should have mentioned that I am already doing that. Thank you for your reply though, this is the first one I have got over three different forums.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    Why do you use message loop to communicate with the server? It seems to me as not a good idea. Could the communication run in its own thread without a message loop? Than no blocking should occure. If you are using poll model, I think that common Timer should work fine.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    Well, that is true. It would be better to use a receive thread and a send thread to do this, but that is not the application that I have inherited and there isnot enough time in this release to change this. We do plan on changing this behavior soon, but in the meantime I really just need to figure this one out. I have a workaround that I do not like and I really just want to understand what is special about the click event of a menu item.

  6. #6
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    the thread that creates aparticular control owns the message pump for it. is there any chance that your dialog or the menu is using a thread other than the main window thread, for creation of the dialog?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Why do modal dialogs that are opened through a menu item’s click event process all wi

    So, I think that the problem is in my application (sorry). I found some code deep down in the guts of the app that was preventing messages from being processed, even though they were being queued. Thanks everyone who tried to help here, I presented a problem that does not really make sense. Sorry for wasting your time, and thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured