例子:显示组件占用大小
优质
小牛编辑
138浏览
2023-12-01
引用脚本的内容:
/* “显示组件占用大小”与“在组件页面增加按钮”例子 by Ansifa 编译需要: NSIS建议最新版,ButtonEvent插件,还有修改过的UI.EXE(见附件) */ !AddPluginDir . XPStyle on OutFile "显示组件占用大小.EXE" Name "显示组件占用大小" !include "WordFunc.nsh" !include 'MUI.nsh' SetFont "Tahoma" 8 Var popmessage !insertmacro MUI_PAGE_WELCOME !define MUI_PAGE_CUSTOMFUNCTION_SHOW ComponentPageShow !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES ChangeUI all "UI.EXE" BrandingText "显示组件占用大小例子 By Ansifa" !insertmacro MUI_LANGUAGE "SimpChinese" InstType 全部安装 InstType 精简安装 ;精确计算section的大小(就是xxxKB转换为MB和GB)并且在组件框的组件名和组件大小之间补空格,使其总共为n个字符长。 !macro SetSizeText Section Push $0 Push $1 Push $2 Push $3 SectionGetText ${${Section}} $0 SectionGetSize ${${Section}} $1 IntCmp $1 1024 +3 +1 +3 StrCpy $1 "$1.0KB" Goto +12 IntOp $1 $1 * 100 IntOp $1 $1 / 1024 ;$1*100/1024取两位小数 StrCpy $2 $1 "" -1 ;最后一位 StrCpy $3 $1 1 -2 ;倒数第二位 StrCpy $1 $1 -2 ;前面位数 IntCmp $2 5 +1 +2 +1 ;如果大于5小数点加1 IntOp $3 $3 + 1 StrCmp $3 10 +1 +3 StrCpy $3 0 IntOp $1 $1 + 1 StrCpy $1 "$1.$3MB" ;整理数字 StrLen $2 $0 ;名称文本长度 StrLen $3 $1 ;大小文本长度 IntOp $2 46 - $2 IntOp $2 $2 - $3 ;$2=36-名称文本长度-大小文本长度 StrCpy $3 "" IntOp $2 $2 - 1 StrCpy $3 " $3" StrCmp $2 0 +1 -2 SectionSetText ${${Section}} "$0$3$1" Pop $3 Pop $2 Pop $1 Pop $0 !macroend Section "组件1" 1 SectionIn 1 2 AddSize 100 SectionEnd Section "组件2" 2 SectionIn 1 AddSize 1024 SectionEnd Section "组件3" 3 SectionIn 1 2 3 AddSize 10990 SectionEnd Section "组件4" 4 AddSize 1 SectionEnd Section "组件5" 5 AddSize 595948 SectionEnd Function .onInit ;给不同的section设置一次大小(12345是section的索引名,就是【Section "组件1" 1】中的最后那个1 !insertmacro SetSizeText 1 !insertmacro SetSizeText 2 !insertmacro SetSizeText 3 !insertmacro SetSizeText 4 !insertmacro SetSizeText 5 FunctionEnd ;将组件框内字体强制设置为宋体等宽字体,使插入空格后能对齐 Function ComponentPageShow FindWindow $0 "#32770" "" $HWNDPARENT GetDlgItem $1 $0 1032 CreateFont $0 "宋体" "9" "" SendMessage $1 0x0030 $0 0 ;给按钮默认文字 FindWindow $R0 "#32770" "" $HWNDPARENT GetDlgItem $R0 $R0 1099 SendMessage $R0 ${WM_SETTEXT} 0 'STR:查看详细信息' StrCpy $popmessage "将鼠标移到相应组件上,按此按钮可以查看更详细的信息" ;给按钮加动作 GetFunctionAddress $R0 ButtonClicked ButtonEvent::AddEventHandler /NOUNLOAD 1099 $R0 FunctionEnd ;鼠标移到组件上面的响应 Function .onMouseOverSection FindWindow $R0 "#32770" "" $HWNDPARENT GetDlgItem $R0 $R0 1043 SendMessage $R0 ${WM_SETTEXT} 0 "STR:将鼠标移上组件框即可看到详细说明" StrCmp $0 0 "" +3 SendMessage $R0 ${WM_SETTEXT} 0 "STR:第一个组件是一个组件" StrCpy $popmessage "我是第1个组件" StrCmp $0 1 "" +3 SendMessage $R0 ${WM_SETTEXT} 0 "STR:第二个组件是两个组件" StrCpy $popmessage "我是第2个组件" StrCmp $0 2 "" +3 SendMessage $R0 ${WM_SETTEXT} 0 "STR:第三个组件" StrCpy $popmessage "我是第3个组件" StrCmp $0 3 "" +3 SendMessage $R0 ${WM_SETTEXT} 0 "STR:第4个组件" StrCpy $popmessage "我是第4个组件" StrCmp $0 4 "" +3 SendMessage $R0 ${WM_SETTEXT} 0 "STR:第5个组件" StrCpy $popmessage "我是第5个组件" ;组件框右面的按钮是用reshacker修改UI.EXE加进去的,ID随意起,我随便写了一个1099,下面要引用就是1099 FindWindow $R0 "#32770" "" $HWNDPARENT GetDlgItem $R0 $R0 1099 SectionGetText $0 $1 ;将组件后面的组件大小文字删掉,只需要组件名,分隔符就是空格了 ${WordFind} $1 " " "+1{" $1 SendMessage $R0 ${WM_SETTEXT} 0 'STR:查阅$1的详细信息' FunctionEnd Function ButtonClicked StrCmp $popmessage "" +2 MessageBox MB_ICONINFORMATION|MB_OK $popmessage FunctionEnd
另存附件。