I'm using this Delphi 7 code to detect if Internet Explorer is running:
function IERunning: Boolean;
begin
Result := FindWindow('IEFrame', NIL) > 0;
end;
This works on 99% of the systems with IE 8,9 and 10.
But there are some systems (unfortunately none of mine, but I have two beta testers which have such systems, both Win7 x64 SP1) where FindWindow() returns 0 for IEFrame, even if IE is in memory.
So I've coded an alternate method to find the window:
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;
The alternate method works on 100% of all systems.
My question - why is FindWindow() not reliable on some of the systems?
EnumWindows()
instead. – TendFindWindow
by callingEnumWindows
. Anyway, if performance is the issue, then that's a different matter. But since it's a popup window it would seem unlikely to be a problem. Anyway, this issue may be interesting to others. How can we reproduce it? – TengdinEnumWindows
does not return until all callbacks have been called. – TengdinEnumWindows
. – TengdinGetNextWindow
variant is quicker. It is around 4 times quicker. It's clear that performance is not your issue since you can readily afford 0.07 milliseconds whilst showing a popup menu. – Tengdin