1,183
社区成员
发帖
与我相关
我的任务
分享
wndInfo=packed record
dwProcessId:DWORD;
hWind:HWND;
end;
LPWNDINFO=^wndInfo;
function EnumWindowsProc(
hwnd: HWND;
lParam: LPARAM
): BOOL; stdcall;
var
vProcessID: THandle;
vBuffer: array[0..255] of Char;
nStyle:integer;
pInfo:LPWNDINFO;
begin
Result:= true;
GetWindowThreadProcessId(hwnd, vProcessID);
pInfo:=LPWNDINFO(lParam);
if vProcessID = pInfo.dwProcessId then
begin
nStyle:=GetWindowLong(hWnd,GWL_HWNDPARENT);
if nStyle=0 then
Result:=True
else
begin
pInfo.hWind:=nStyle;
Result:=FALSE;
end;
end;
end;
function GetProcessMainWnd(dwProcessId:DWORD):HWND;
var
Dwnd:wndInfo;
begin
wi.dwProcessId:=dwProcessId;
wi.wnd:=HWND(nil);
EnumWindows(@EnumWindowsProc,LPARAM(@Dwnd));
result:=Dwnd.hWind;
end;