프로그래밍/델파이
주어진 프로세스 ID의 IE에 대한 IWebBrowser2 구하기
채윤아빠
2008. 2. 29. 15:12
function GetWebBrowser2(nProcessID: THandle):IWebBrowser2;
var
x: Integer;
AShellWindows: IShellWindows;
AWebBrowser2:IWebBrowser2;
dwProcessID: Cardinal;
begin
Result := nil;
AShellWindows := CoShellWindows.Create;
for x := 0 to AShellWindows.Count - 1 do
begin
if ((AShellWindows.Item(x) <> nil)
and (AShellWindows.Item(x).QueryInterface(IWebbrowser2, AWebBrowser2) = S_OK)) then
begin
GetWindowThreadProcessId(AWebbrowser2.HWND, dwProcessID);
if (dwProcessID = nProcessID) then
begin
Result := AWebbrowser2;
Exit;
end;
end;
end;
end;
var
x: Integer;
AShellWindows: IShellWindows;
AWebBrowser2:IWebBrowser2;
dwProcessID: Cardinal;
begin
Result := nil;
AShellWindows := CoShellWindows.Create;
for x := 0 to AShellWindows.Count - 1 do
begin
if ((AShellWindows.Item(x) <> nil)
and (AShellWindows.Item(x).QueryInterface(IWebbrowser2, AWebBrowser2) = S_OK)) then
begin
GetWindowThreadProcessId(AWebbrowser2.HWND, dwProcessID);
if (dwProcessID = nProcessID) then
begin
Result := AWebbrowser2;
Exit;
end;
end;
end;
end;
728x90
반응형