簡體   English   中英

如何在NSIS安裝程序中在鼠標移動時顯示一些文本

[英]How to show some text on mouse move in NSIS installer

是否有可能在NSIS安裝程序自定義頁面上顯示一些描述性文本,但只能在鼠標懸停時顯示?

我在安裝程序的開頭進行了先決條件檢查,當一個(或多個)測試失敗時,將顯示相應的警告消息。 這是在整個安裝之前顯示的自定義頁面。 問題是,有太多消息(在最壞的情況下)並且安裝程序頁面很小-無法覆蓋所有消息而不顯示它們...所以我只想顯示一些標題(簡要描述問題)和更詳細的信息(位於專用區域下面的某個位置),但僅限於將鼠標移到簡短文本上時。 或者,其他解決方案是創建一些可滾動區域。

但是我不知道如何在NSIS中做到這一點。 我知道.onMouseOverSection回調,但是AFAIK它只能在節選擇頁面中使用。

是否可以在NSIS頁面中執行此操作?

提前致謝。

我認為在instfiles頁面上執行此操作不是一個好主意。 我會去自定義頁面。 如果您決定采用自定義頁面提示,則可能有3個選擇:

  • 創建一個自定義的nsis插件,以您想要的任何方式顯示頁面。
  • 使用nsDialogs創建一個自定義頁面,並使用WndSubclass插件處理鼠標消息。
  • 使用兩個組件頁面並調整其中之一。

以下示例使用第三個選項,因為它僅使用官方的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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM