Windows Programming Study Notes (13)

Source: Internet
Author: User

Chapter 9 Dialog Box

Modal Dialog Box 

There are two types of dialog boxes: [modal] and [non-modal]. The modal dialog box means that when we end this dialog box, we can interact with another dialog box in the same program, however, we can switch to other programs. The non-modal dialog box does not have this property.

After a dialog box is created, a created template is generated, for example:

 ABOUTBOX DIALOG DISCARDABLE  32, 32, 180, 100 

STYLE DS_MODALFRAME | WS_POPUP

FONT 8, "MS Sans Serif"

BEGIN

DEFPUSHBUTTON "OK",IDOK,66,80,50,14

ICON "ABOUT1",IDC_STATIC,7,7,21,20

CTEXT "About1",IDC_STATIC,40,12,100,8

CTEXT "About Box Demo Program",IDC_STATIC,7,40,166,8

CTEXT "(c) Charles Petzold, 1998",IDC_STATIC,7,52,166,8

END

· Where dialog discardable is the keyword, and the last four digits are the position and size of the dialog box, and the position is displayed relative to the parent window.

· Then the style

· Font font

Of course, we can also adjust these items in the dialog box properties.

If we want to use our custom controls in the dialog box, such as an elliptical OK button, we can use a subwindow to implement:

· First register a class in the main function, "OK _button"

· Then we can add a control in the above template: "OK _button", which can be written as follows:

Control "OK", idok, "OK _button", ws_group | ws_tabstop

· In this way, we can create a custom button in dialog.

 

Dialog Box Handler

Bool callback dialogproc (hwnd, uint, wparam, lparam );

Differences between the dialog box handler and the window message handler:

· Window message processing program wndproc returns lresult, while dialogproc returns bool

· If wndproc does not process the message, defwindowproc will be called. If dialogproc does not process the message, false will be returned.

· The Dialog Box program does not need to process the wm_paint or wm_destroy message. The Dialog Box program does not accept the wm_reate message, but initializes the dialog box during wm_initdialog message processing.

Activation dialog box

If we display a defined dialog box, we can do this:

Dialogbox (hinstance, makeintresource (idd_dialog), hwnd, dialogproc );

Even if the program displays a dialog box, wndproc can receive messages. We can send messages to wndproc from the dialog box program:

Sendmessage (getparent (hdlg ),...);

When we need to control the control of the dialog box, we can use functions to obtain the control handle through the dialog box handle and Control ID:

Getdlgitem (hdlg, ID );

Non-Modal Dialog Box

The non-modal dialog box allows us to switch between different dialogs in the same program. The modal dialog box is created using dialogbox, while the non-modal dialog box is created using createdialog.

The non-Modal Dialog Box differs from the modal dialog box:

· A non-modal dialog box usually contains a title column and a system menu button.

· To send messages in a non-modal dialog box to a program message queue, you must change the message queue.

· In the non-modal dialog box, destroywindow is used instead of enddialog to end the non-modal dialog box. (If the close button is used to end the dialog box, we must process the wm_close message. In Windows, the message handler in the dialog box does not process the wm_close message.

 

 while(GetMessage(&msg,NULL,0,0))
{
if(hDlgModeless == 0 || !IsDialogMessage(hDlgModeless,&msg))
  {
   TranslateMessage(&msg);
   DispatchMessage(&msg);  }}

If the message is sent to the dialog box, isdialogmessage sends it to the Message Processing Program of the dialog box and returns true. The translatemessage function must be called only when hdlgmedeless is 0 or the message is not in the dialog box.

Related Article

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.