Windows SDK Notes (5): Non-Mode dialog

zhaozj2021-02-17  84

1. Overview The dialog built using DialGbox is "Mode dialog", only the other window of the program can be operated after the dialog is closed. Correspondingly, there is a "Non-Mode Dialog" and after the dialog is established, the user does not force the user to react immediately, but to the other window simultaneously accept user operations.

Second, establish a non-mode dialog box to use createDialg. You can establish the main window in WinMain, and the dialog handle is saved.

HDLGModeless = CREATEDIALOG

Hinstance,

TEXT ("Colorscrdlg"), // dialog template

HWnd,

Colorscrdlg // dialog message processing function

);

Third, the message loop adds processing for non-mode dialogs

"Non-Mode Dialog" is different from "Mode dialog", and the mode dialog is working, there is a message pump mechanism within it.

The Non-Mode dialog is like a normal window, and the message loop drive written by WinMain.

However, since it is a dialog, it has special processing for some messages, such as the "Tab" key, "entry" key, "enter" key, "" key, etc. used in each sub-control in the dialog.

Therefore, in the message loop, you need to provide a chance to intercept messages to the dialog box.

While (GetMessage (& MSG, NULL, 0, 0))

{

IF (HDLGModeless == 0 ||! IsdialogMessage (HDLGModeless, & MSG))

{

TranslateMessage (& MSG);

DispatchMessage (& MSG);

}

}

If the currently acquired message is the dialog message, isDialgMessage handles it to the dialog message processing function and returns TRUE.

No need to distribute.

Fourth, the destruction of the non-mode dialog box:

DestroyWindow (HDLG); When the user closes the dialog, the dialog message handler will receive a WM_CLOSE message, then call DESTROYWINDOW to destroy the Non-Mode dialog.

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

New Post(0)