簡體   English   中英

如何在NSIS中設置MUI_PAGE_INSTFILES的位置?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM