3

编辑:我发现解决方案见底部文字

我正在尝试使 MUI2 欢迎页面的文本具有透明背景。

我可以让文本具有 MUI1 的透明背景,但 MUI2 不具有透明背景(标签窗口保持白色背景)。您还建议我只使用 MUI1 还是 MUI2 更好用?

你能帮我让 MUI2 欢迎页面的标签具有透明背景吗?

相关代码(请参阅下面的所有代码,您可以编译以查看错误):

!define MUI_PAGE_CUSTOMFUNCTION_SHOW WelcomePageShow
!insertmacro MUI_PAGE_WELCOME
Function WelcomePageShow
    # Why does the following code make the labels background transparent in MUI 
    # but NOT in MUI2???
    # What do I need to do to make it transparent in MUI2??

    ; Set transparent backgrounds.
    SetCtlColors $MUI_HWND 0xFFFFFF transparent
    !insertmacro SetTransparent $MUI_HWND 1201  # These aren't transparent in MUI2
    !insertmacro SetTransparent $MUI_HWND 1202  # These aren't transparent in MUI2

    # Make main white background a different colour
    GetDlgItem $R0 ${MUI_HWND} 1044
    SetCtlColors $R0 0x444444 0xff0000         # The background colour doesn't change in MUI2
    # Make smaller white background a different colour
    GetDlgItem $R0 ${MUI_HWND} 1018
    SetCtlColors $R0 0x444444 0x00ff00         # The background colour doesn't change in MUI2 
    Call RefreshParentControls
FunctionEnd

所有代码:

!include MUI2.nsh   # change this to !include MUI.nsh to see how the code works successfully for MUI1
!include WinMessages.nsh
!include "LogicLib.nsh"

; Local bitmap path.
!define BITMAP_FILE test2.bmp

; --------------------------------------------------------------------------------------------------
; Installer Settings
; --------------------------------------------------------------------------------------------------
Name "Background Bitmap"
OutFile "bgbitmap.exe"
ShowInstDetails show

; --------------------------------------------------------------------------------------------------
; Modern UI Settings
; --------------------------------------------------------------------------------------------------
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_CUSTOMFUNCTION_GUIINIT MyGUIInit

; --------------------------------------------------------------------------------------------------
; Definitions
; --------------------------------------------------------------------------------------------------
!ifndef LR_LOADFROMFILE
    !define LR_LOADFROMFILE     0x0010
!endif
!ifndef LR_CREATEDIBSECTION
    !define LR_CREATEDIBSECTION 0x2000
!endif
!ifndef IMAGE_BITMAP
    !define IMAGE_BITMAP        0
!endif
!ifndef SS_BITMAP
    !define SS_BITMAP           0x0000000E
!endif
!ifndef WS_CHILD
    !define WS_CHILD            0x40000000
!endif
!ifndef WS_VISIBLE
    !define WS_VISIBLE          0x10000000
!endif
!define HWND_TOP            0
!define SWP_NOSIZE          0x0001
!define SWP_NOMOVE          0x0002
!define IDC_BITMAP          1500
!define stRECT "(i, i, i, i) i"
Var hBitmap

; --------------------------------------------------------------------------------------------------
; Pages
; --------------------------------------------------------------------------------------------------
!define MUI_PAGE_CUSTOMFUNCTION_SHOW WelcomePageShow
!insertmacro MUI_PAGE_WELCOME

!insertmacro MUI_LANGUAGE English

; --------------------------------------------------------------------------------------------------
; Macros
; --------------------------------------------------------------------------------------------------
; Destroy a window.
!macro DestroyWindow HWND IDC
    GetDlgItem $R0 ${HWND} ${IDC}
    System::Call `user32::DestroyWindow(i R0)`
!macroend

; Give window transparent background.
!macro SetTransparent HWND IDC
    GetDlgItem $R0 ${HWND} ${IDC}
    SetCtlColors $R0 0x444444 transparent
!macroend

; Refresh window.
!macro RefreshWindow HWND IDC
    GetDlgItem $R0 ${HWND} ${IDC}
    ShowWindow $R0 ${SW_HIDE}
    ShowWindow $R0 ${SW_SHOW}
!macroend

