How to close ie8 tabs

This code below does not close the tab in Internet Explorer 8. If I send the 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 reconfigure the handle to the frame? If so, why doesn't it close 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;
+5
source share
2 answers

You missed 1 layer, the tab itself, except for that, everything 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;
+6
source
var
  hie,
  hftab,
  htab : DWORD;
begin
  hie := FindWindow('IEFrame', nil);
  hftab := FindWindowEx(hie, 0, 'Frame Tab', nil);
  htab := FindWindowEX(hftab, 0, 'TabWindowClass', nil);
  PostMessage(htab, WM_CLOSE, 0, 0);
  CloseHandle(hie);
end;`

The structure of the IE8 window is shown in the screenshot below.

alt text http://img171.imageshack.us/img171/6702/captureids.png

0

All Articles