Message mechanism in SDK

xiaoxiao2021-03-06  18

I have learned so long, I still understand the WINDOWS message mechanism, I can't help enough, I will put the SDK in the SDK in the SDK; first, this article is written in the case of the information. If there is a mistake there, I hope that the visitor help me correct, the younger brother is grateful.

The first is the message to be structured:

Old way to check MSDN

The MSG Structure Contains Message Information from A Thread's Message Queue.

Syntax

Ypedef struct {hWnd hwnd; uint message; wparam wparam; lparam lparam; dword time; point pt;} msg, * pmsg; members

hwnd Handle to the window whose window procedure receives the message // window handle messages directed message Specifies the message identifier Applications can only use the low word;.. the high word is reserved by the system // message identifier obtained indicating the application. The program can only use low bytes, high bytes as retention word WParam Specifies Additional Information About The Message. The exact meaning depends on the value of the message message. // Ruplely meaning different news has different Means LParam Specifies Additional information about the message. the exact meaning depends on the value of the message member. // Wparam and defined as time Specifies the time at which the message was posted. // pt Specifies the message transmission time of the cursor position, in screen coordinates, when the message is posted. // Indicates that the coordinates sent by the message is not what the message structure is more.

The key place is how messages are sent to how to be processed.

If you understand these two aspects, you should understand the news mechanism in the SDK.

The first is the message of the message: I started the problem is when a window will send a message? How to send a message in a function? That is, how to call the message function in a function to send a message and make the formulated window to make a corresponding action.

Send a message to the window: send, send, and broadcast. The function of sending messages has SendMessage, SendMessageCallback, SendNotifyMessage, SendMessageTimeout;

The function of sending messages is mainly postmessage, postthreadmessage, postquitmessage;

Broadcast messages I know only BroadcastsystemMessage, BroadcastsystemMessageex.

Look at it first is to take SendMessage. . .

MSDN:

The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message immediately, queue and return use the postmessage or postthreadMessage function.

// sendMessage Sends a message waiting to return the result, use sendMessageCallback or sendnotifyMessage to return to send a message to a thread SYNTAX using PostMessage or PostthreadMessage

LResult SendMessage (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM); parameters

hWnd [in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up Windows; but the message is not Sent to child windows.

If this parameter is the HWND_Broadcast message will be sent to all top windows including failure, hide, overlap, and pop-up windows, but this message does not send to the child window MSG [in] specifies the message to be sample. Wparam [in] Specifies Additional Message- Specific Information. LParam [in] Specifies Additional Message-Specific Information.Return Value

IT Depends on the message;

Remarks

Applications That NEED To Communicate Using HWND_Broadcast Should Use The RegisterWindowMessage Function To Obtain a Unique Message for Inter-Application Communication.

The System Only Does Marshalling for System Messages (Those In The Range 0 To WM_USER) To ANOTHER Process, You Must Do Custom Marshalling.

The above sentence is a critical part of the message mechanism, please help me translate, thank you first if the specified window was created by The calling thread, The window procedure is caled immediately as a subsroutine. If the specified window Was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. However, the sending thread will process incoming nonqueued messages while waiting for its message to be processed. to prevent this, use SendMessageTimeout with SMTO_BLOCK set. for more information on nonqueued messages, see nonqueued messages.

There are 3 functions of the message: getMessage, PeekMessage, WaitMessage.

We use the SDK writer to use the following code.

switch (message) {case WM_COMMAND: wmId = LOWORD (wParam); wmEvent = HIWORD (wParam); // Parse the menu selections: switch (wmId) {case IDM_ABOUT: DialogBox (hInst, (LPCTSTR) IDD_ABOUTBOX, hWnd, (DLGPROC About; break; case IDM_EXIT: DESTROYWINDOW (HWND); Break; Default: Return DefWindowProc (hwnd, message, wparam, lparam);}

The code is executed in the case where the message is small, but the news will be too bad for a long time.

If the concept of messaging is proposed

Here are some of Windowsx.h

/ ****** Message Crackers ************************************************ *********** /

#define handle_msg (hwnd, message, fn) / case (message): Return Handle _ ## message (hwnd), (wparam), (lParam), (FN))

/ * Void CLS_OnCompacting (HWND HWND, UINT Compactratio) * / # define handle_wm_compacting (hwnd, wparam, lparam, fn) / ((hWnd) (UINT) (WPARAM)), 0L) #define forward_wm_compacting (hwnd , compactRatio, fn) / (void) (fn) ((hwnd), WM_COMPACTING, (WPARAM) (UINT) (compactRatio), 0L) / * void Cls_OnWinIniChange (HWND hwnd, LPCTSTR lpszSectionName) * / # define HANDLE_WM_WININICHANGE (hwnd, WPARAM, LPARAM, FN) / ((hWnd), (LPCTSTSTR) (LPARAM)), 0L) #define Forward_WM_WININICHANGE (HWND, LPSZSECTIONNAME, FN) / (VOID) ((hwnd), WM_WININICHANGE, 0L, (LPCTSTR) (LPSZSECTIONNAME)

/ * Void CLS_ONSYSCOLORCHANGE (HWND HWND) * / # define handle_wm_syscolorchange (hwnd, wparam, lparam, fn) / (hwnd), 0L) #define forward_wm_syscolorchange (hwnd, fn) / (void) (FN) ((FN) (( HWnd, WM_SYSCOLORCHANGE, 0L, 0L)

/ * BOOL Cls_OnQueryNewPalette (HWND hwnd) * / # define HANDLE_WM_QUERYNEWPALETTE (hwnd, wParam, lParam, fn) / MAKELRESULT ((BOOL) (fn) (hwnd), 0L) #define FORWARD_WM_QUERYNEWPALETTE (hwnd, fn) / (BOOL) ( DWORD) (FN) ((hWnd), WM_QuerynewPalette, 0L, 0L)

/ * Void Cls_OnPaletteIsChanging (HWND hwnd, HWND hwndPaletteChange) * / # define HANDLE_WM_PALETTEISCHANGING (hwnd, wParam, lParam, fn) / ((fn) ((hwnd), (HWND) (wParam)), 0L) #define FORWARD_WM_PALETTEISCHANGING (hwnd , hwndPaletteChange, fn) / (void) (fn) ((hwnd), WM_PALETTEISCHANGING, (WPARAM) (HWND) (hwndPaletteChange), 0L) ................... ................................

Below is a diverted effect Switch (hwnd, wm_command, msgcracker; handle_msg (hwnd, wm_destroy, msgcracker); Default: Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);

Tomorrow is studying it.

Sleep :(

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

New Post(0)