刷新系统托盘(清除死掉的图标)修正版
2009-08-06 18:50:06| 分类: | 标签: |字号大中小
type TOSVersion = (osUnknown, os95, os98, osME, osNT3, osNT4, os2K, osXP, os2K3); ...... function GetOS: TOSVersion; var OS: TOSVersionInfo; begin ZeroMemory(@OS,SizeOf(OS)); OS.dwOSVersionInfoSize := SizeOf(OS); GetVersionEx(OS); Result := osUnknown; if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then begin case OS.dwMajorVersion of 3: Result := osNT3; 4: Result := osNT4; 5: begin case OS.dwMinorVersion of 0: Result:= os2K; 1: Result:= osXP; 2: Result:= os2K3; end; end; end; end else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 0) then Result := os95 else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then Result := os98 else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) then Result := osME end; function GetSysTrayWnd(): HWND; //返回系统托盘的句柄,适合于Windows各版本 var OS: TOSVersion; begin OS := GetOS; Result := FindWindow('Shell_TrayWnd', nil); Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil); if(OS in [osXP, os2K3])then Result := FindWindowEx(Result, 0, 'SysPager', nil); if(OS in [os2K, osXP, os2K3])then Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil); end; procedure RefreshTrayIcon(); //刷新系统托盘图标 var hwndTrayToolBar : HWND; rTrayToolBar : tRect; x , y : Word; begin hwndTrayToolBar := GetSysTrayWnd; Windows.GetClientRect(hwndTrayToolBar, rTrayToolBar); for x:=1 to rTrayToolBar.right-1 do begin for y:=1 to rTrayToolBar.bottom-1 do begin SendMessage(hwndTrayToolBar , WM_MOUSEMOVE, 0, MAKELPARAM(x,y)); end; end; end; =================================== 调用RefreshTrayIcon()就OK [笔记]隐藏指定程序的托盘图标(Delphi版)
突然想到又添加一个把“疯狂刷新”的托盘图标都隐藏的功能。于是百度了半天才弄到一个还可以的实现功能。(添加uses CommCtrl;)
procedure HideAllTrace;
var TBHWND: HWND; i, count: Integer; PID, PRC: THandle; Buff: PChar; Info: _TBBUTTON; R: Cardinal; S: array[0..1024] of char;begin TBHWND := GetSysTrayWnd; if TBHWND = 0 then exit; GetWindowThreadProcessId(TBHWND, @PID); PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID); Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE); count := SendMessage(TBHWND, TB_BUTTONCOUNT, 0, 0); //托盘中button的个数,不一定是图标的个数,有些button是隐藏的。 for i := 0 to count - 1 do begin FillChar(Info, SizeOf(Info), 0); WriteProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); //消息使用的内存空间必须在Shell之内,所以利用ReadProcessMemoery和WriteProcessMemory。 SendMessage(TBHWND, TB_GETBUTTON, i, Integer(Buff)); ReadProcessMemory(PRC, Buff, @Info, SizeOf(Info), R); SendMessage(TBHWND, TB_GETBUTTONTEXT, Info.idCommand, Integer(Integer(@Buff[0]) + SizeOf(Info))); ReadProcessMemory(PRC, Pointer(Integer(@Buff[0]) + SizeOf(Info)), @S[0], SizeOf(S), R); if pos('疯狂刷新', StrPas(S)) > 0 then //如果button的TEXT中包含'疯狂刷新' SendMessage(TBHWND, TB_DELETEBUTTON, i, 0); //删除 end; VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE); CloseHandle(PRC);end;但终因这个功能太猥亵,有点你木马或恶意软件而没有添加到辅助工具里。