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;
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;
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 Window structure is shown in screenshot below
alt text http://img171.imageshack.us/img171/6702/captureids.png
精彩评论