この Delphi 7 コードを使用して、Internet Explorer が実行されているかどうかを検出しています。
function IERunning: Boolean;
begin
Result := FindWindow('IEFrame', NIL) > 0;
end;
これは、IE 8、9、および 10 を搭載したシステムの 99% で機能します。
しかし、いくつかのシステムがあります (残念ながら私のものではありませんが、IE がメモリ内にある場合でも、FindWindow() が IEFrame に対して 0 を返すシステムが 2 つあります)。
そこで、ウィンドウを見つける別の方法をコーディングしました。
function IERunningEx: Boolean;
var WinHandle : HWND;
Name: array[0..255] of Char;
begin
Result := False; // assume no IE window is present
WinHandle := GetTopWindow(GetDesktopWindow);
while WinHandle <> 0 do // go thru the window list
begin
GetClassName(WinHandle, @Name[0], 255);
if (CompareText(string(Name), 'IEFrame') = 0) then
begin // IEFrame found
Result := True;
Exit;
end;
WinHandle := GetNextWindow(WinHandle, GW_HWNDNEXT);
end;
end;
別の方法は、すべてのシステムの 100% で機能します。
私の質問 - 一部のシステムで FindWindow() が信頼できないのはなぜですか?