Refresh SysTray: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page with '== 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. <highlig...')
 
(Fixed LParam for WM_MOUSEMOVE)
 
Line 45: Line 45:
IntOp $6 $2 - $6
IntOp $6 $2 - $6
LoopX:
LoopX:
SendMessage $0 ${WM_MOUSEMOVE} 0 "$6 | $7"
IntOp $8 $7 << 16
IntOp $8 $8 + $6
SendMessage $0 ${WM_MOUSEMOVE} 0 $8
IntOp $6 $6 - $4
IntOp $6 $6 - $4
IntCmp $6 0 EndLoopX EndLoopX LoopX
IntCmp $6 0 EndLoopX EndLoopX LoopX

Latest revision as of 16:59, 8 December 2022

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\System.nsh"
 
Function 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