BgWorker为NSIS提供多线程支持

/*
BgWorker.dll插件为NSIS提供多线程支持,特别是在自定义界面进行进度条操作时常要用到的插件.
*/
!AddPluginDir "../Plugins"
OutFile "BgWorker.exe"
SetCompressor /SOLID lzma
!include "nsDialogs.nsh"
!include "FileFunc.nsh"
!define secondsofwork 10
Page custom page1.create
Function Func3
 #${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6
 #SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:$4:$5:$6"
FunctionEnd
Function Func2
 System::Call kernel32::GetTickCount()i.r1
 loop:
 System::Call kernel32::GetTickCount()i.r2
 IntOp $2 $2 - $1
 IntOp $3 1000 * ${secondsofwork}
 IntOp $4 100 * $2
 IntOp $4 $4 / $3
 ${If} $4 <> $5
 StrCpy $5 $4
 ${NSD_SetText} $8 "Working... ($4%)"
 ${EndIf}
 IntCmp $2 $3 0 loop
FunctionEnd
Function Func2_
 GetFunctionAddress $0 Func2_
 nsDialogs::KillTimer $0
 !if 1 ;do work in background thread?
 GetFunctionAddress $0 Func2
 BgWorker::CallAndWait
 !else
 call Func2
 !endif
 SetCtlColors $8 0x007700 transparent
 ${NSD_SetText} $8 "Work completed"
 System::Call "user32::InvalidateRect(i $hwndparent,i0,i 1)"
FunctionEnd
Function Func1
 System::Call kernel32::GetTickCount()i.r1
 loop:
 System::Call kernel32::GetTickCount()i.r2
 IntOp $2 $2 - $1
 IntOp $3 1000 * ${secondsofwork}
 IntOp $4 100 * $2
 IntOp $4 $4 / $3
 ${If} $4 <> $5
 StrCpy $5 $4
 ${NSD_SetText} $9 "Working... ($4%)"
 ${EndIf}
 IntCmp $2 $3 0 loop
FunctionEnd
Function Func1_
 GetFunctionAddress $0 Func1_
 nsDialogs::KillTimer $0
 !if 1 ;do work in background thread?
 GetFunctionAddress $0 Func1
 BgWorker::CallAndWait
 !else
 call Func1
 !endif
 SetCtlColors $9 0x007700 transparent
 ${NSD_SetText} $9 "Work completed"
 System::Call "user32::InvalidateRect(i $hwndparent,i0,i 1)"
FunctionEnd
Function page1.create
 nsDialogs::Create 1018
 Pop $0
 ${NSD_CreateLabel} 0 0 100% 10u "Working..."
 Pop $9
 SetCtlColors $9 0x0000FF 0xFFFFFF
 ${NSD_CreateLabel} 0 50 100% 10u "Working..."
 Pop $8
 SetCtlColors $8 0x0000FF 0xFFFFFF
 GetFunctionAddress $1 Func1_
 nsDialogs::CreateTimer $1 100
 GetFunctionAddress $1 Func2_
 nsDialogs::CreateTimer $1 100
 GetFunctionAddress $1 Func3
 nsDialogs::CreateTimer $1 100
 nsDialogs::Show
FunctionEnd
Section "永恒心锁"
SectionEnd
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容