1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
1.create a thread
HWND mainWnd =((CWnd *)g_pCalltaker_form)->GetSafeHwnd();
HANDLE hc = (HANDLE)_beginthread( PostAcceptEvent, 0, mainWnd );
2.postMessage
void PostAcceptEvent( void *dummy )
{
HWND mainWnd =(HWND)dummy;
long state = 3;
::PostMessage(mainWnd,WM_POST_BUTTONSATE,state,0);
}
3. SetWindowsHookEx (The currentThread is the main window thread)
g_hookHandle = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, NULL, GetCurrentThreadId());
4.CallWndProc
LRESULT CALLBACK CallWndProc(int ncode, WPARAM wParam, LPARAM lParam)
{
if (ncode != HC_ACTION )
{
return CallNextHookEx(g_hookHandle, ncode, wParam, lParam);
}
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWPSTRUCT *Struct = (CWPSTRUCT *)lParam;
if (WM_POST_BUTTONSATE==Struct->message )
{
log.debug() << "--WM_POST_BUTTONSATE,wParam="<<(long)Struct- >wParam<<",lParam="<<(long)Struct->lParam<<"\n";
}
}
|