DelphiFAQ Home Search:

Closing Internet Explorer (IE) from Delphi

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

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!
Content-type: text/html

Comments:

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: