代码之家  ›  专栏  ›  技术社区  ›  Omair Iqbal

如何关闭ie8标签

  •  5
  • Omair Iqbal  · 技术社区  · 16 年前

    下面的代码没有关闭Internet Explorer 8中的选项卡。如果我将wm\u close命令发布到Wnd,它将关闭Internet Explorer,但我要关闭当前选项卡而不是整个“ieframe”。FindWindowEX(Wnd,0,'Frame Tab',nil)是否应该将句柄重新运行到ie Frame?如果是,为什么不关闭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;
    
    2 回复  |  直到 16 年前
        1
  •  6
  •   Francesca    16 年前

    你错过了一层,标签本身,除此之外,它很好。。

    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;
    
        2
  •  0
  •   Im0rtality    16 年前
    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;`
    

    IE8窗口结构如下图所示

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