最新消息:

安装目录选择与组件选择页面完美合一

nsis 永恒心锁 1475浏览 0评论
!AddPluginDir .
!include "MUI.nsh"
;!include "WinCore.nsh"
!define SHACF_FILESYSTEM 0x00000001
!define EN_CHANGE 0x0300
Name "安装目录选择与组件选择页面完美合一"
OutFile "Example.exe"
InstallDir $TEMP
ShowInstDetails show
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_UI_COMPONENTSPAGE_NODESC myui.exe
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirPageShow
!insertmacro MUI_PAGE_DIRECTORY ;作为第一个页面,但不会显示
!define MUI_PAGE_CUSTOMFUNCTION_SHOW HideBack
!insertmacro MUI_PAGE_LICENSE ${__FILE__} ;在第二个页面隐藏上一步按钮
!define MUI_COMPONENTSPAGE_TEXT_INSTTYPE $(^DirBrowseText) ;浏览对话框文本可用安装类型组合框旁的文本代替
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ComPageShow
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"
Section "主程序" Main
SectionIn RO
AddSize 500
 DetailPrint "$INSTDIR"
SectionEnd
Section /o "测试区段1" Sec01
AddSize 500
DetailPrint "测试区段1"
SectionEnd
Section "测试区段2" Sec02
AddSize 500
DetailPrint "测试区段2"
SectionEnd
Function DirPageShow
FindWindow $1 "#32770" "" $HWNDPARENT
# 这里使用了$R0保存目录选择页面的过程函数地址,后面要避免使用$R0保存其它数据;
# 如不可避免的要使用$R0作临时变量,则应注意保护变量
System::Call User32::GetWindowLong(ir1,i4)i.R0
SendMessage $HWNDPARENT 0x408 1 0
FunctionEnd
Function HideBack
GetDlgItem $0 $HWNDPARENT 3
ShowWindow $0 ${SW_HIDE}
FunctionEnd
Function ComPageShow
FindWindow $1 "#32770" "" $HWNDPARENT
GetFunctionAddress $0 onComPageCallback
 ;WndSubclass::S $R0 $0
 ;Pop $0
 WndProc::onCallback /r=1 $1 $0
GetDlgItem $0 $1 1001
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^BrowseBtn)"
GetDlgItem $0 $1 1007
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^DirText)"
GetDlgItem $0 $1 1020
SendMessage $0 ${WM_SETTEXT} 0 "STR:$(^DirSubText)"
GetDlgItem $0 $1 1019
SendMessage $0 ${WM_SETTEXT} 0 "STR:$INSTDIR"
# 输入路径时自动匹配显示下拉列表显示系统中已存在的文件或文件夹
 System::Call `shlwapi::SHAutoComplete(ir0,i${SHACF_FILESYSTEM})`
FunctionEnd
Function onComPageCallback
 ${If} $2 = ${WM_COMMAND}
 IntOp $5 $3 & 0x0000FFFF
 IntOp $6 $3 >> 16
 IntOp $6 $6 & 0x0000FFFF
 ${If} $6 = ${EN_CHANGE}
 ${AndIf} $5 = 1019
 System::Call User32::GetDlgItemText(ir1,i1019,t.d,i${NSIS_MAX_STRLEN})
 ${EndIf}
 System::Call User32::CallWindowProc(iR0,ir1,ir2,ir3,ir4)
${EndIf}
FunctionEnd
永恒心锁,版权所有丨如未注明,均为转载丨本网站采用BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » 安装目录选择与组件选择页面完美合一

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