杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1896|回复: 0

NSIS:实现程序窗口逐渐透明的渐入渐出效果

[复制链接]
发表于 2015-2-3 22:22:36 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
需要修改版的插件(支持timer功能):
MUI:InstallOptions.dll
MUI2:nsDialogs.dll
以及system插件,(受api限制)只能运行于2k或者更高的平台之上。

说明:
请在相应目录下建立transparent.ini文件。

  1. /*
  2. <a href="http://www.flighty.cn" target="_blank">www.flighty.cn</a>
  3. */
  4. !AddPluginDir .\
  5. ;--------------------------------
  6. !define MUI2  ;定义UI版本(MUI,MUI2)
  7. !define iTransparentPercent 90   ;定义透明度
  8. Var DIALOG
  9. var iTransparent
  10. var bTransparent
  11. Name "Transparent Example"
  12. SetCompressor /SOLID lzma
  13. InstallDir $ExeDir
  14. OutFile transparent_nsis.exe
  15. !ifdef MUI2
  16. !include MUI2.nsh
  17. Var TIMERID
  18. !else
  19. !include MUI.nsh
  20. ;定义INI文件
  21. !define INI $PLUGINSDIR\transparent.ini
  22. !endif
  23. !include LogicLib.nsh
  24. !ifndef GWL_EXSTYLE
  25. !define GWL_EXSTYLE -20
  26. !endif
  27. !ifndef WS_EX_LAYERED
  28. !define WS_EX_LAYERED 0x80000
  29. !endif
  30. !ifndef LWA_ALPHA
  31. !define LWA_ALPHA 2
  32. !endif
  33. !define MUI_CUSTOMFUNCTION_ABORT UserAbort
  34. !ifdef MUI2
  35. Page custom nsDialogsPage
  36. !else
  37. page custom InstallOptionsPage
  38. !endif
  39. !define MUI_PAGE_CUSTOMFUNCTION_SHOW welcome_PageShow
  40. ; 欢迎页面
  41. !insertmacro MUI_PAGE_WELCOME
  42. !insertmacro MUI_PAGE_DIRECTORY
  43. !insertmacro MUI_PAGE_INSTFILES
  44. !insertmacro MUI_PAGE_FINISH
  45. ;--------------------------------
  46. !insertmacro MUI_LANGUAGE "SimpChinese"
  47. Section -Nil
  48. SectionEnd
  49. Function welcome_PageShow
  50. !ifdef MUI2
  51.   Pop $0
  52.    nsDialogs::KillTimer /NOUNLOAD $TIMERID
  53. !endif
  54.   GetDlgItem $0 $hwndparent 3
  55.   ShowWindow $0 0
  56.   ${if} $bTransparent == 0
  57.     ${For} $R0 0 $iTransparent
  58.       system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i R0, i ${LWA_ALPHA}) .iR1'
  59.       sleep 1
  60.     ${Next}
  61.   ${endif}
  62.   StrCpy $bTransparent 1
  63. FunctionEnd
  64. Function Exit
  65.   ${ForEach} $R0 $iTransparent 0 - 1
  66.     system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i R0, i ${LWA_ALPHA}) .iR1'
  67.     sleep 1
  68.   ${Next}
  69. FunctionEnd
  70. Function UserAbort
  71.   Messagebox MB_YESNO|MB_ICONQUESTION "Are Sure you want to cancel?" IDYES +2
  72.   Abort
  73.   call Exit
  74. FunctionEnd
  75. Function .onInstSuccess
  76.   Messagebox MB_OK|MB_ICONINFORMATION "Install Success!"
  77.   call Exit
  78. FunctionEnd
  79. Function SetWindowAttrib
  80.   ${if} $bTransparent == 0
  81.     system::call 'user32::GetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}) .iR0'
  82.     ;messagebox mb_ok $R0
  83.     IntOp $R0 $R0 + ${WS_EX_LAYERED}
  84.     system::call 'user32::SetWindowLong(i $HWNDPARENT, i ${GWL_EXSTYLE}, i R0) .iR1'
  85.     system::call 'user32::SetLayeredWindowAttributes(i $HWNDPARENT, i 0, i 0, i ${LWA_ALPHA}) .iR2'
  86.   Pop $R2
  87.   Pop $R1
  88.   Pop $R0
  89.   ${endif}
  90. FunctionEnd
  91. !ifndef MUI2
  92. Function InstallOptionsPage
  93.   Call SetWindowAttrib
  94.   InstallOptions::initDialog /NOUNLOAD ${INI}
  95.     Pop $DIALOG
  96. ;如果你想做的更逼真一些,请把它仿成欢迎页面(你的初始页面)一样的
  97.   InstallOptions::Show
  98. FunctionEnd
  99. !endif
  100. !ifdef MUI2
  101. Function OnTimer
  102.   Pop $0 ;Free Timer id
  103.   GetDlgItem $1 $HWNDPARENT 1
  104.   SendMessage $1 ${BM_CLICK} 0  1
  105. FunctionEnd
  106. Function nsDialogsPage
  107.   Call SetWindowAttrib
  108.   nsDialogs::Create /NOUNLOAD 1018
  109.   Pop $DIALOG
  110. ;如果你想做的更逼真一些,请把它仿成欢迎页面(你的初始页面)一样的
  111.   GetFunctionAddress $0 OnTimer
  112.   nsDialogs::CreateTimer /NOUNLOAD $0 10
  113.   Pop $TIMERID
  114.   nsDialogs::Show
  115. FunctionEnd
  116. !endif
  117. Function .OnInit
  118.   InitPluginsDir
  119. !ifndef MUI2
  120.   File /oname=${INI} "transparent.ini"
  121. !endif
  122.   IntOp $iTransparent ${iTransparentPercent} * 255
  123.   IntOp $iTransparent $iTransparent / 100
  124.   StrCpy $bTransparent 0
  125. FunctionEnd
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-17 23:58 , Processed in 0.120097 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表