以下代码未关闭Internet Explorer 8中的选项卡。如果我将Wm_close命令发布到Wnd,它会关闭Internet Explorer,但我想关闭当前选项卡而不是整个'ieframe'。 FindWindowEX(Wnd,0,'Frame Tab',nil)是否应该重新设置一个句柄即框架?如果是,为什么不关闭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;
答案 0 :(得分:6)
你错过了1层,标签本身,除此之外,它很好......
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;
答案 1 :(得分:0)
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