【问题标题】:WM_PAINT Hook using SetWindowsHookExWM_PAINT Hook 使用 SetWindowsHookEx
【发布时间】:2011-07-22 21:33:38
【问题描述】:

这是我的代码

// hook.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <iostream>

using namespace std;

LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam);

int _tmain(int argc, _TCHAR* argv[]){
int __;
cout << "Hallo World" << endl;
SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, 0, 0);
cin >> __;
return 0;
}

LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam){
cout << code << endl;
return 0;
}

我正在尝试获取 WM_PAINT 事件...目前我正在尝试捕获所有事件。我在哪里失踪?

【问题讨论】:

    标签: visual-c++ setwindowshookex


    【解决方案1】:

    请阅读文档。它清楚地说明了为什么您的用法不正确,尤其是在最后两个参数方面。如果你想钩住你需要提供一个模块的每个线程 http://msdn.microsoft.com/en-us/library/ms644990(v=vs.85).aspx

    【讨论】:

    • 抱歉,您能说得详细一点吗?我已经阅读了关于最后一个参数的链接If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
    • 阅读其他参数的文档。 "指向钩子过程的指针。如果dwThreadId参数为零或指定由不同进程创建的线程的标识符,则lpfn参数必须指向DLL中的钩子过程。否则,lpfn可以指向DLL中的钩子过程与当前进程关联的代码。" "如果 hMod 参数为 NULL 并且 dwThreadId 参数为零或指定另一个进程创建的线程的标识符,则可能会发生错误。"
    • 我的 lpfn 在当前进程中。但是我希望我的 dwThreadId 应该是 0 ??这是场景吗??我在这里很乱。在这个简单的(可能)事情上。我对 VC++ 非常不友好。请我不明白我应该做什么。
    猜你喜欢
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 2011-11-23
    相关资源
    最近更新 更多