카테고리 없음

nsis에서 프로그램 강제 종료후 tray icon refresh 하는 방법

파란하늘999 2025. 5. 16. 15:26

여러가지 방법을 모두 해봤지만 되는 방식은 아래방식 밖에 없었다.

!include WinMessages.nsh
!include "${NSISDIR}\Examples\System\System.nsh"
 
Function un.RefreshSysTray
	; $0: SysTray Window Handle
	FindWindow $0 "Shell_TrayWnd" ""
	FindWindow $0 "TrayNotifyWnd" "" $0
	FindWindow $0 "SysPager" "" $0
	FindWindow $0 "ToolbarWindow32" "" $0
 
	; Create RECT struct
	System::Call "*${stRECT} .r1"
	; Get windows information
	System::Call "User32::GetWindowRect(i, i) i (i r0, r1) .r2"
	; Get left/top/right/bottom coords
	; $2: Left, $3: Top, $4: Right, $5: Bottom
	System::Call "*$1${stRECT} (.r2, .r3, .r4, .r5)"
	System::Free $1
 
	; $2: Width
	IntOp $2 $4 - $2
	; $3: Height
	IntOp $3 $5 - $3
 
	; $4: Small Icon Width
	System::Call 'User32::GetSystemMetrics(i 49) i .r4'
	; $5: Small Icon Height
	System::Call 'User32::GetSystemMetrics(i 50) i .r5'
 
	; $7: y - Start at the bottom
	IntOp $7 $4 / 2
	IntOp $7 $3 - $7
	LoopY:
		; $6: X - Start at the right
		IntOp $6 $5 / 2
		IntOp $6 $2 - $6
		LoopX:
			IntOp $8 $7 << 16
			IntOp $8 $8 + $6
			SendMessage $0 ${WM_MOUSEMOVE} 0 $8
			IntOp $6 $6 - $4
			IntCmp $6 0 EndLoopX EndLoopX LoopX
		EndLoopX:
		IntOp $7 $7 - $5
		IntCmp $7 0 EndLoopY EndLoopY LoopY
	EndLoopY:
FunctionEnd

//사용방법
Call un.RefreshSysTray

 

참고

https://nsis.sourceforge.io/Refresh_SysTray

 

Refresh SysTray - NSIS

How to Use This function is useful after killing a process that has a system tray icon. This will clear out the icon as though the cursor had been moved over it. Call RefreshSysTray The Function !include WinMessages.nsh !include "${NSISDIR}\Examples\System

nsis.sourceforge.io

 

반응형