Windows SDK Notes (3): Custom Control Message Processing Functions

zhaozj2021-02-17  82

First, the message processing function of the overview control is defined by the system, usually, does not need to be provided. However, when the control is required to be specially controlled, a message processing function can be provided to replace the original message processing function. After your own processing is complete, call the default message processing of the control.

Second, related functions 1. The properties of the window class can be read and set by getWindowlong and SetWindowlong

Long getWindowlong

HWND HWND, // Handle to Window

INT NINDEX / / Offset of Value To Retrieve

);

Long setwindowlong

HWND HWND, // Handle to Window

INT NINDEX, // Offset of Value To Set

Long Dwnewlong // New Value

); You can return or set the following:

NINDEX value meaning

GWL_EXSTYLE extension style

GWL_Style style

GWL_WNDPROC message processing function

GWL_HINSTANCE instance

GWL_ID window ID

GWL_USERDATA user data

DWL_DLGPROC dialog message processing function

DWL_MSGRESULT

DWL_USER

Use

OldMsgProc = (WndProc) Setwindowlong (hcontrolwnd, gwl_wndproc, (long) mymsgproc); replacing the control message processing function into mymsgproc, the original processing function is recorded by the OldMSGProc.

2. Call message processing function

LResult CallWindowProc

WndProc LPPREVWNDFUNC, / / ​​POINTER TO Previous Procedure

HWND HWND, // Handle to Window

Uint MSG, // Message

WPARAM WPARAM, // First Message Parameter

LParam lParam // Second Message Parameter

);

Third, example

1. Provide new processing functions

// Record global variables for the original handler

WndProc OldmsgProc;

// New message processing function

Lresult mymsgproc (hwnd hwnd, uint message, wparam wparam, lparam lparam)

{

Switch (Message)

{

Case WM_LBUTTONDOWN:

:: MessageBox (NULL, Click! "," ", MB_OK);

}

// Call the control of the controlled message processing function

Return CallWindowProc (OldmsgProc, Hwnd, Message, WPARAM, LPARAM);

}

2. After the window is created, change the message processing function.

Case WM_CREATE:

{

HWND HCONTROLWND = CREATEWINDOWEX (0, "Button",

Text ("button (& a)),

WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,

10,

10,

100,

100,

HWnd,

(HMENU) 1000, // Control ID

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

NULL);

/ / Embed a new message processing function

OldMsgProc = (WndProc) setwindowlong (hcontrolwnd, gwl_wndproc, (long) mymsgproc;

}

Return 0;

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

New Post(0)