C++ WinAPI:如何从用户输入中捕获每条消息?
我想抓住:C++ WinAPI:如何从用户输入中捕获每条消息?,c++,visual-studio-2008,winapi,windows-xp,C++,Visual Studio 2008,Winapi,Windows Xp,我想抓住: 窗口大小调整/移动/最小化/最大化/关闭消息 鼠标点击和键盘按下 当用户按enter或dblclick执行任何程序时。(如果可能的话?) 这应该与keylock程序的工作方式相同:如果您执行某些事件,我可以通过我的程序决定是否让Windows处理它,或者我是否处理它,或者两者兼而有之 我怎样才能做到这一点呢?正如汉斯·帕桑所指出的,您需要这个功能。 在链接中,详细解释了所有可能的钩子,以及需要实现的钩子函数。下面是一个小例子,如何安装一个全局钩子,在消息被窗口处理后处理它们 int
我怎样才能做到这一点呢?正如汉斯·帕桑所指出的,您需要这个功能。
在链接中,详细解释了所有可能的钩子,以及需要实现的钩子函数。下面是一个小例子,如何安装一个全局钩子,在消息被窗口处理后处理它们
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
HHOOK msgHook = SetWindowsHookEx(WH_CALLWNDPROCRET, msgHook, hInstance, 0);
if(msgHook == NULL){
//Error handling here
cout << "Failed to set hook";
}
else{
//Hook has been set and will automatically be removed, when your application exits.
}
//A clean shutdown should always unhook everything it has installed
UnhookWindowsHookEx(msgHook);
return 0;
}
要安装的其他挂钩遵循相同的原则
另见
在链接中,详细解释了所有可能的钩子,以及需要实现的钩子函数。下面是一个小例子,如何安装一个全局钩子,在消息被窗口处理后处理它们
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
HHOOK msgHook = SetWindowsHookEx(WH_CALLWNDPROCRET, msgHook, hInstance, 0);
if(msgHook == NULL){
//Error handling here
cout << "Failed to set hook";
}
else{
//Hook has been set and will automatically be removed, when your application exits.
}
//A clean shutdown should always unhook everything it has installed
UnhookWindowsHookEx(msgHook);
return 0;
}
要安装的其他挂钩遵循相同的原则
另见