Windows SDK Notes (2): Create controls on the window

zhaozj2021-02-17  65

The control is a sub-window, which is a system that has defined a good window class, so it does not need to be registered, nor does it need to write message processing functions. Create a sub-window when you get a WM_CREATE message at the main window.

Second, instance

// Parameter: window handle, message, message parameter, message parameters

Lresult Callback WndProc (HWND HWND, UINT MESSAGE, WPARAM WPARAM, LPARAM LPARAM)

{

// Test the message of interest

Switch (Message)

{

Case WM_CREATE:

CreateWindow (Text ("Button"), // Control "class name"

Text ("button (& a)),

WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

10,

10,

100,

100,

HWnd,

(HMENU) 1000, // Control ID

(LpcreateStruct) LPARAM -> Hinstance, // Example handle

NULL);

Return 0;

Case WM_DESTROY:

// When the user closes the window, the window is destroyed, the program needs to end, send out the message to exit the message loop

PostquitMessage (0);

Return 0;

}

/ / Other messages are handed over to the default processing function provided by the system

Return :: DefWindowProc (Hwnd, Message, WParam, Lparam);

}

Third, about WM_CREATE message

The LPARAM parameter of WM_CREATE will be incompatated to create a job structure pointer (lpCreateStruct).

The structure contains some useful information (parameters when the window is established).

Typedef struct tagcreatestruct {

LPVOID LPCREATEPARAMS;

Hinstance hinstance; // instance handle

Hmenu Hmenu;

HWND HWNDPARENT;

int Cy;

Int CX;

Int Y;

INT X;

Long style;

LPCTSTR LPSZNAME;

LPCTSTR LPSZCLASS;

DWORD DWEXSTYLE;

CreateStruct, * lpcreatestruct;

Fourth, collaboration between control and parent window

1. When an action occurs on the control, the notification message WM_COMMAND will be sent to the parent window.

WM_COMMAND:

HiWord (WPARAM): Notification Code

LOWORD (WPARAM): Control ID

(HWnd) LPARAM: Control handle

In addition to WM_COMMAND, each control may have other notification messages (such as WM_DRAWITEM).

2. When the parent window needs to control the control, send the control message to the control. The control handle should be recorded in advance, or get the control handle by the ID

3. Note: Notification of the various controls and control messages can be checked by MSDN-> Platform SDK-> User Interface Services-> Windows User Interface-> Controls.

V. Control "Class Name" 1. Standard Control Button: Composite B /T: Edit Listbox: List Richedit: Rich Edit Version 1.0RichEdit_class: Rich Edit Version 2.0 Scrollbar: Strike Static: Static

2. Common Controls included with the shell: INTCOMMONCONTROLSEX before establishing

ICMMONCONTROLSEX ICEX; // EnSure That The Common Control DLL IS loaded.icex.dwsize = sizeof (InitCommontrolsex);

Icex.dwicc = ICC_ListView_Classes;

INITCOMMONCONTROLSEX (& ICEX);

HWND HWNDLISTVIEW = CREATEWINDOWEX (0, wc_listview, // wc_listview does not need to be quoted

TEXT (""),

WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_ICON | LVS_EDITLABELS | WS_EX_CLIENTEDGE,

10,

10,

100,

100,

HWnd,

(HMENU) 1000, // Control ID

(LpcreateStruct) LPARAM -> Hinstance, // Example handle

NULL);

Animate_class

DateTimePick_class

HotKey_Class

Monthcal_class

PROGRESS_CLASS

RebarclassName

StatusClassName

ToolbarclassName

Tooltips_class

TRACKBAR_CLASS

UPDOWN_CLASS

WC_COMBOBOXEX

WC_HEADER

WC_IPAddress

WC_ListView

WC_PAGESCROLLER

WC_TABCONTROL

WC_TreeView

3. Special window MDIClient: MDI client area of ​​the window ComboLBox: The class for the list box contained in a combo box DDEMLEvent:. Windows NT / 2000: The class for DDEML events Message:. Windows 2000: The class for a message-only window . # 32769: The class for the desktop window. # 32770: The class for a dialog box. # 32771: The class for the task switch window. # 32772: Windows NT / 2000: The Class for icon titles.

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

New Post(0)