脚本:实现程序窗口逐渐透明的渐入渐出效果
优质
小牛编辑
152浏览
2023-12-01
需要修改版的插件(支持timer功能):
MUI: InstallOptions.dll
MUI2:nsDialogs.dll
以及system插件,(受api限制)只能运行于2k或者更高的平台之上。
脚本编写:Restools、X-Star、zhfi
引用transparent.nsi的内容:
MUI: InstallOptions.dll
MUI2:nsDialogs.dll
以及system插件,(受api限制)只能运行于2k或者更高的平台之上。
脚本编写:Restools、X-Star、zhfi
引用transparent.nsi的内容:
/*代码开始*/ ## transparent.nsi ## ## Script write by Restools X-Star, Mod by zhfi. ## Needs the mod version of nsdialogs.dll or installoptions.dll plugin (suppert timer function)! ## Transparent Splash effect in NSIS while run/Exit installer, only effective on windows 2k or higher. /* ## function usage: ;function SetLayeredWindowAttributes(hwnd: HWND; crKey: TColor; bAlpha: BYTE; dwFlags: DWORD): Boolean; ; external 'SetLayeredWindowAttributes@user32.dll stdcall'; ;function GetWindowLong(Wnd: HWnd; Index: Integer): Longint; ; external 'GetWindowLongA@user32.dll stdcall'; ;function SetWindowLong(Wnd: HWnd; Index: Integer; NewLong: Longint): Longint; ; external 'SetWindowLongA@user32.dll stdcall'; ; SetWindowLong(WizardForm.Handle, GWL_EXSTYLE, GetWindowLong(WizardForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED); system::call 'user32::GetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}) .iR0' ;messagebox mb_ok $R0 IntOp $R0 $R0 + ${WS_EX_LAYERED} system::call 'user32::SetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}, i R0) .iR1' ; SetLayeredWindowAttributes(WizardForm.Handle, 0, Transparent, LWA_ALPHA); system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i $iTransparent, i ${LWA_ALPHA}) .iR2' */ !AddPluginDir .\ ;-------------------------------- ;定义UI版本(MUI,MUI2) !define MUI ;定义透明度 !define iTransparentPercent 90 Var DIALOG var iTransparent var bTransparent Name "Transparent Example" SetCompressor /SOLID lzma InstallDir $ExeDir OutFile transparent_nsis.exe !ifdef MUI2 !include MUI2.nsh Var TIMERID !else !include MUI.nsh ;定义INI文件 !define INI $PLUGINSDIR\transparent.ini !endif !include LogicLib.nsh !ifndef GWL_EXSTYLE !define GWL_EXSTYLE -20 !endif !ifndef WS_EX_LAYERED !define WS_EX_LAYERED 0x80000 !endif !ifndef LWA_ALPHA !define LWA_ALPHA 2 !endif !define MUI_CUSTOMFUNCTION_ABORT UserAbort !ifdef MUI2 Page custom nsDialogsPage !else page custom InstallOptionsPage !endif !define MUI_PAGE_CUSTOMFUNCTION_SHOW welcome_PageShow ; 欢迎页面 !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH ;-------------------------------- !insertmacro MUI_LANGUAGE "SimpChinese" Section -Nil SectionEnd Function welcome_PageShow !ifdef MUI2 Pop $0 nsDialogs::DestroyTimer /NOUNLOAD $TIMERID !endif GetDlgItem $0 $hwndparent 3 ShowWindow $0 0 ${if} $bTransparent == 0 ${For} $R0 0 $iTransparent system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i R0, i ${LWA_ALPHA}) .iR1' sleep 2 ${Next} ${endif} StrCpy $bTransparent 1 FunctionEnd Function Exit ${ForEach} $R0 $iTransparent 0 - 1 system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i R0, i ${LWA_ALPHA}) .iR1' sleep 2 ${Next} FunctionEnd Function UserAbort Messagebox MB_YESNO|MB_ICONQUESTION "Are Sure you want to cancel?" IDYES +2 Abort call Exit FunctionEnd Function .onInstSuccess Messagebox MB_OK|MB_ICONINFORMATION "Install Success!" call Exit FunctionEnd Function SetWindowAttrib ${if} $bTransparent == 0 system::call 'user32::GetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}) .iR0' ;messagebox mb_ok $R0 IntOp $R0 $R0 + ${WS_EX_LAYERED} system::call 'user32::SetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}, i R0) .iR1' system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i 0, i ${LWA_ALPHA}) .iR2' Pop $R2 Pop $R1 Pop $R0 ${endif} FunctionEnd !ifndef MUI2 Function InstallOptionsPage Call SetWindowAttrib InstallOptions::initDialog /NOUNLOAD ${INI} Pop $DIALOG ;如果你想做的更逼真一些,可以把它仿成欢迎页面一样的 InstallOptions::Show FunctionEnd !endif !ifdef MUI2 Function OnTimer Pop $0 ;Free Timer id GetDlgItem $1 $HWNDPARENT 1 SendMessage $1 ${BM_CLICK} 0 1 FunctionEnd Function nsDialogsPage Call SetWindowAttrib nsDialogs::Create /NOUNLOAD 1018 Pop $DIALOG ;如果你想做的更逼真一些,请把它仿成欢迎页面(你的初始页面)一样的 GetFunctionAddress $0 OnTimer nsDialogs::CreateTimer /NOUNLOAD 10 $0 Pop $TIMERID nsDialogs::Show FunctionEnd !endif Function .OnInit InitPluginsDir !ifndef MUI2 File /oname=${INI} "transparent.ini" !endif IntOp $iTransparent ${iTransparentPercent} * 255 IntOp $iTransparent $iTransparent / 100 StrCpy $bTransparent 0 FunctionEnd
附件另存。