SendMessageCallback example

http://msdn.microsoft.com/en-us/library/ms644951%28v=VS.85%29.aspx

I searched everywhere, but could not find one working thing in c, how to do this. There seem to be some challenges that completely confused me. Perhaps someone can give just a small example of how to declare this callback and then send a message to it?

thank

+3
source share
1 answer

I guess you are perfectly comfortable with simple ol ' SendMessage. Step from there to SendMessageCallbacknot so long.

First look

LRESULT WINAPI SendMessage(__in  HWND hWnd,
                           __in  UINT Msg,
                           __in  WPARAM wParam,
                           __in  LPARAM lParam);

Then look

BOOL WINAPI SendMessageCallback(__in  HWND hWnd,
                                __in  UINT Msg,
                                __in  WPARAM wParam,
                                __in  LPARAM lParam,
                                __in  SENDASYNCPROC lpCallBack,
                                __in  ULONG_PTR dwData);

It is clear that the different parts are parameters SENDASYNCPROCand ULONG_PTR SendMessageCallback.

lpCallBack , , hWnd Msg, .

lpCallBack SENDASYNCPROC,

VOID CALLBACK SendAsyncProc(__in  HWND hwnd,
                            __in  UINT uMsg,
                            __in  ULONG_PTR dwData,
                            __in  LRESULT lResult);

dwData - , , , . , ++. , . dwData , .

. SendMessageCallback ( ):

SendMessageCallback(hWnd, WM_FOO, 0, 0, MySendAsyncProc, (ULONG_PTR)myData);

, , , , myData 0:

SendMessageCallback(hWnd, WM_FOO, 0, 0, MySendAsyncProc, 0);

, MySendAsyncProc:

VOID CALLBACK MySendAsyncProc(__in  HWND hwnd,
                              __in  UINT uMsg,
                              __in  ULONG_PTR dwData,  // This is *the* 0
                              __in  LRESULT lResult)   // The result from the callee
{
    // Whohoo! It called me back!
}

, WM_FOO .

.

+9

Source: https://habr.com/ru/post/1793405/


All Articles