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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With