; --------------------------------------------------------------------------------------------------
; Functions
; --------------------------------------------------------------------------------------------------
Function MyGUIInit

    ; Extract bitmap image.
    InitPluginsDir
    ReserveFile `${BITMAP_FILE}`
    File `/ONAME=$PLUGINSDIR\bg.bmp` `${BITMAP_FILE}`

    ; Get the size of the window.
    System::Call `*${stRECT} .R0`
    System::Call `user32::GetClientRect(i $HWNDPARENT, i R0)`
    System::Call `*$R0${stRECT} (, , .R1, .R2)`
    System::Free $R0

    ; Create bitmap control.
    System::Call `kernel32::GetModuleHandle(i 0) i.R3`
    System::Call `user32::CreateWindowEx(i 0, t "STATIC", t "", i ${SS_BITMAP}|${WS_CHILD}|${WS_VISIBLE}, i 0, i 0, i R1, i R2, i $HWNDPARENT, i ${IDC_BITMAP}, i R3, i 0) i.R1`
    System::Call `user32::SetWindowPos(i R1, i ${HWND_TOP}, i 0, i 0, i 0, i 0, i ${SWP_NOSIZE}|${SWP_NOMOVE})`

    ; Set the bitmap.
    System::Call `user32::LoadImage(i 0, t "$PLUGINSDIR\bg.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s`
    Pop $hBitmap
    SendMessage $R1 ${STM_SETIMAGE} ${IMAGE_BITMAP} $hBitmap

    ; Set transparent backgrounds.
    !insertmacro SetTransparent $HWNDPARENT 3
    !insertmacro SetTransparent $HWNDPARENT 1
    !insertmacro SetTransparent $HWNDPARENT 2
    !insertmacro SetTransparent $HWNDPARENT 1034
    !insertmacro SetTransparent $HWNDPARENT 1037
    !insertmacro SetTransparent $HWNDPARENT 1038

    ; Remove unwanted controls.
    !insertmacro DestroyWindow  $HWNDPARENT 1256
    !insertmacro DestroyWindow  $HWNDPARENT 1028
    !insertmacro DestroyWindow  $HWNDPARENT 1039

FunctionEnd

Function RefreshParentControls

    !insertmacro RefreshWindow  $HWNDPARENT 1037
    !insertmacro RefreshWindow  $HWNDPARENT 1038

FunctionEnd

Function WelcomePageShow

    # Why does the following code make the labels background transparent in MUI 
    # but NOT in MUI2???
    # What do I need to do to make it transparent in MUI2??

    ; Set transparent backgrounds.
    SetCtlColors $MUI_HWND 0xFFFFFF transparent
    !insertmacro SetTransparent $MUI_HWND 1201  # These aren't transparent in MUI2
    !insertmacro SetTransparent $MUI_HWND 1202  # These aren't transparent in MUI2

    # Make main white background a different colour
    GetDlgItem $R0 ${MUI_HWND} 1044
    SetCtlColors $R0 0x444444 0xff0000         # The background colour doesn't change in MUI2
    # Make smaller white background a different colour
    GetDlgItem $R0 ${MUI_HWND} 1018
    SetCtlColors $R0 0x444444 0x00ff00         # The background colour doesn't change in MUI2 
    Call RefreshParentControls
FunctionEnd

; Free loaded resources.
Function .onGUIEnd

    ; Destroy the bitmap.
    System::Call `gdi32::DeleteObject(i s)` $hBitmap

FunctionEnd

; --------------------------------------------------------------------------------------------------
; Dummy section
; --------------------------------------------------------------------------------------------------
Section "Dummy Section"
SectionEnd

解决方案:

    Function WelcomePageShow
          # Sets background image
        System::Call `user32::LoadImage(i 0, t "$PLUGINSDIR\wb.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s`
        Pop $hBitmap
        SendMessage $bitmapWindow ${STM_SETIMAGE} ${IMAGE_BITMAP} $hBitmap

           # Start solution
        SetCtlColors $mui.WelcomePage ${CTRL_COLOUR} transparent
        SetCtlColors $mui.WelcomePage.text ${CTRL_COLOUR} transparent
        SetCtlColors $mui.WelcomePage.title 0x333333 transparent

        !insertmacro DestroyWindow  $HWNDPARENT 1037
        !insertmacro DestroyWindow  $HWNDPARENT 1038
        !insertmacro DestroyWindow  $HWNDPARENT 1036 
        System::Call `user32::DestroyWindow(i $mui.WelcomePage.Image)`
        Call RefreshParentControls
    FunctionEnd
4

1 回答 1

0

解决方案:

Function WelcomePageShow
      # Sets background image
    System::Call `user32::LoadImage(i 0, t "$PLUGINSDIR\wb.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s`
    Pop $hBitmap
    SendMessage $bitmapWindow ${STM_SETIMAGE} ${IMAGE_BITMAP} $hBitmap

       # Start solution
    SetCtlColors $mui.WelcomePage ${CTRL_COLOUR} transparent
    SetCtlColors $mui.WelcomePage.text ${CTRL_COLOUR} transparent
    SetCtlColors $mui.WelcomePage.title 0x333333 transparent

    !insertmacro DestroyWindow  $HWNDPARENT 1037
    !insertmacro DestroyWindow  $HWNDPARENT 1038
    !insertmacro DestroyWindow  $HWNDPARENT 1036 
    System::Call `user32::DestroyWindow(i $mui.WelcomePage.Image)`
    Call RefreshParentControls
FunctionEnd
于 2012-06-04T03:44:37.123 回答