c++ - SendMessageCallback usage example -


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

i v been searching everywhere cant find single working thing in c on how done. there seems several calls totally confused me. perhaps can put small example on how declare callback post message it?

thank you

i assume comfortable plain ol' sendmessage. step there sendmessagecallback not long.

first, at

lresult winapi sendmessage(__in  hwnd hwnd,                            __in  uint msg,                            __in  wparam wparam,                            __in  lparam lparam); 

then at

bool winapi sendmessagecallback(__in  hwnd hwnd,                                 __in  uint msg,                                 __in  wparam wparam,                                 __in  lparam lparam,                                 __in  sendasyncproc lpcallback,                                 __in  ulong_ptr dwdata); 

it's glaringly obvious differing parts sendasyncproc , ulong_ptr parameters of sendmessagecallback.

the lpcallback there name of callback of yours called os when hwnd window procedure returns after handling message msg sent it.

the type of lpcallback sendasyncproc, declared as

void callback sendasyncproc(__in  hwnd hwnd,                             __in  uint umsg,                             __in  ulong_ptr dwdata,                             __in  lresult lresult); 

the dwdata there kind of data want use inside callback, whenever gets called. pointer complex data, struct or c++ class. in case lifetime of memory must considered carefully, it's valid when callback called. dwdata can simple integer data looks like.

bringing together, then. in code call sendmessagecallback (error checking omitted readability):

sendmessagecallback(hwnd, wm_foo, 0, 0, mysendasyncproc, (ulong_ptr)mydata); 

but, hmmm, since exercise, let's assume mydata 0:

sendmessagecallback(hwnd, wm_foo, 0, 0, mysendasyncproc, 0); 

that means have declared callback mysendasyncproc:

void callback mysendasyncproc(__in  hwnd hwnd,                               __in  uint umsg,                               __in  ulong_ptr dwdata,  // *the* 0                               __in  lresult lresult)   // result callee {     // whohoo! called me back! } 

and callback called when wm_foo message has been handled.

that pretty sums up.


Comments

Popular posts from this blog

delphi - TJvHidDeviceController "DevicePath" always showing "\" -

Disabling Android home button for industry application -

java - where to store the user credentials in an enterprise application(EAI)? -