[英]How to set position of MUI_PAGE_INSTFILES in NSIS?
我想在安装时设置MUI_PAGE_INSTFILES安装页面的默认位置,该位置现在位于屏幕的左上角。 我需要将页面位置更改为屏幕的中心。 我该怎么办? 无法在网上找到与此有关的任何帮助,将不胜感激。
尝试这个:
(免责声明:代码取自http://nsis.sourceforge.net/Moving_install_window_to_a_corner_of_the_screen,并使用NSIS的Visual&Installer编辑器更改为居中代码: http : //www.visual-installer.com )
; The name of the installer
Name "Example1"
; The file to write
OutFile "example1.exe"
; The default installation directory
InstallDir $DESKTOP\Example1
; Request application privileges for Windows Vista
RequestExecutionLevel user
;--------------------------------
; Pages
Page directory
Page instfiles
;--------------------------------
; The stuff to install
Section "" ;No components page, name is not important
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File example1.nsi
SectionEnd ; end the section
!include "${NSISDIR}\Examples\System\System.nsh"
# before 2.07 !include "${NSISDIR}\Contrib\System\System.nsh"
Function .onGUIInit
Call repositionWindow
FunctionEnd
!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 / 2
; Left side of screen + 10
;IntOp $0 $4 / 2
; Bottom of screen - window - 5
IntOp $1 $7 - $3
IntOp $1 $1 / 2
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
对我来说还不太清楚,是要在用户启动安装程序时还是在他们进入InstFiles页面(通常不是第一页)时将窗口居中。
无论哪种方式,您都可以调用此函数以使窗口居中:
!include LogicLib.nsh
!ifndef SPI_GETWORKAREA
!define SPI_GETWORKAREA 0x0030
!endif
Function CenterWindowOnCurrentMonitor
System::Store S
System::Call '*(i,i,i,i,i,i,i,i,i,i)i.r9' ; Allocate a RECT/MONITORINFO struct
System::Call 'USER32::GetWindowRect(i$hwndParent, ir9)'
System::Call '*$9(i.r1,i.r2,i.r3,i.r4)' ; Extract data from RECT
IntOp $3 $3 - $1 ; Window width
IntOp $4 $4 - $2 ; Window height
System::Call "User32::SystemParametersInfo(i${SPI_GETWORKAREA}, i0, ir9, i0)"
System::Call '*$9(i.r5,i.r6,i.r7,i.r8)' ; Extract data from RECT
System::Call 'USER32::MonitorFromWindow(i$hwndParent, i1)i.r0'
${If} $0 <> 0
System::Call '*$9(i40)' ; Set MONITORINFO.cbSize
System::Call 'USER32::GetMonitorInfo(ir0, ir9)i.r0'
${IfThen} $0 <> 0 ${|} System::Call "*$9(i,i,i,i,i,i.r5,i.r6,i.r7,i.r8)" ${|} ; Extract data from MONITORINFO
${EndIf}
System::Free $9
IntOp $7 $7 - $5 ; Workarea width
IntOp $8 $8 - $6 ; Workarea height
IntOp $7 $7 / 2
IntOp $8 $8 / 2
IntOp $1 $5 + $7 ; Left = Workarea left + (Workarea width / 2)
IntOp $2 $6 + $8 ; Top = Workarea top + (Workarea height / 2)
IntOp $3 $3 / 2
IntOp $4 $4 / 2
IntOp $1 $1 - $3 ; Left -= Window width / 2
IntOp $2 $2 - $4 ; Top -= Window height / 2
System::Call 'USER32::SetWindowPos(i$hwndParent, i, ir1, ir2, i, i, i 0x211)' ; NoSize+NoZOrder+NoActivate
System::Store L
FunctionEnd
要将其放在InstFiles页面上:
Section
Call CenterWindowOnCurrentMonitor
SectionEnd
要在安装程序启动时将其居中:
; Optional: !include MUI2.nsh
!ifdef MUI_INCLUDED
!define MUI_CUSTOMFUNCTION_GUIINIT CenterWindowOnCurrentMonitor
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
!else
Function .onGuiInit
Call CenterWindowOnCurrentMonitor
FunctionEnd
Page Components
Page InstFiles
!endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.