Reputation: 11309
I have hooked WM_SETFOCUS message by calling API
hhookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, HookCallWndProc, hInst, threadID);
Hook Procedure is
extern "C" LRESULT _declspec(dllexport) __stdcall CALLBACK HookCallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION) {
CWPSTRUCT* info = (CWPSTRUCT*) lParam;
if(info->message == WM_SETFOCUS )
{
if(info->hwnd == hControl)
{
MessageBox(NULL,L"Focus on control",L"Focus",MB_OK);
}
}
}
return CallNextHookEx(hhookCallWndProc , nCode, wParam, lParam);
}
Now when I focus on the control, this hook procedure is getting called . MessageBox is shown. But as soon as I click on Ok , another message pops up.
Messages keep on popping up infinitely. I want to get messagebox only once whenever I focus on control, but here I am getting messages infinitely.
Anything I am doing wrong.
Upvotes: 1
Views: 1559
Reputation: 17842
Whenever debugging your application better create log file to save the information. You have commented that keyboard event is tracked more than four times.
Upvotes: 0
Reputation: 11492
I think the problem is that with the message box you take away the focus and when clicking ok you give back the focus to the control, so your hook is called again. I would recommend to try print out something using the OutputDebugString instead of using a message box.
Upvotes: 2
Reputation: 38603
Quick guess - doesn't closing a message box force a re-focus of the control and therefore call your function again?
Upvotes: 4