Moving install window to a corner of the screen

From NSIS Wiki
Jump to navigationJump to search
Author: Wasteland (talk, contrib)


Description

Here is a code snippet that will allow you to position the installer window in the lower left or lower right corner of the screen, taking into account the start menu, screen size, etc. The code as written will position it in the lower left (for the lower right, uncomment the appropriate lines below)

The Script

!include "${NSISDIR}\Examples\System\System.nsh"
# before 2.07 !include "${NSISDIR}\Contrib\System\System.nsh"
 
Function repositionWindow
	;Save existing register values to the stack
	Push $0
	Push $1
	Push $2
	Push $3
	Push $4
	Push $5
	Push $6
	Push $7
 
;	!define SPI_GETWORKAREA             0x0030
;	!define SWP_NOSIZE                  0x0001
;	!define SWP_NOOWNERZORDER	    0x0200
 
	; Reposition window in the lower left
	; Create RECT struct
	System::Call "*${stRECT} .r1"
	; Find Window info for the window we're displaying
	System::Call "User32::GetWindowRect(i, i) i ($HWNDPARENT, r1) .r2"
	; Get left/top/right/bottom
	System::Call "*$1${stRECT} (.r2, .r3, .r4, .r5)"
 
	; Calculate width/height of our window
	IntOp $2 $4 - $2 ; $2 now contains the width
	IntOp $3 $5 - $3 ; $3 now contains the height
 
	; Determine the screen work area
	System::Call "User32::SystemParametersInfo(i, i, i, i) i (${SPI_GETWORKAREA}, 0, r1, 0) .r4" 
	; Get left/top/right/bottom
	System::Call "*$1${stRECT} (.r4, .r5, .r6, .r7)"
 
	System::Free $1
 
	; Right side of screen - window - 10
	;IntOp $0 $6 - $2
	;IntOp $0 $0 - 10
	; Left side of screen + 10
	IntOp $0 $4 + 10
 
	; Bottom of screen - window - 5
	IntOp $1 $7 - $3
	IntOp $1 $1 - 5
 
	System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) b ($HWNDPARENT, 0, $0, $1, 0, 0, ${SWP_NOOWNERZORDER}|${SWP_NOSIZE})"
 
	;Restore register values from the stack
	Pop $7
	Pop $6
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
FunctionEnd