Win32 user interface design foundation Dialog

xiaoxiao2021-03-06  78

The dialog is divided into a modal dialog and a non-modular dialog. Creating a Modal dialog box with DialogBox (), creating a non-modal dialog with createDialog (), a dialog box usually should have a parent window, dialog Positioning the coordinate system of the parent window, the parent window close the dialog is also closed. If the Modal Dialog box does not have the feature of the modal dialog (the user must processes the requirements of the modal dialog). For example, using MessageBox (NULL, "Message", "ERROR", MB_OK) pops up a warning dialog box blocks the user's further operation, but the first parameter specifies its parent window to null, the information box will no longer have an expected function, When the dialog is displayed, the user can still operate in the main window of the program.

I. Modal dialog and non-modular dialog

1, call the modal dialog

After calling DialogBox () or DialogBoxIndirect (), the modal dialog is displayed, and his parent window is connected to a WM_CANCELMODE message requesting it to release the capture of the mouse, for the dialog box. The dialog has its own message queue. When the message queue is idle, its parent window will receive the WM_ENTRYIDLE message, which can be operated in the process of handling this message. The message queue of the PeekMessage () monitoring dialog should be continuously invoked during processing, and the control is transferred to the dialog in the discovery message.

2, call the non-modular dialog

Call CREATEDIALOG () or createDialogindirect (), parameters, and Dialogbox () parameters are identical, but the Non-Modular dialog box will not be displayed automatically, so call the showWindow () function, or edit the dialog in the resource editor. The specified dialog box is Visible. E.g:

ShowWindow (CreateDialog (HinST, (LPCSTR) IDD_DIALOG, HWND, (DLGPROC) DLGPROC, TRUE

Second, dialog box template

The dialog template is used to describe the appearance of a dialog and the control therebetween, and a dialog box can use a dialog resource in the executable, or a memory template.

1. Use a memory template to establish a dialog

The memory dialog template consists of two parts. The first part is a DLGTemplate (or DLGTEMPLATEX) structure, the integral structure of the dialog, the second part is a number of DLGItemTemplate (or DLGITEMTEMPLATEX) structure, the control inside the dialog, the template is established CreateDialogindirect () or dialogboxindirect () function establishment dialog box with CREATEDIALOGIRECT () or DialogBoxIndirect () function

2, DLGTEMPLATE structure

Typedef struct {dWord style; dWord dwextendedStyle; Word Cdit; Short X; Short Y; Short Cx; Short Cy;} DLGTemplate, * LPDLGTEMPLATE

Third, DLGITEMTEMPLATE structure

Typedef struct {dword; dword dwextendedStyle; Short X; Short Y; Short CX; Short Cy; Word ID; // on window 45/98, this is a byte.} DLGItemTemplate, * PDLGItemTemplate;

Fourth, Modeless dialog

1, call non-modular dialog

if (IsWindow (hwndDlg)!) {hwndDlg = CreateDialog (hInst, (LPCSTR) IDD_DLG, hWnd, (DLGPROC) DlgProc); ShowWindow (hwndDlg, SW_SHOW);} IsWindow () if the function determines hwndDlg already pointing a window, if the return TRUE, the dialog has been displayed, no need to call the dialog, if false is returned, call the CREATEDIALOG () Display dialog box. It should be noted that hwnddlg must declare a global variable instead of a private variable of the dialog function, otherwise each dialog function is called to reinitialize the variable iswindow (hwnddlg) General Fang False, the above judgment statement is similar to the same dummy . At the same time, hWnddlg = null should be invoked before, otherwise the dialog is turned off, ISWINDOW (HWNDDLG) always returns True, and can no longer beaten.

2, handle non-modular dialog messages

For non-modular dialogs, the messages received by the dialog may be passed to the parent window, so you can distinguish the message from the window and from the dialog box before the message processing of the parent window:

IF (! isDialogmessage (& msg)) {TranslateMessage (& MSG); DispatchMessage (& MSG);

转载请注明原文地址:https://www.9cbs.com/read-93372.html

New Post(0)