首页 > 解决方案 > NSIS 安装程序按钮皮肤在自定义页面中不起作用

问题描述

我正在为我的安装程序创建一个自定义页面,我隐藏了默认按钮(返回、下一步和取消),并且只显示了一个自定义按钮(安装)。问题是,我无法使用skinned controls plugin设置自定义按钮的背景颜色。如果我显示默认按钮,我会看到通过位图应用于它们的背景颜色。这意味着蒙皮将应用于默认按钮,而不是自定义按钮。关于我会错过什么的任何指示?

这是代码:

!include "logiclib.nsh"
;--------------------------------
;Include Modern UI
  !include "MUI2.nsh"
  !include "InstallOptions.nsh"

;--------------------------------
;General

  ;Name and file
  Name "Custom App"
  OutFile "custom_installer.exe"

  ;Default installation folder
  InstallDir "$LOCALAPPDATA\Custom Test"

  RequestExecutionLevel user

  ;Remove default branding text of Nullsoft
  ;BrandingText " "

var title
var description
var button
Var ImageCtrl
Var BmpHandle

;--------------------------------
;Interface Settings
  !define MUI_ABORTWARNING
  !define Black "814EFA"
  !define LightRed "FFFFFF"
  !define MUI_CUSTOMFUNCTION_GUIINIT myGUIInit


XPStyle off
;--------------------------------
;Functions
Function .onInit
    InitPluginsDir
  ; Extract bitmaps for buttons
  File "/oname=$PLUGINSDIR\button.bmp" "${NSISDIR}\Contrib\SkinnedControls\skins\button_background.bmp"
FunctionEnd

Function myGUIInit
  DetailPrint "myGUIInit"
  ; start the plugin
  ; the /disabledtextcolor, /selectedtextcolor and /textcolor parameters are optionnal
  SkinnedControls::skinit /NOUNLOAD \
            /disabledtextcolor=808080 \
            /selectedtextcolor=000080 \
            /textcolor=000000 \
            "/button=$PLUGINSDIR\button.bmp"
FunctionEnd

Function Start
  nsDialogs::Create 1044
  Pop $0
    SetCtlColors $0 222425 FBFBFB
  SetCtlColors $HWNDPARENT 222425 FBFBFB
  
  ${NSD_CreateLabel} 0 150 100% 24u "Welcome to Custom App"
  pop $title
  SetCtlColors $title 0x000000 0xFBFBFB
  ${NSD_AddStyle} $title ${SS_CENTER}
  CreateFont $0 "Arial" 24
  SendMessage $title ${WM_SETFONT} $0 1

  ${NSD_CreateLabel} 0 190 100% 28u "By clicking install you agree to the terms of the End $\r$\n User License Agreement"
  pop $description
  SetCtlColors $description 0x000000 0xFBFBFB
  ${NSD_AddStyle} $description ${SS_CENTER}
  CreateFont $0 "Arial" 14
  SendMessage $description ${WM_SETFONT} $0 1

  ${NSD_CreateButton} 25 250 90% 15u INSTALL
  pop $button
  ;SetCtlColors $button 0x000000 0x0FFFFF
  ${NSD_AddStyle} $button ${SS_CENTER}

  GetDlgItem $0 $HWNDPARENT 3 ; Back Button
  GetDlgItem $1 $HWNDPARENT 1 ; Next/Close Button
  GetDlgItem $2 $HWNDPARENT 2 ; Cancel Button
  
  ;ShowWindow $0 ${SW_HIDE}
  ;ShowWindow $1 ${SW_HIDE}
  ;ShowWindow $2 ${SW_HIDE}


  GetDlgItem $0 $HWNDPARENT 1035
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1036
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1045
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1028
  ShowWindow $0 ${SW_HIDE}
  GetDlgItem $0 $HWNDPARENT 1256
  ShowWindow $0 ${SW_HIDE}

    nsDialogs::Show

  ${NSD_FreeBitmap} $BmpHandle
FunctionEnd

;--------------------------------
;Pages

  Page custom Start
  !insertmacro MUI_PAGE_COMPONENTS

;--------------------------------
;Languages
 
  !insertmacro MUI_LANGUAGE "English"

;--------------------------------
;Installer Sections

Section "Dummy Section" SecDummy

  SetOutPath "$INSTDIR"

SectionEnd

这是当前的 UI(清楚地显示了默认按钮的皮肤): 在此处输入图像描述

标签: nsis

解决方案


这是您使用的 Skinned Control 插件中的一个错误,您需要修复它。

某些旧版本有可能修复了此问题,但由于未知原因,您的脚本不适用于旧版本,而且我不记得确切的详细信息/版本。

我是该插件的 Wiki 页面中提到的Graphical Installer ( http://www.graphical-installer.com/ ) 的开发人员,前段时间我在 SkinnedControls 插件上工作并修复了一些问题。但这几乎是 10 年前的事了。

据我所知,这个插件存在一些问题,因为我们想在图形安装程序(允许对整个安装程序进行皮肤的工具)中使用它。但是我们无法解决所有问题,所以我们结束了编写按钮工作正常的自定义插件: 按钮在 GI 中工作

有时间我会看看这个插件,同时你可以打开项目(我猜是Visual Studio 2008 C++项目)并调试它。该插件应该枚举所有控件,检测所有按钮(这可能是一个问题)并为它们蒙皮。


推荐阅读