Windows SDK Notes (6): Using dialog box resource creation windows

zhaozj2021-02-17  63

1. Overview In Charles Petzold book, a method of directly utilizing dialog resource establishing a main window is introduced. Using this method, it can be convenient to arrange child controls in the main window, and the other parts of the code are the same as a normal window.

We know that the dialog is a "window class" pre-defined system. It has its own window handling function, and our own written dialog message processing function is not a real window message processing function. But we can specify this dialog in the dialog template script, specify this dialog, instead of the system's dialog box class, so that the message processing function of the dialog is "grafted" to our own defined message processing Function.

Second, writing a "real" window message processing function writes a message processing function in a normal window. (Don't miss defWindowproc)

Third, registration window class registers a window class with a message processing function written.

Fourth, establish a dialog resource, specify the window class as a custom window class. Hand writing a dialog resource, saving a separate file, and then inciting to the resource file. (Use the Menu View-> Resource INCLUDES pop-up dialog box, fill the file name into the Compile-Time Derective column, which will add a line in the RC file: "# include" "Some.dlg" ") Example: Create a file Some.dlg writing:

HEXCALC DIALOG -1, -1, 102, 122

STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX

Class "HEXCALC" // Fill in the class name of the registration

Caption "HEX Calculator"

{

Pushbutton "D", 68, 8, 24, 14, 14

Pushbutton "A", 65, 8, 40, 14, 14

// Various controls

}

5. Use a non-mode dialog box to establish a main window.

When establishing a main window, use CreateDialog.

HWND = CREATEDIALOG

Hinstance,

SZAPPNAME, / / ​​Dialog Template

0,

NULL);

ShowWindow (hwnd, icmdshow);

All other parts are the same as normal windows (registration window, message loop, etc.).

II. Build a custom sub-window in the dialog

You can define your own control and use it in the dialog template.

1. Define the "Window Class" and message processing function In addition to the registration main window class in WinMain, the class for the dialog is registered, indicating the message processing function of the class.

WNDCLASS.Style = CS_HREDRAW | CS_VREDRAW;

WNDCLASS.LPFNWNDPROC = SomeWndProc; // Corresponding message processing function

WNDCLASS.CBCLSEXTRA = 0;

Wndclass.cbWndextra = 0;

WNDCLASS.HINSTANCE = HINSTANCE;

WNDCLASS.HICON = NULL;

WNDCLASS.HCURSOR = loadingcursor (null, idc_arrow);

WNDCLASS.HBRBACKGROUND = (Hbrush) (Color_BTNFACE 1);

WNDCLASS.LPSZMENUNUNAME = NULL;

Wndclass.lpszclassname = text ("someControl");

RegisterClass (& WNDCLASS); at the same time, you have to write a good message handler SomeWndProc.

Second, add a custom control window in the dialog template to put "Custom Control" on the dialog template, then set the properties, and fill in the class name SomeControl.

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

New Post(0)