最新消息:

NSIS 学习(1)——安装包打开后主界面显示背景图片(使用向导创建)

nsis 永恒心锁 1824浏览 0评论
var txt_LicensePage
Var TopImage
Var BGImage
Var ImageHandle



; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
; 安装程序初始定义常量
!define PRODUCT_NAME "pkpm"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "My company, Inc."
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

SetCompressor lzma
;BrandingText "${EM_BrandingText}"
SetCompress force
XPStyle on

; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"
;!include "MUI2.nsh"
!include "nsWindows.nsh"
!include "WinCore.nsh"
;加载rtf的头文件
!include "LoadRTF.nsh"


; MUI 预定义常量
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

;自定义初始化
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
;自定义页面
Page custom WelcomePage

; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
;许可协议页面
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "aa.txt"
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!insertmacro MUI_PAGE_FINISH


; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "pkpm.exe"
InstallDir "$PROGRAMFILES\pkpm"
ShowInstDetails show
ShowUnInstDetails show


;初始化必须要调用的组件
Function .onInit
 InitPluginsDir
 ;File `/oname=$PLUGINSDIR\license.rtf` `license\license.rtf`
 File `/ONAME=$PLUGINSDIR\bg.bmp` `images\bg.bmp`
 File `/ONAME=$PLUGINSDIR\welcome.bmp` `images\welcome.bmp`
 File `/ONAME=$PLUGINSDIR\a.bmp` `images\a.bmp`
FunctionEnd

;初始化的函数
Function onGUIInit
 ;消除边框
 System::Call `user32::SetWindowLong(i$HWNDPARENT,i${GWL_STYLE},0x9480084C)i.R0`
 ;隐藏一些既有控件
 GetDlgItem $0 $HWNDPARENT 1034
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1035
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1036
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1037
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1038
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1039
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1256
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 1028
 ShowWindow $0 ${SW_HIDE}
FunctionEnd

;处理无边框移动
Function onGUICallback
 ${If} $MSG = ${WM_LBUTTONDOWN}
 SendMessage $HWNDPARENT ${WM_NCLBUTTONDOWN} ${HTCAPTION} $0
 ${EndIf}
FunctionEnd

;自定义的欢迎页面 (如果此页面为空,则会调用原来的默认的页面)
Function WelcomePage
 GetDlgItem $0 $HWNDPARENT 1
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 2
 ShowWindow $0 ${SW_HIDE}
 GetDlgItem $0 $HWNDPARENT 3
 ShowWindow $0 ${SW_HIDE}
 ;初始化的定义一个窗口
 nsDialogs::Create 1044
 Pop $0
 ${If} $0 == error
 Abort
 ${EndIf}
 SetCtlColors $0 "" transparent ;背景设成透明

 ;加入头文件"nsWindows.nsh"
 ${NSW_SetWindowSize} $HWNDPARENT 520 350 ;改变窗体大小
 ${NSW_SetWindowSize} $0 520 350 ;改变Page大小
 /*
 ;读取RTF的文本框
 nsDialogs::CreateControl "RichEdit20A" \
 ${ES_READONLY}|${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} \
 ${WS_EX_STATICEDGE} 5 35 501 216 ''
 Pop $txt_LicensePage
 ${LoadRTF} '$PLUGINSDIR\license.rtf' $txt_LicensePage
 ShowWindow $txt_LicensePage ${SW_HIDE}
 */
 
 ;界面的上方图片
 ${NSD_CreateBitmap} 0 0 520 230 ""
 Pop $TopImage
 ${NSD_SetImage} $TopImage $PLUGINSDIR\welcome.bmp $ImageHandle
 ;ShowWindow $MiddleImage ${SW_HIDE}

 ;贴背景大图
 ${NSD_CreateBitmap} 0 0 100% 100% ""
 Pop $BGImage
 ;${NSD_SetImage} $BGImage $PLUGINSDIR\bg.bmp $ImageHandle
 ${NSD_SetImage} $BGImage $PLUGINSDIR\a.bmp $ImageHandle
 
 #当加上以下的代码后,背景图片以及界面的上方图片显示出来
 GetFunctionAddress $0 onGUICallback
 WndProc::onCallback $BGImage $0 ;处理无边框窗体移动
 nsDialogs::Show
 ${NSD_FreeImage} $ImageHandle
FunctionEnd



Section "MainSection" SEC01
SectionEnd

Section -AdditionalIcons

 SetOutPath $INSTDIR
 CreateDirectory "$SMPROGRAMS\pkpm"
 CreateShortCut "$SMPROGRAMS\pkpm\Uninstall.lnk" "$INSTDIR\uninst.exe"

SectionEnd

Section -Post
 WriteUninstaller "$INSTDIR\uninst.exe"

 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
 WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"

SectionEnd

/******************************
 * 以下是安装程序的卸载部分 *
 ******************************/

Section Uninstall

 Delete "$INSTDIR\uninst.exe"

 Delete "$SMPROGRAMS\pkpm\Uninstall.lnk"

 RMDir "$SMPROGRAMS\pkpm"

 RMDir "$INSTDIR"

 DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
 SetAutoClose true

SectionEnd

#-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#

Function un.onInit
 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
 Abort
FunctionEnd

Function un.onUninstSuccess
 HideWindow
 MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd
永恒心锁,版权所有丨如未注明,均为转载丨本网站采用BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » NSIS 学习(1)——安装包打开后主界面显示背景图片(使用向导创建)

您必须 登录 才能发表评论!