The Mode dialog box cannot process the parent window without processing it, but the mode dialog box can process the parent window without processing the dialog box first. example: Right-click my computer on the desktop, select properties, and the System Properties window is displayed. Click technical support below to bring up the technical support information, now you cannot operate on the System Properties window. This is called the mode dialog box. Close the technical support information, select hardware in the system properties, and click the Device Manager. The Device Manager window is displayed, now you can still operate on the System Properties window. This is called the non-mode dialog box.
In Win32, the mode dialog box is generally created using dialogbox. The non-mode dialog box is created using createwindow. In MFC or wtl, the mode dialog box generally uses domodal, while the mode dialog box is created using create.
I,Differences in use
After the mode dialog box is created, other windows of the program cannot be operated. You must close the window before other windows can be operated. This is not required for a non-mode dialog box. It does not require immediate user response, but accepts user operations at the same time as other windows.
II,Differences between message responses
In terms of message response, the mode dialog box and the mode dialog box are very different. When the mode dialog box is created, it has an internal message pump mechanism, and the interaction between controls does not need to be manually controlled. The system will help us to process them. The non-mode dialog box is similar to a normal window, and is driven by the message loop written in winmain. But because it is a dialog box, it has special processing for some messages. Therefore, in a message loop, the dialog box must be provided with the opportunity to intercept messages.
While (getmessage (& MSG, null, 0, 0 ))
{
If (hdlgmodeless = 0 |! Isdialogmessage (hdlgmodeless, & MSG ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
}
If the received message is a dialog box message, isdialogmessage submits it to the dialog message processing function and returns true. You do not need to send more messages.
Note: This method is not very easy to use, because when there are too many dialogs, it will be more troublesome to process. Another method is to use subclass controls to process interactions between controls.
III,Destruction differences
The destroy mode dialog box uses enddialog, but the destroy mode dialog box uses destroywindow .. So we need to make a difference when destroying the dialog box.
In the non-mode dialog box, when you close the dialog box, the message processing function of the dialog box receives the wm_close message, and then calls destroywindow to destroy the non-mode dialog box.
Mode dialog box, usually returns the idok and idcancel. On PPC, we need to pay attention to this when handling the OK and X keys.
IV,Others
The template of the non-modal dialog box must have the visible style; otherwise, the dialog box is invisible, and the modal dialog box does not need to set the style. The more insurance method is to call showwindow (hdialog, sw_show) to display the dialog box, regardless of whether the dialog box has the visible style.
The non-Modal Dialog Box objects are dynamically created using the new operator in the heap, instead of being embedded into other objects in the form of member variables or built on the stack in the form of local variables. Generally, a pointer member variable pointing to the dialog box class should be declared in the dialog box owner's window class, through which the dialog box object can be accessed.
Call the create function to start the dialog box instead of domodal, which is the key to the modal dialog box. Since the create function does not start a new message loop, the dialog box and the application share the same message loop, so that the dialog box will not monopolize user input. Create returns the result immediately after the dialog box is displayed, while domodal returns the result only after the dialog box is closed. As we all know, in the MFC program, the lifetime of the window object should be longer than the corresponding window, that is, the corresponding window object cannot be deleted without closing the window on the screen. After the return result of create, you cannot determine whether the dialog box is closed or not, so you cannot determine the lifetime of the dialog box object. Therefore, you have to build the dialog box object in the heap, it cannot be constructed in the form of local variables.
Because the non-Modal Dialog Box object is built using the new operator, you must use the delete operator to delete the dialog box object after the dialog box is closed.
There must be a flag indicating whether the non-modal dialog box is open. The reason for this is that you may choose to open the command again when opening a modal dialog box. The program determines whether to open a new dialog box or simply activate the original Dialog Box Based on the flag. Generally, the pointer to the dialog box object in the owner window can be used as this flag. When the dialog box is closed, a null value is assigned to the pointer to indicate that the dialog box object does not exist.
Note: In C ++ programming, a common method to determine whether an object in the heap exists is to determine whether the pointer to this object is null. This mechanism requires the programmer to initialize the pointer to the object to a null value, assign the returned address to the pointer when creating the object, and set the pointer to a null value when deleting the object.
|
Mode |
Non-Modal |
Form |
① A mode dialog box is a pop-up window with system menus, title bars, and edges. In the create dialog box, specify the ws_popup, ws_sysmenu, ws_caption, and ds_modalframe styles. The Mode dialog box is displayed even if the ws_visible style is not specified.
② When creating the dialog box window, send the wm_initdialog message (if the ds_setfont style of the dialog box is specified, and the wm_setfont message is also sent) to the dialog box. (The dialog box window process is provided by the Windows system. When you create a dialog box window, a dialog box is called by the window process .)
③ After a dialog box window is created, windows makes it an activation window and remains activated until the dialog box is called during the process: run the enddialog function end dialog box or activate another application in windows, during activation, the user or application cannot activate its owner window ). |
① A stateless dialog box is a pop-up window with system menus, title bars, and edges. Specify the ws_popup, ws_caption, ws_border, and ws_sysmenu styles when creating a dialog box template. If the ws_visible style is not specified, the dialog box without mode is automatically displayed.
② A non-mode dialog box neither disallows the window nor sends messages to it. When a mode dialog box is created, windows makes it an active window, but users or programs can change and set the active window at any time. If the dialog box is not activated, even if the window to which it belongs is active, it remains above the window in the z-axis sequence.
|
Create |
Domodal () |
Create () |
Destroy |
An application destroys a mode dialog box by calling the: enddialog function. Generally, when you select the close command from the system menu or press OK or cancel, the enddialog is called by the dialog box. When calling: enddialog, specify the value of its nresult parameter. In Windows, this value is returned after the destruction dialog box window. Generally, the program checks whether the task has been completed or canceled by the user in the dialog box through the return value.
※Enddialog (idc_button_default); in our code, the enddialog method is called at the end of the specified button to close the dialog box. |
Before the application ends, it must destroy all modeless dialogs. Use: destroywindow to destroy a dialog box without using: enddialog. In general, the dialog box responds to user input. If the user selects the "cancel" button, the system automatically calls: destroywindow. If the user does not have any action, the application must call: destroywindow. |