MFC Tutorials (12)--dialog box and dialog box class CDialog (1)

Source: Internet
Author: User
Tags message queue

dialog boxes are often used because dialog boxes can be created from templates, and dialog templates can be easily edited using the resource editor.

Mode and modeless dialog boxes

The dialog box is divided into two types, a modal dialog box and a modeless dialog box.

modal dialog box

A modal dialog box is a pop-up window with a system menu, title bar, sideline, and so on. Specify Ws_popup, Ws_sysmenu, ws_caption, and Ds_modalframe styles when creating dialog boxes. The modal dialog box is displayed even if the ws_visible style is not specified.

When you create a dialog window, you send a WM_INITDIALOG message (if you specify the Ds_setfont style of the dialog box, as well as the Wm_setfont message) to the dialog box procedure.

The dialog box procedure (Dialog box procedure) is not a window procedure (Windows procedure) for a dialog window. In Win32, the dialog window process is provided by the Windows system, and the user provides a dialog box that is invoked by the window procedure when the dialog window is created.

After the dialog window is created, Windows makes it an active window, which remains active until the dialog box procedure is invoked:: The EndDialog function ends the dialog box or Windows activates another application, when activated, The user or application may not be able to activate its owning window (Owner window).

When you create a modal dialog box from a window, Windows automatically disables the use of (Disable) This window and all its child windows until the modal dialog is closed and destroyed. Although the dialog box process can enable the owning window, doing so loses the function of the modal dialog box, so it is discouraged.

When Windows Create modal dialog box, send a message wm_canclemode to the window that is currently capturing mouse input (if any). When this message is received, the application should terminate mouse capture (release the mouse capture) so that the user can move the mouse over the modal dialog box, otherwise the program loses mouse input because the owner window is blocked.

To handle a message in a modal dialog box, Windows starts the message loop itself, temporarily controlling the message queue for the entire application. If Windows receives a non-dialog message, it sends the message to the appropriate window, and if the Wm_quit message is received, the message is put back into the application's message queue so that the application's main message loop can eventually process the message.

When the application's message queue is empty, Windows sends a WM_ENTERIDLE message to the owner window. When the dialog box runs, the program can use this message for background processing, and of course should pay attention to often give up control to the modal dialog box so that it can receive user input. If you do not want the modal dialog box to send a wm_enteridle message, specify the ds_noidlemsg style when you create the modal dialog box.

An application destroys a modal dialog box by invoking the:: EndDialog function. In general, when the user selects the Close command from the system menu or presses the OK or cancel (cancle) button,:: EndDialog is invoked by the dialog box procedure. When called:: enddialog Specifies the value of its parameter nresult, Windows returns the value after the dialog window is destroyed, in general, the program returns the value to determine whether the dialog window completes the task or is canceled by the user.

modeless dialog box

A modeless dialog box is a pop-up window with a system menu, title bar, sideline, and so on. Specifies the Ws_popup, ws_caption, Ws_border, and Ws_sysmenu styles when creating a dialog box template. If you do not specify a ws_visible style, the modeless dialog box is not automatically displayed.

A modeless dialog box neither prohibits the owning window nor sends a message to it. When you create a modal dialog box, Windows makes it the active window, but the user or program can change and set the active window at any time. If the dialog box is inactive, it is still above the owning window in the z-axis order, even if the owning window is active.

The application is responsible for obtaining and distributing input messages to the dialog box. Most applications work with the main message loop, but the application should call:: IsDialogMessage function for users to be able to use the keyboard to move between control windows or to select Control Windows.

Here, by the way, explain:: IsDialogMessage function. Although the function is designed for modeless dialogs, any window that contains a control child window can be invoked to implement a keyboard selection action similar to a dialog box.

When:: IsDialogMessage processes a message, it checks the keyboard messages and converts them to the selection command for the corresponding dialog box. For example, when the TAB key is pressed, the next or next group of controls is selected, and when the DOWN ARROW key is pressed, the next control in a group of controls is selected.

:: IsDialogMessage completes all necessary message conversions and message distribution, so the message processed by this function must not be passed to TranslateMessage and dispatchmessage processing.

A modeless dialog box cannot return a value to an application like a modal dialog box. However, the dialog box procedure can use:: SendMessage to pass information to the owning window.

Before the application ends, it must destroy all modeless dialog boxes. Use::D Estroywindow destroys a modeless dialog box, not using:: EndDialog. In general, a dialog box procedure responds to user input, such as when the user chooses the Cancel button, and then calls::D Estroywindow; If the user does not have an action, the application must call::D Estroywindow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.