简体   繁体   English

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

[英]How to set position of MUI_PAGE_INSTFILES in NSIS?

I want to set the default position of the MUI_PAGE_INSTFILES installation page while installation, which is now at upper left corner of the screen. 我想在安装时设置MUI_PAGE_INSTFILES安装页面的默认位置,该位置现在位于屏幕的左上角。 I need to change the page position to the center of the screen. 我需要将页面位置更改为屏幕的中心。 How should I do it? 我该怎么办? Unable to find anything on web regarding this any help will be appreciated. 无法在网上找到与此有关的任何帮助,将不胜感激。

Try this: 尝试这个:

(Disclaimer: Code taken from http://nsis.sourceforge.net/Moving_install_window_to_a_corner_of_the_screen and changed to center using Visual & Installer editor for NSIS: http://www.visual-installer.com ) (免责声明:代码取自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

It is a little unclear to me if you want to center the window when the user starts the installer or when they get to the InstFiles page (which is normally not the first page). 对我来说还不太清楚,是要在用户启动安装程序时还是在他们进入InstFiles页面(通常不是第一页)时将窗口居中。

Either way, you can call this function to center the window: 无论哪种方式,您都可以调用此函数以使窗口居中:

!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

To center it on the InstFiles page: 要将其放在InstFiles页面上:

Section
Call CenterWindowOnCurrentMonitor
SectionEnd

To center it when the installer starts: 要在安装程序启动时将其居中:

; 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.

相关问题 NSIS如何在安装过程中修改MUI_PAGE_INSTFILES? - NSIS How to modify MUI_PAGE_INSTFILES during installtion? 如何调整NSIS MUI_PAGE_INSTFILES中的节的列表框的大小 - How to resize the list box of sections in NSIS MUI_PAGE_INSTFILES 如何在NSIS中的MUI_PAGE_INSTFILES上显示自定义文本 - How to display a custom text on MUI_PAGE_INSTFILES in NSIS NSIS:当MUI_PAGE_INSTFILES完成时,如何自动按“下一步”按钮 - NSIS: How to press “Next” button automatically when MUI_PAGE_INSTFILES is complete 如果存在两个MUI_PAGE_INSTFILES,如何更改MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT - How to change MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT if exists two MUI_PAGE_INSTFILES 添加到MUI_PAGE_INSTFILES的链接不显示 - Added link to MUI_PAGE_INSTFILES does not show 为什么当我添加自定义 nsDialog 页面时,我的 NSIS 脚本似乎跳过了 MUI_PAGE_INSTFILES 等安装页面? - Why does my NSIS script appear to be skipping over installation pages like MUI_PAGE_INSTFILES when I add custom nsDialog pages? 如何在MUI instfiles页面中更改进度栏长度并安排按钮位置? - How to change Progress bar length in MUI instfiles page and arrange button position? 模拟下一次单击 INSTFILES 页面以将用户带到自定义页面 (NSIS) - Simulate next click on INSTFILES page to take user to a Custom Page (NSIS) 将 MUI2 用于 NSIS 时,如何修改 MUI_WELCOME_PAGE 中的文本? - How can I modify the text in the MUI_WELCOME_PAGE when using MUI2 for NSIS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM