一个很弱的问题。(40)

  • 主题发起人 主题发起人 fxh7622
  • 开始时间 开始时间
F

fxh7622

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,如何根据窗口句柄,或者窗口标题得到进程句柄呢????
 
The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window. This function supersedes the GetWindowTask function. DWORD GetWindowThreadProcessId( HWND hWnd, // handle of window LPDWORD lpdwProcessId // address of variable for process identifier );ParametershWndIdentifies the window. lpdwProcessIdPoints to a 32-bit value that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the 32-bit value; otherwise, it does not. Return ValuesThe return value is the identifier of the thread that created the window. var iHandle : HWND; pid : DWORD;begin GetWindowThreadProcessId(WindowHandle, @pid);end;
 
楼上既是~~
 
procedure TForm1.Button1Click(Sender: TObject);var hWindow: HWND; { 窗体句柄 } dwProcessID: DWORD; { 进程 ID } hProcess: THandle; { 进程句柄 }begin { 根据标题获取窗体的句柄 } hWindow := FindWindow(nil, '标题'); { 通过窗体句柄获取进程 ID } GetWindowThreadProcessId(hWindow, dwProcessID); { 通过进程 ID 获取进程句柄 } hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, dwProcessID); { 结束该进程 } TerminateProcess(hProcess, 0);end;
 
多人接受答案了。
 
后退
顶部