2010-05-15 14 views
5

Questo codice qui sotto non è la chiusura di una scheda in Internet Explorer 8. Se ho posto di comando WM_CLOSE a WND si chiude Internet Explorer, ma voglio chiudere la scheda corrente non l'intero 'ieframe'. FindWindowEX (Wnd, 0, 'Frame Tab', nil) dovrebbe ricomporre un handle per ie frame? Se sì, perché non chiude la scheda corrente in Internet Explorer?come chiudere le schede IE8

var 
    Wnd, WndChild : hwnd; 
begin 
    Wnd := FindWindow('IEFrame', nil); 
    WndChild := FindWindowEX(Wnd, 0, 'Frame Tab', nil); 
    postmessage(WndChild, wm_close, 0, 0); 
end; 
+0

Non sono sicuro che questo sia possibile. –

+0

@George: Beh, in teoria * * dovrebbe essere possibile, se IE8 sta creando finestre effettivi per le schede, che sembra probabile. Il trucco sta nel trovare la maniglia della finestra giusta, che può essere davvero molto difficile - o addirittura impossibile, come hai detto tu. :-) –

risposta

6

Vi siete persi 1 strato, la scheda stessa, a parte questo, è andato tutto bene ..

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; 
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;` 
struttura

IE8 finestra è mostrato nella schermata sotto

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

+0

grazie per la risposta Ho poche confusioni: 1.Why ha fatto si utilizza DWORD invece di hwnd. 2. è CloseHandle (HTAB) equvalent a HTAB: = nil 3. è CloseHandle necessario, Wont le maniglie sono automaticamente chiusi una volta il mio programma si chiude? –

+1

Esempio di codice molto cattivo. 1) Dovresti controllare il risultato di FindWindow [Ex]. 2) NON chiudi le maniglie restituite da FindWindow [Ex]. – gabr

+0

In realtà, questo era per mostrare un'idea di come dovrebbe essere fatto, lasciando un po 'di spazio per pensare (errore di cattura). Dove hai trovato di non chiudere le maniglie (http://msdn.microsoft.com/en-us/library/ms633500(VS.85).aspx dice nulla di esso)? E sì, l'handle di chiusura della finestra ricevuto WM_CLOSE genera effettivamente un'eccezione (ecco perché non l'ho chiusa). – Im0rtality

Problemi correlati