更改NSIS安装程序中的加载栏颜色

时间:2012-09-27 03:11:36

标签: winapi installer nsis

如何在NSIS安装程序的“安装文件”页面中更改“加载栏”的颜色?

以下尝试将消息PBM_SETBARCOLOR发送到加载栏窗口,但加载栏的颜色永远不会改变?

!include MUI2.nsh
!include WinMessages.nsh

InstallDir  "abc"
Name        "def"        
OutFile     "def.exe"

!define MUI_PAGE_CUSTOMFUNCTION_SHOW InstFilesPageShow
!insertmacro MUI_PAGE_INSTFILES

!macro RefreshWindow HWND IDC
    GetDlgItem $R0 ${HWND} ${IDC}
    ShowWindow $R0 ${SW_HIDE}
    ShowWindow $R0 ${SW_SHOW}
!macroend

Function InstFilesPageShow

    SendMessage 1004 ${PBM_SETBARCOLOR} 0 "COLORREF(0,200,200)" #0xFF0000
    System::Call `user32::SendMessage(i R1, i ${PBM_SETBARCOLOR}, i 0, i COLORREF(0,0,0))`  #System::Call `user32::SetWindowPos(i R8, i ${HWND_TOP}, i 0, i 0, i ${w}, i ${h}, i ${SWP_NOMOVE})`
    #!insertmacro RefreshWindow $HWND 1004
    #!insertmacro RefreshWindow $mui.InstallPage 1004
    !insertmacro RefreshWindow $HWNDPARENT 1004

FunctionEnd

Section "Dummy" 
    DetailPrint "Test"
SectionEnd

2 个答案:

答案 0 :(得分:1)

XPStyle on
Page instfiles "" instfilesShow

!include WinMessages.nsh

Function instfilesShow
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1004
System::Call UxTheme::SetWindowTheme(ir0,w"",w"")
SendMessage $0 ${PBM_SETBARCOLOR} 0 0x11aaee
FunctionEnd

答案 1 :(得分:0)

我担心您无法执行此操作:PBM_SETBARCOLOR documentation,MSDN状态

  

启用视觉样式时,此消息无效。

顺便说一下,在你的RefreshWindow宏中,你错误地从其ID获取控制句柄。 NSIS文档告诉

  

如果要在内部对话框中获取控件的句柄,请首先使用FindWindow user_var(output) "#32770" "" $HWNDPARENT来获取内部对话框的句柄。

因此你可以这样写:

FindWindow $R1 "#32770" "" $HWNDPARENT ;$R1 = handle of the inner dialog
GetDlgItem $R0 $R1 ${IDC} ;get the handle of control from its ID
ShowWindow $R0 ${SW_HIDE}
ShowWindow $R0 ${SW_SHOW}