1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
procedure NettoieBarreDesTaches;
var
hProc : Cardinal; //handle de Explorer.exe
hTray : Cardinal; //hWnd du tray
pid : Cardinal; //identifiant de Explorer.exe
ptrVM : Pointer; //pointeur vers la zone mémoire pour TBBUTTON
ret : Cardinal; //valeur de retour
tbut: _TBBUTTON; //les infos sur le bouton
x : Cardinal; //compteur
nIcons : Cardinal; //nombre d//icones dans le tray
Icons: array of Tray; //tableau temporaire des icones dans le tray
Icon:TNotifyIconData;
const
PROCESS_VM = PROCESS_QUERY_INFORMATION Or PROCESS_VM_OPERATION
Or PROCESS_VM_READ Or PROCESS_VM_WRITE; //Or PROCESS_DUP_HANDLE
//renvoie le Hwnd du tray
function GethWndTray() : Cardinal;
var
hwnd,hwnd2 : Cardinal; //handle
begin
//on descend dans la hiérarchie parent-enfant
hwnd := FindWindow('Shell_TrayWnd', 0);
hwnd := FindWindowEx(hwnd, 0, 'TrayNotifyWnd', 0);
hwnd2 := FindWindowEx(hwnd, 0, 'SysPager', 0); //uniquement XP
//jusqu//à obtenir le handle de la barre d//outils faisant de tray
hwnd2 := FindWindowEx(hwnd2, 0, 'ToolbarWindow32', 0); // ME, 2000, XP...
If (hwnd2 = 0) Then
begin
hwnd2 := FindWindowEx(hwnd, 0, 'SysPager', 0);
hwnd2 := FindWindowEx(hwnd2, 0, 'User Promoted Notification Area', 0); // Seven
end;
if (hwnd2) = 0 then
Result := hwnd // 95,98
Else
Result := hwnd2; // ME, 2000, XP...
end;
begin
hTray := GethWndTray(); //on demande le hWnd du tray
If hTray = 0 Then //si erreur
Exit;
GetWindowThreadProcessId(hTray, @pid); //on demande l'identifiant de Explorer.exe
hProc := OpenProcess(PROCESS_VM, False, pid) ; //on demande un handle de Explorer.exe
If hProc = -1 Then //si erreur
Exit;
ptrVM := VirtualAllocEx(hProc, nil, sizeof(tbut), MEM_COMMIT, PAGE_READWRITE);//on alloue de la mémoire pour TBBUTTON
If ptrVM = nil Then //si erreur
Exit;
nIcons := SendMessage(hTray, TB_BUTTONCOUNT, 0, 0); //on demande le nombre de boutons dans le tray
SetLength(Icons,nIcons);//on redimensionne le tableau au nombre d'icones
For x := nIcons - 1 downto 0 do //on parcours la liste des icones
begin
SendMessage(hTray, TB_GETBUTTON, wparam(x), lparam(ptrVM));//on demande les infos sur le bouton
ReadProcessMemory(hProc, ptrVM, @tbut, sizeof(tbut), ret);//on lit les infos sur le bouton
ReadProcessMemory(hProc, Pointer(tbut.dwData), @Icons[x].hwnd, 36, ret); //on lit les données de l'icone
//on envoie la commande de suppression de l'icone qui ne fonctionne
//que si cette icone n'est plus attachée a un programme
Icon.cbSize := 0; //SizeOf
Icon.Wnd := Icons[x].hwnd;//Handle;
Icon.uID := 1;
Shell_NotifyIcon(NIM_DELETE,@Icon);
end;
end; |
Partager