强制结束进程后立即清理托盘图标

优质
小牛编辑
130浏览
2023-12-01
强制结束有托盘图标的进程后,需要把鼠标移到托盘图标时,图标才会消失。想图标立即消失,用以下代码即可:

FindWindow $0 "Shell_TrayWnd"
FindWindow $0 "TrayNotifyWnd" "" $0
FindWindow $1 "ToolBarWindow32" "" $0 ;Win2K
StrCmp $1 0 0 +3
FindWindow $0 "SysPager" "" $0
FindWindow $1 "ToolBarWindow32" "" $0 ;WinXP/2003
SendMessage $1 ${WM_MOUSEMOVE} 0 0


缺点:当图标是不活动图标被隐藏时,就失效了。

下面的方法比较好,用 Shell_NotifyIcon 但需要用System 插件:

!include "UsefulLib.nsh"
!define NIM_DELETE 2

!insertmacro DEFINE_FUNC_LITE DelTrayIcon
!macro INSERT_FUNC_LITE_DelTrayIcon HWND uID
    Push $1
    System::Call "*(i 88, i ${HWND}, i ${uID}, i, i, i, &t64) i .r1"
    System::Call "Shell32::Shell_NotifyIcon(i, i) i (${NIM_DELETE}, r1)"
    System::Free $1
    Pop $1
!macroend

Section
    FindWindow $0 "Afx:400000:0" "Lingoes 灵格斯"
    ;${DelTrayIcon} $0 128  ;发送{WM_CLOSE}可以结束进程就不需要了
    SendMessage $0 ${WM_CLOSE} 0 0

    FindWindow $0 "Eset Client Frame" "ESET NOD32 Antivirus"
    ${DelTrayIcon} $0 0     ;发送{WM_CLOSE}不能结束进程就要先删掉图标
    KillProcDLL::KillProc "egui.exe"     ;强制结束进程
SectionEnd