DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

Closing Internet Explorer (IE) from Delphi

Question:

My application has to close the IE. How can an application close the Internet Explorer or an Explorer window?


Answer:

The key is to post to the *right* window. Use the code below and it will close all instances of IE.

program Sample;
 
 function CloseIEs(Wnd : HWnd; Form : TForm1) : Boolean; export; stdcall;
 var
   sCap : array [0..255] of char;
 begin
   GetWindowText (Wnd, sCap, sizeof(sCap));
   if pos ('Microsoft Internet Explorer', sCap) > 0 then
   begin
     PostMessage (Wnd, WM_CLOSE, 0, 0);
   end
   else
   begin
     // check by class name!
    GetClassName (Wnd, sCap, sizeof(sCap));
     if sCap = 'IEFrame' then
       PostMessage (Wnd, WM_CLOSE, 0, 0);
   end;
 
   CloseIEs := true; { next window, please }
 end;
 
 begin
   // close all hidden instances
  EnumWindows(@CloseIEs, 0);
 end.
You don't like the formatting? Check out SourceCoder then!
Generated 20:01:48 on Nov 21, 2017