钩挂钩程序后无限呼叫 [英] After hooking hook procedure is called infinitely

查看:113
本文介绍了钩挂钩程序后无限呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过调用API连接了WM_SETFOCUS消息

I have hooked WM_SETFOCUS message by calling API

hhookCallWndProc = SetWindowsHookEx(WH_CALLWNDPROC, HookCallWndProc, hInst, threadID);

挂钩程序

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);
    }



现在当我专注于控件时,这个钩子程序被调用。显示MessageBox。但是一旦我点击确定,就会弹出另一条消息。

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.

消息会无限弹出。
当我专注于控件时,我只想获取一次messagebox,但这里我无限地收到消息。

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.

任何我做错了。

推荐答案

快速猜测 - 不关闭消息框强制重新控制控件,因此再次调用您的函数

Quick guess - doesn't closing a message box force a re-focus of the control and therefore call your function again?

这篇关于钩挂钩程序后无限呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