Windows SDK Notes (4): Mode dialog

zhaozj2021-02-17  69

First, the Overview Dialog is a special window that is established according to the dialog template resources. It is different from the general window, many processes are completed by the system, although the user still provides a message processing function, but in this message processing function, there is no need to confirm the message processing function. In fact, the process of calling the default process is completed.

Second, the dialog message processing function dialog also requires the user to provide a message processing function, but this processing function does not have the message processing function of the normal window "right". The dialog is a system-defined "window class" that has defined the corresponding message processing function. The message processing function made by the customer is not directly connected to the window, but a supplement to the dialog message processing function, or "embedded". Therefore, the dialog processing function does not need to call the "default message processing function". When there is a message being processed, returns true, no message needs to be processed, returns false, and after exiting the user message processing function, the system will depass the provincial message processing function.

// Dialog Box Message Processing Function

// The return value is BOOL, which is different from the normal window processing function.

Bool Callback AboutdlgProc (HWND HDLG, Uint Message, WPARAM WPARAM, LPARAM LPARAM)

{

Switch (Message)

{

Case WM_INITDIALOG:

Return true; // Return true, indicating that the message is processed.

Case WM_COMMAND:

Switch (loword (wparam))

{

Case IDOK:

Case IDCANCEL:

Enddialog (HDLG, 0); // Close dialog using EndDialog

Return true; // Return true, indicating that the message is processed.

}

Break;

}

Return False; return false, indicating that the message is not processed by the user, and the default message processing function is dealtled.

}

Third, the mode dialog is established

Use Dialogbox.

INT_PTR DIALOGBOX

Hinstance Hinstance, // Handle to Module

LPCTSTR LPTEMPLATE, / / ​​DIALOG BOX TEMPLATE

HWND HWNDPARENT, // Handle To Owner Window

DLGPROC LPDIALOGFUNC / / DIALOG BOX Procedure

);example:

Case WM_COMMAND:

Switch (loword (wparam))

{

Case id_about:

Dialogbox (Hinst, MakeintResource (IDD_ABOUT), HWND, ABOTDLGPROC;

Break;

}

Return 0;

Fourth, mode dialog and program interaction

In the Mode dialog, the data in the program can be changed.

End the dialog box, incoming an exit parameter in the second parameter of EndDialog

This parameter will be DialogBox as the return value, and then the user of the dialog is based on this return value.

Initialization

In the dialog message processing function, make some initialization work when receiving the WM_INITDIALOG message.

If you read the initial value from the global variable to set the status of each control.

2. When exiting

If you exit, the changes need to take effect (if "OK") is pressed, the global variable is set according to the control status and the corresponding value (such as true) is used in EndDialg.

If the change does not need to take effect (such as "cancel"), the result is not saved, and a value (such as false) is used in EndDialg in EndDialg.

3. Dialog box users respond

Different operations according to Dialogbox's return value

For example, when returning True, redraw window: IF (DialogBox (Hinstance, Text ("AboutBox"), HWND, ABOTDLGPROC)

InvalidateRect (HWND, NULL, TRUE);

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

New Post(0)