在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
只知道进程ID,获取主窗口句柄的方法如下:
代码如下: function GetHwndFromProcess(const hPID: THandle): THandle; type PEnumInfo = ^TEnumInfo; TEnumInfo = record ProcessID: DWORD; HWND: THandle; end; function EnumWindowsProc(Wnd: DWORD; var EI: TEnumInfo): Bool; stdcall; var PID: DWORD; h: THandle; begin Result := True; GetWindowThreadProcessID(Wnd, @PID); if PID = EI.ProcessID then begin h := GetWindowLong(Wnd, GWL_HWNDPARENT); if h = 0 then begin EI.HWND := Wnd; Result := False; end; end; if not Result then EI.HWND := WND; end; function FindMainWindow(PID: DWORD): DWORD; var EI: TEnumInfo; begin EI.ProcessID := PID; EI.HWND := 0; EnumWindows(@EnumWindowsProc, Integer(@EI)); Result := EI.HWND; end; begin if hPID <> 0 then Result := FindMainWindow(hPID) else Result:=0; end;
by lin 2016-11-13 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论