LRESULT CALLBACK MyCallWndProc(
int
nCode, WPARAM wParam, LPARAM lParam)
{
LPCWPSTRUCT stru
=
(LPCWPSTRUCT)lParam;
if
(nCode
=
=
HC_ACTION)
{
if
(stru
-
>hwnd
=
=
g_hwnd && stru
-
>message
=
=
WM_USER
+
1
)
{
CString
str
;
str
.
Format
(L
"lParam:%d---wParam:%d"
, stru
-
>lParam, stru
-
>wParam);
OutputDebugStringW(
str
);
return
1
;
}
}
return
CallNextHookEx(g_hook, nCode, wParam, lParam);
}
bool
MyHook()
{
g_hook
=
SetWindowsHookExW(WH_CALLWNDPROC, MyCallWndProc, NULL, g_tID);
if
(!g_hook)
{
MessageBoxW(NULL, L
"Error:Hook"
, L
"Error"
, MB_OK);
return
false;
}
return
true;
}
void MyUnHook()
{
if
(g_hook)
{
UnhookWindowsHookEx(g_hook);
}
}
void NewDlg::OnBnClickedButton1()
/
/
开始hook
{
/
/
TODO: 在此添加控件通知处理程序代码
g_hwnd
=
::FindWindow(NULL, L
"T1ll"
);
if
(!g_hwnd)
{
::MessageBoxW(NULL, L
"Error:hWnd"
, L
"Error"
, MB_OK);
return
;
}
g_tID
=
GetWindowThreadProcessId(g_hwnd, NULL);
if
(!g_tID)
{
::MessageBoxW(NULL, L
"Error:tID"
, L
"Error"
, MB_OK);
return
;
}
MyHook();
}