Skip to content
⌘ NSIS Forum Archive

Get installer to open in center of screen

4 posts

r2du-soft#

Get installer to open in center of screen

hi
i create a custom page and change width and height.
now when i open installer, i see installer in not run in center screen...
for open installer in center screen i write this codes:

${nsResize_Window} 170u 76u

System::Call 'user32::GetSystemMetrics(i 0) i .r0'
System::Call 'user32::GetSystemMetrics(i 1) i .r1'
intop $0 $0 / 2
intop $1 $1 / 2

System::Call "User32::SetWindowPos(i, i, i, i, i, i, i) i ($HWNDPARENT, 0, $0, $1, 0, 0, 0x201)"
but my installer after running no run in center screen...
when run this code the installer position 0 0 (top left) run in center screen.

i want open that in center screen?how must do it?


and another question:
i how can give installer width and height?

regards
Anders#
You at least need to subtract half of the width and height of the installer for it to be center. Your code also assumes that there is only one monitor!
r2du-soft#edited
Thanks
How can i calculate the width and height the program i write (my installer after open)

Anders#
Function CenterNSISMainWindowOnNearestMonitor ; NSIS 2.51+
System::Store S
!if "${NSIS_PACKEDVERSION}" <= 0x0300003F
System::Call '*(i,i,i,i,i,i,i,i,i,i)p.r5'
System::Call "USER32::GetWindowRect(p$HWNDPARENT,ir5)"
!else
System::Call "USER32::GetWindowRect(p$HWNDPARENT,@r5)"
!endif
System::Call '*$5(i.r6,i.r7,i.r8,i.r9)'
IntOp $6 $8 - $6
IntOp $7 $9 - $7
System::Call 'USER32::SystemParametersInfo(i0x30,i0,pr5,i0)'
System::Call '*$5(i.r1,i.r2,i.r3,i.r4)'
System::Call 'USER32::MonitorFromWindow(p$HWNDPARENT,i2)i.r0'
IntCmpU $0 0 calcAndMove
System::Call '*$5(i40)'
System::Call 'USER32::GetMonitorInfo(pr0,pr5)i.r0'
IntCmpU $0 0 calcAndMove
System::Call '*$5(i,i,i,i,i,i.r1,i.r2,i.r3,i.r4)'
calcAndMove:
IntOp $1 $3 - $1
IntOp $2 $4 - $2
IntOp $6 $6 / 2
IntOp $7 $7 / 2
IntOp $1 $1 / 2
IntOp $2 $2 / 2
IntOp $1 $1 - $6
IntOp $2 $2 - $7
System::Call 'USER32::SetWindowPos(p$HWNDPARENT,i,ir1,ir2,i,i,i0x11)'
!if "${NSIS_PACKEDVERSION}" <= 0x0300003F
System::Free $5
!endif
System::Store L
FunctionEnd
...
System::Call 'USER32::SetWindowPos(p$HWNDPARENT,i,i,i,i620,i420,i0x12)' ; Set the size to something stupid
call CenterNSISMainWindowOnNearestMonitor