代码之家  ›  专栏  ›  技术社区  ›  zbynour

如何在NSIS安装程序中显示鼠标移动时的文本

  •  0
  • zbynour  · 技术社区  · 14 年前

    有没有可能在NSIS安装程序自定义页面上显示一些描述性文本,但只在鼠标悬停时显示?

    我在安装程序开始时进行了先决条件检查,当一个(或多个)测试失败时,将显示相应的警告消息。它是在整个安装之前显示的自定义页面。问题是,有太多的消息(在最坏的情况下)和安装程序页面太小-不可能显示所有的消息而不覆盖。。。因此,我只想在下面的特定区域显示一些标题(简要描述问题)和更详细的信息,但仅当鼠标移到简短文本上时。或者,另一个解决方案是创建一些可滚动区域。。。

    但我不知道在国家安全局怎么做。我知道。onMouseOverSection回调,但它只能在节选择页中使用。

    有可能在NSIS页面上做吗?

    提前谢谢。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Anders    14 年前

    我不认为在 instfiles 佩奇是个好主意。我想要一个定制页面。如果您决定采用自定义页面的想法,您可能有3个选项:

    • 创建一个自定义nsis插件,它可以以任何方式显示页面。
    • 使用nsDialogs创建自定义页,并使用 WndSubclass plugin
    • 使用两个组件页并调整其中一个。

    下面的示例使用第三个选项,因为它只使用官方nsis插件。

    OutFile "$%temp%\test.exe"
    Name "Prereq desc"
    RequestExecutionLevel user
    !include MUI2.nsh
    
    !define MUI_PAGE_HEADER_TEXT "Header blablah"
    !define MUI_PAGE_HEADER_SUBTEXT "subheader blablah"
    !define MUI_COMPONENTSPAGE_TEXT_TOP "blablah 1"
    !define MUI_COMPONENTSPAGE_TEXT_INSTTYPE " "
    !define MUI_COMPONENTSPAGE_TEXT_COMPLIST " "
    !define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE "blablah 4"
    !define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "blablah 5"
    !define MUI_PAGE_CUSTOMFUNCTION_PRE prereqcreate
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW prereqshow
    !insertmacro MUI_PAGE_COMPONENTS
    
    !define MUI_PAGE_CUSTOMFUNCTION_PRE componentscreate
    !insertmacro MUI_PAGE_COMPONENTS
    
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE "English"
    
    Function .onInit
    InitPluginsDir
    StrCpy $0 0
    loop:
        ClearErrors
        SectionGetText $0 $1
        IfErrors done
        WriteIniStr "$Pluginsdir\sec.ini" S $0 $1 ;Save section names...
        IntOp $0 $0 + 1
        Goto loop
    done:   
    FunctionEnd
    
    !macro ShowSections initial flip
    StrCpy $0 0
    StrCpy $2 ${initial}
    loop:
        ClearErrors
        SectionGetText $0 $1
        IfErrors done
        ReadIniStr $1 "$Pluginsdir\sec.ini" S $0
        IntCmpU 0 $2 "" +2 +2
        StrCpy $1 ""
        SectionSetText $0 $1
        IntOp $0 $0 + 1
        IntCmpU $0 ${flip} "" +2 +2
        IntOp $2 $2 ! 
        Goto loop
    done:
    !macroend
    
    !macro CreatePreReq text name
    Section /o "${text}" ${name}
    SectionIn RO
    SectionEnd
    !macroend
    
    !insertmacro CreatePreReq "Windows Installer v4.5" SEC_PRMSI
    !insertmacro CreatePreReq ".NET v666" SEC_PRDOTNET
    
    Section "Program files" SEC_PROG
    ;...
    SectionEnd
    
    Section "Desktop shortcut" SEC_DESKLNK
    ;...
    SectionEnd
    
    !define FIRSTREALSECTION ${SEC_PROG}
    
    Function prereqcreate
    !insertmacro ShowSections 1 ${FIRSTREALSECTION}
    FunctionEnd
    
    Function prereqshow
    FindWindow $0 "#32770" "" $HWNDPARENT
    GetDlgItem $1 $0 0x3FD
    ShowWindow $1 0 
    GetDlgItem $1 $0 0x3FE
    ShowWindow $1 0 
    GetDlgItem $1 $0 0x3FF
    ShowWindow $1 0 ;hide space texts
    GetDlgItem $1 $0 0x408
    !define TVM_SETIMAGELIST 0x1109
    SendMessage $1 ${TVM_SETIMAGELIST} 2 0 ;Remove images (leaking the imagelist in the process, oh well)
    System::Call '*(&i24)i.r2'
    System::Call 'user32::GetWindowRect(ir1,ir2)'
    System::Call 'user32::MapWindowPoints(i0,ir0,ir2,i2)'
    System::Call '*$2(i,i.r0,i.r3,i.r4)'
    System::Free $2
    IntOp $4 $4 - $0
    System::Call 'user32::SetWindowPos(ir1,i0,i0,ir0,ir3,ir4,i0)'
    FunctionEnd
    
    Function componentscreate
    !insertmacro ShowSections 0 ${FIRSTREALSECTION}
    FunctionEnd
    
    !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
      !insertmacro MUI_DESCRIPTION_TEXT ${SEC_PRMSI} "You need MSI in a NSIS installer? ;)"
      !insertmacro MUI_DESCRIPTION_TEXT ${SEC_PRDOTNET} "You need moar bloat!"
      !insertmacro MUI_DESCRIPTION_TEXT ${SEC_PROG} "Required program files..."
      !insertmacro MUI_DESCRIPTION_TEXT ${SEC_DESKLNK} "Stupid desktop shortcut"
    !insertmacro MUI_FUNCTION_DESCRIPTION_END