向explorer.exe注入代码的一个小问题
我在跟踪一个向exporer.exe注入代码的程序(codeproject上的),所注入代码功能是点击"开始"按钮时左右键功能交换;
问题是:InjectDll函数要向"exporer.exe"中注入代码,为此,调用SetWindowsHookEx函数,此函数的最后一个参数GetWindowThreadProcessId (hWnd,NULL)的第一个参数是"hWnd",而"hWnd"传进来的hwnd确实"开始"按钮的句柄(第12行),
为什么GetWindowThreadProcessId 以hWnd为参数而确获得了exporer.exe的句柄?谢谢
//-------------------------------------------------------------
// InjectDll
// Notice:
// - injects "HookInjEx.dll" into "explorer.exe" (via SetWindowsHookEx);
// - subclasses the START button (see HookProc for more details);
//
// Parameters: - hWnd = START button handle
//
// Return value: 1 - success;
// 0 - failure;
//
1int InjectDll( HWND hWnd )
{
2 g_hWnd = hWnd;
3 // Hook "explorer.exe"
4 g_hHook = SetWindowsHookEx( WH_CALLWNDPROC,(HOOKPROC)HookProc,
hDll, GetWindowThreadProcessId (hWnd,NULL) );
5 if( g_hHook==NULL )
return 0;
// By the time SendMessage returns,
// the START button has already been subclassed
6 SendMessage( hWnd,WM_HOOKEX,0,1 );
7 return g_bSubclassed;
}
8 hStart = ::FindWindow ("Shell_TrayWnd",NULL); // get HWND of taskbar first
9 hStart = ::FindWindowEx (hStart, NULL,"BUTTON",NULL); // get HWND of start button
.....
10 case WM_COMMAND:
11 if( !g_bSubclassed) {
12 InjectDll( hStart );
if( g_bSubclassed )
::SetDlgItemText( hDlg, IDC_BUTTON, "Unmap Dll" );
}