nsDialogs如何使用控件可用或不可用

;NSDialogs 允许使用 ${NSD_Create*} 创建控件并返回 HWND 值到堆栈,这样我们很方便就可以对控件进行设置可用或不可用,当然我们这里要使用NSIS里的EnableWindow 命令。

;比如我们创建一个大按钮,再创建一个勾选框,点击勾选框时让按钮可用否则不可用。

!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
Caption "如何使用控件可用或不可用"
OutFile "yhxs3344.exe"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
Page Custom pre
var dialog
var hwnd
var button
Function pre
 nsDialogs::Create 1018
 Pop $dialog
 ${NSD_CreateCheckbox} 0 0 50% 6% "使按钮可用/不可用"
 Pop $hwnd
 ${NSD_OnClick} $hwnd EnDisableButton
 ${NSD_CreateButton} 25% 25% 50% 50% "永恒心锁"
 Pop $button
 EnableWindow $button 0 # 开始状态为灰化不可用 disabled
 nsDialogs::Show
FunctionEnd
Function EnDisableButton
 Pop $hwnd
 ${NSD_GetState} $hwnd $0
 ${If} $0 == 1
 EnableWindow $button 1
 ${Else}
 EnableWindow $button 0
 ${EndIf}
FunctionEnd
Section ""
SectionEnd
在上面例子的基础上,我们为按钮增加一个点击操作。
!include "nsDialogs.nsh"
!include "winmessages.nsh"
!include "logiclib.nsh"
Caption "如何使用控件可用或不可用"
OutFile "yhxs3344.exe"
loadlanguagefile "${NSISDIR}ContribLanguage filessimpChinese.nlf"
Page Custom pre
var dialog
var hwnd
var button
Function pre
 nsDialogs::Create 1018
 Pop $dialog
 ${NSD_CreateCheckbox} 0 0 50% 6% "使按钮可用/不可用"
 Pop $hwnd
 ${NSD_OnClick} $hwnd EnDisableButton
 ${NSD_CreateButton} 25% 25% 50% 50% "永恒心锁"
 Pop $button
 ${NSD_OnClick} $button OpenURL
 EnableWindow $button 0 # 开始状态为灰化不可用 disabled
 nsDialogs::Show
FunctionEnd
Function EnDisableButton
 Pop $hwnd
 ${NSD_GetState} $hwnd $0
 ${If} $0 == 1
 EnableWindow $button 1
 ${Else}
 EnableWindow $button 0
 ${EndIf}
FunctionEnd

Function OpenURL
 Pop $button
 ExecShell open "http://www.yhxs3344.net"
FunctionEnd
Section ""
SectionEnd
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容