Not so modal CDialogs

This is a discussion on Not so modal CDialogs within the Windows Programming forums, part of the Platform Specific Boards category; We had some weird crashes in our client application and I finally reproduced it in a wizard generated 3-liner: This ...

  1. #1
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139

    Not so modal CDialogs

    We had some weird crashes in our client application and I finally reproduced it in a wizard generated 3-liner:

    This "works" in VC6 and VC7.

    Create a Dialog based MFC Application. Deselect all features. When your Dialog comes up, double click the OK Button. This will send you directly into the code. You just overwrote OnOK. Now make it look like this, opening up another copy of the same dialog:

    Code:
    void CCDialogTestDlg::OnOK() 
    {
    	CCDialogTestDlg dlg;
    
    	dlg.DoModal();
    }
    While obviously stupid, it will show what my problem is. Start the program. Click OK. Move the dialog a bit. Click OK on the new Dialog again. You now have three windows, each one modally bound to it's parent. Click with the mouse on each one, only the topmost window ( the last in the modally opened chain ) will activate.

    So far, it's working as intended.

    Now select the middle/second window in the chain in the taskbar. Voila, the second window is selected and ready for input by keyboard ( not usable with the mouse though ).

    You can probably imagine that working with and closing the second window in a three ( or more, test it ) dialog chain will crash any application. I cannot have a user select which dialog he wants to answer to, that's what modal dialogs are for: topmost first. Nothing else.

    I tested this in VC6, then hoped it was a bug and tested it in VC7 resulting in the exact same behaviour. So I guess it must be me being totally confused and unable to set the right flag when creating a dialog. Does anyone have any ideas how to solve this ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    that is wierd, never noticed that before....

    I can only get the middle dlgs to respond to the ENTER key not the TAB key in MSVC 2003. This does allow me to click the dlg's default button and so recreate the issue.

    Try removing the 'Application Window' style.
    This is the flag that gives a dlg an icon in the taskbar.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    I removed the WS_EX_APPWINDOW style, so I have only one taskbar entry for the applicaion and it works fine. But I can already hear our users screaming. It's clearly unusable ( read: different than yesterday ) now and no one can work anymore
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Hmmm.. Very strange. But it's doing what you tell it to. You click on OK and fire off another dialog before you destroy the first one.

    I think this is why the MFC docs state that if you want to have a dialog appear after another closes, execute that dialog outside of the one that is closing, not inside of it.

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    I don't want to close the underlying dialogs but return to them when the one on top closes. Example at hand: First dialog is a tree of jobs. Click on one and another dialog opens with all modules of said job. Click on a module and you get another dialog for specific module data. Close it, get back to the job details. Close that and you get back to the job tree.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by nvoigt
    ..it works fine. But I can already hear our users screaming. It's clearly unusable ( read: different than yesterday ) now and no one can work anymore
    Bloody users!

    If their not complaining about the software, they're finding new and inventive ways to break it.....
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Doesn't the dialog class have a constructor argument where you pass the parent window? Pass the current this pointer to that.
    If it doesn't have such an argument (as it's your class, after all), give it one. You need it. Read up on the Modality series in the Old New Thing blog, starting on this archive page, and look in particular at part 4.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non modal Dialogs
    By Barjor in forum Windows Programming
    Replies: 3
    Last Post: 02-08-2002, 11:50 AM
  2. Independent System Modal Toolbar
    By serp13 in forum Windows Programming
    Replies: 1
    Last Post: 12-06-2001, 09:56 PM
  3. Modal Dialogs?
    By jinx in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2001, 02:49 PM
  4. Getting Modal text in and SDI app.
    By jinx in forum Windows Programming
    Replies: 3
    Last Post: 11-23-2001, 12:01 PM
  5. modal average
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2001, 01:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21