Thread: modal and modeless

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    modal and modeless

    hey all,
    I would just like to know if anyone here can please tell me what the difference is between a modal and modeless dialog box, in english please.

    I have read numerous books on the Win32 API on this subject, but none of them seem to mention clear differences between modal and modeless dialog boxes. they give very simple descriptions like "a modeless dialog is more independant than a modal" and "a modal is the most common" however that tells me nothing about the real difference.

    in the last release of my program I used a simple call to DialogBox to create the main dialog box window. but in this release, I will be implementing a whole bunch of GUI enhancements, including more menus and accelerator keys.

    however in this release I don't see how I am going to be able to position a function like TranslateAccelerator in my WinMain and pass the dialog window the translated accelerator messages if I don't have a valid handle of the dialog window inside of WinMain. replacing DialogBox with CreateDialog would solve this, but DialogBox creates a modal dialog box, and CreateDialog creates a modeless dialog box .

    could anyone please help me out with this modal and modeless thing? also do you think its possible for me to use DialogBox and still handle things like accelerator keys, and if so how should I go about that (would it be ok without a message loop containing a TranslateMessage?)?

    any help here would be greatly appreciated. thank you in advance.
    Last edited by Bleech; 12-02-2006 at 04:39 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    A modeless dialog lets the program that created it run on. The user can still select and use the other windows of the program.
    A modal dialog on the other hand is always active, and will disable all other windows of your program until it's closed. The user cannot select the other windows of a program if the program is waiting for a modal dialog to finish.
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    They're both based on the same system defined window class(window class name "#32770") with slightly different system defined behaviour - a bit like push buttons and radio buttons which are both manifestations of the 'button' system defined window class, except the differences between the dialog box types are not quite so visually nor, perhaps, behaviourally pronounced.

    A modal dialog box (created with DialogBox,DialogBoxParam) basically hogs attention until it's dismissed - they're intended for situations where user input or user response/acknowledgement are required before proceeding; they don't allow you to switch to other windows within the same application(application modal) or even other applications(system modal) until the modal dialog box is dismissed.

    A modeless dialog is just like another window; you can switch between it and other windows within the same application.

    Neither type of dialog is intended to be used as a main application window although some people do this anyway - at least until they discover some limitation to this approach. They are generally intended to elicit or provide user information/response/selections and it's the type of response/input required by the application that ideally should determine your choice of which to use.

    For further clarification consider creating simple test case applications which produce both types of dialog and examine both the code differences (for example the requirement for your own application message loop for modeless dialogs, destruction with DestroyWindow etc.), the implications of these differences and observe their default behaviour while referring to the msdn documentation and any other texts you have to hand.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to create a Modeless Modal?
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-21-2007, 05:31 PM
  2. Creating a modeless property sheet
    By axr0284 in forum Windows Programming
    Replies: 6
    Last Post: 01-12-2005, 06:29 AM
  3. Taskbar Entry for modal Dialog?
    By PrivatePanic in forum Windows Programming
    Replies: 2
    Last Post: 07-28-2002, 01:38 PM