Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close ie8 tabs

This code below is not closing a tab in Internet Explorer 8. If I post wm_close command to Wnd it closes Internet Explorer but I want to close the current tab not the entire 'ieframe'. Is FindWindowEX(Wnd , 0, 'Frame Tab', nil) supposed to retun a handle to ie frame? If yes why is it not closing the current tab in Internet Explorer?

var
   Wnd, WndChild : hwnd;
begin
   Wnd := FindWindow('IEFrame', nil);
   WndChild := FindWindowEX(Wnd, 0, 'Frame Tab', nil);
   postmessage(WndChild, wm_close, 0, 0);
end;
like image 383
Omair Iqbal Avatar asked May 15 '10 05:05

Omair Iqbal


1 Answers

You missed 1 layer, the tab itself, other than that, it was fine..

var
  Wnd, WndChild: THandle;
begin
  Wnd := FindWindow('IEFrame', nil); // Top most IE
  if Wnd > 0 then
  begin
    WndChild := FindWindowEx(Wnd, 0, 'Frame Tab', nil); // Tabs holder
    if WndChild > 0 then
    begin
      WndChild := FindWindowEX(WndChild, 0, 'TabWindowClass', nil); // top most tab
      if WndChild > 0 then
        if PostMessage(WndChild, WM_CLOSE, 0, 0) then
          ShowMessage('Close request succeeded...')
        else
          ShowMessage('Failed!');
    end
    else
      // not tabbed, close IE
        if PostMessage(Wnd, WM_CLOSE, 0, 0) then
          ShowMessage('Close request succeeded...')
        else
          ShowMessage('Failed!');
  end
  else
    ShowMessage('No IE');
end;
like image 188
Francesca Avatar answered Oct 06 '22 00:10

Francesca