不好意思,写反了。<br>type<br> tagWNDINFO = packed record<br> dwProcessId: DWORD;<br> hWnd: HWND;<br> end;<br> PWNDINFO = ^tagWNDINFO;<br><br>function GetProcessMainWnd(dwProcessId: DWORD): HWND;<br> function EnumFunc(const hWnd: Longword; lParam: Longint): BOOL; stdcall;<br> var<br> dwProcessId: DWORD;<br> pInfo: PWNDINFO;<br> begin<br> GetWindowThreadProcessId(hWnd, dwProcessId);<br> pInfo := PWNDINFO(lParam);<br> if dwProcessId = pInfo.dwProcessId then<br> begin<br> pInfo.hWnd := hWnd;<br> Result := False;<br> end<br> else Result := True;<br> end;<br>var<br> wi: tagWNDINFO;<br>begin<br> wi.dwProcessId := dwProcessId;<br> wi.hWnd := 0;<br> EnumWindows(@EnumFunc, Longint(@wi));<br> Result := wi.hWnd;<br>end;