检测其他进程的窗口移动/拖动的最佳方法是什么?在 Windows7 64 位
我目前正在使用 C++ 和 C# 调查来自 DLL 的全局挂钩。这是一种痛苦,因为它不想正常工作。我在键盘和鼠标挂钩方面取得了一些成功。但是对于窗口消息,我只是不知道出了什么问题。
这是我的 .dll 文件中的代码
#include <windows.h>
#include <iostream>
#include <stdio.h>
HINSTANCE hinst;
#pragma data_seg(".shared")
HHOOK hhk;
WNDPROC realProc;
#pragma data_seg()
//#pragma comment(linker, "/SECTION:.shared,RWS") compiler error in VC++ 2008 express
LRESULT CALLBACK wireKeyboardProc(int code, WPARAM wParam,LPARAM lParam) {
//open the standard out stream for writing
freopen("CONOUT$","w+t", stdout);
printf("code:%d wparam:%d lparam:%d\n", code, wParam, lParam);
/*
if (code < 0) {
return CallNextHookEx(0, code, wParam, lParam);
}
*/
//Beep(1000, 20);
return CallNextHookEx(hhk, code, wParam, lParam);
}
LRESULT CALLBACK hookProc(HWND h, UINT msg, WPARAM wp, LPARAM lp)
{
//open the standard out stream for writing
freopen("CONOUT$","w+t", stdout);
printf("h:%d msg:%d wp:%d lp:%d\n", h, msg, wp, lp);
return CallWindowProc(realProc, h, msg, wp, lp);
}
extern "C" __declspec(dllexport) void install(unsigned long threadId, HWND hwnd) {
//open the standard out stream for writing
freopen("CONOUT$","w+t", stdout);
//works for WH_KEYBOARD WH_MOUSE but doesnt work for WH_CALLWNDPROC
hhk = SetWindowsHookEx(WH_CALLWNDPROC, wireKeyboardProc, hinst, threadId);
printf("threadId: %d xxx: %d\n", threadId, hhk);
/*
//dont know whats wrong the return value of realProc is 0
realProc = (WNDPROC)SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)hookProc);
printf("hwnd: %d xxx: %d\n", hwnd, realProc);
*/
}
extern "C" __declspec(dllexport) void uninstall() {
UnhookWindowsHookEx(hhk);
}
BOOL WINAPI DllMain(__in HINSTANCE hinstDLL, __in DWORD fdwReason, __in LPVOID lpvReserved) {
hinst = hinstDLL;
return TRUE;
}
我正在考虑制作自己的 Aero Snap。这只是为了好玩。
谢谢你的帮助。