找回密码
 加入
搜索
查看: 1532|回复: 8

[网络通信] 求助关于修改A版的_MsgBoxDJS函数,增加自定义按钮文字。【已解决】

[复制链接]
发表于 2019-2-19 09:20:51 | 显示全部楼层 |阅读模式
本帖最后由 fybhwsx 于 2019-2-21 08:37 编辑


Local $MsgBox_DJS = _MsgBoxDJS(2 + 64 + 0 + 262144, '提示', '增加了按钮文本自定义,取消了A版_MsgBoxDJS的前两种模式,只保留按钮倒计时。这样$Cflag变量和$__Cflag = $Cflag就没用了,因为完全不懂DllCall,' & _
                '请教下A版或懂DllCall的朋友,这两个变量有在DllCall中传递吗,直接删除似乎会导致不稳定?还有就是有点儿强迫症,怎样一开始就显示自定义的按钮文本和倒计时,而不是先显示下MsgBox的默认按钮?希望A版或知道的朋友能帮助实现想法!', 300, '', '', '重装', '跳过', '退出')
MsgBox(262144, '', '按下按钮:' & $MsgBox_DJS)

;_MsgBoxDJS函数 链接 http://www.autoitx.com/forum.php ... =%B5%B9%BC%C6%CA%B1 作者:afan版主
Func _MsgBoxDJS($flag, $title, $text, $timeout = 10, $Cflag = 2, $hwnd = '', $Button1 = '', $Button2 = '', $Button3 = '')
        Global $___Timer = DllCallbackRegister('__Timer', 'int', 'hwnd;uint;uint;dword')
        If $timeout = '' Or $timeout = -1 Then $timeout = 10
        Global $s__title = $title, $s__text = $text, $__Cflag = $Cflag, $v__zt = 1, $v__ttc = $timeout, $__bttxtFlag = 0, $Button__1 = $Button1, $Button__2 = $Button2, $Button__3 = $Button3
        Global $__Timer_DLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', 0, 'int', 100, 'ptr', DllCallbackGetPtr($___Timer))

        Local $rtMsg = MsgBox($flag, $title, $text, 0, $hwnd)

        DllClose($__Timer_DLL)
        ;DllCallbackFree($___Timer)
        Return $rtMsg
EndFunc   ;==>_MsgBoxDJS

Func __Timer($hwnd, $uiMsg, $idEvent, $dwTime)
        Global $__Timer_DLL, $__bttxtFlag, $__Cflag, $s__title, $v__ttc, $s__text, $v__zt, $___Timer, $s_titleF, $v__TimerJS, $Button__1, $Button__2, $Button__3
        If $idEvent = $__Timer_DLL[0] Then
                Global $s__bttxt, $i_ControlFocus, $n__Static
                If $__bttxtFlag = 0 Then
                        ;WinActivate($s__title)
                        If $Button__1 <> '' Then ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                        If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                        If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        $i_ControlFocus = ControlGetFocus($s__title)
                        $s__bttxt = ControlGetText($s__title, $s__text, $i_ControlFocus)
                        $__bttxtFlag = 1
                EndIf
                If $v__TimerJS = 9 Then

                        If $i_ControlFocus = 'Button1' Then
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__1 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button2' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__2 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button3' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__3 & StringFormat(' %s', $v__ttc - $v__zt))
                        EndIf

                        If $v__zt = $v__ttc Then
                                DllClose($__Timer_DLL)
                                ;DllCallbackFree($___Timer)
                                ControlClick($s__title, $s__text, $i_ControlFocus, '', 2)
                        EndIf
                        $v__zt += 1
                        $v__TimerJS = 0
                Else
                        $v__TimerJS += 1
                EndIf
        EndIf
EndFunc   ;==>__Timer

 楼主| 发表于 2019-2-20 13:15:59 | 显示全部楼层
Local $MsgBox_DJS = _MsgBoxDJS(2 + 64 + 0 + 262144, '提示', '哈哈,终于让我找到导致倒计时偶尔异常的原因了!Return $rtMsg 这句上面的 DllCallbackFree($___Timer) 不能注释掉,否则倒计时不会停下,' & _
                '虽然先前提示窗口已经关闭,看不到倒计时了,但它依然存在,再次调用_MsgBoxDJS就存在隐患。那既然和 $__Cflag 与 $Cflag 变量没有关系,直接拿掉。其实 $__bttxtFlag 变量和 If $__bttxtFlag = 0 Then 那' & _
                '段代码留下 $i_ControlFocus = ControlGetFocus($s__title, $s__text) 其它也能拿掉,但那样显示默认按钮时间更长了,强迫症就更严重了。。还没做更多测试,不知下面这样修改还有没有其它问题。。', 300, '', '重装', '跳过', '退出')
MsgBox(262144, '', '按下按钮:' & $MsgBox_DJS)

;_MsgBoxDJS函数 链接 http://www.autoitx.com/forum.php ... =%B5%B9%BC%C6%CA%B1 作者:afan版主
Func _MsgBoxDJS($flag, $title, $text, $timeout = 10, $hwnd = '', $Button1 = '', $Button2 = '', $Button3 = '')
        Global $___Timer = DllCallbackRegister('__Timer', 'int', 'hwnd;uint;uint;dword')
        If $timeout = '' Or $timeout = -1 Then $timeout = 10
        Global $s__title = $title, $s__text = $text, $v__zt = 1, $v__ttc = $timeout, $__bttxtFlag = 0, $Button__1 = $Button1, $Button__2 = $Button2, $Button__3 = $Button3
        Global $__Timer_DLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', 0, 'int', 100, 'ptr', DllCallbackGetPtr($___Timer))
        Local $rtMsg = MsgBox($flag, $title, $text, 0, $hwnd)
        DllClose($__Timer_DLL)
        DllCallbackFree($___Timer)
        Return $rtMsg
EndFunc   ;==>_MsgBoxDJS

Func __Timer($hwnd, $uiMsg, $idEvent, $dwTime)
        Global $__Timer_DLL, $__bttxtFlag, $s__title, $v__ttc, $s__text, $v__zt, $___Timer, $s_titleF, $v__TimerJS, $Button__1, $Button__2, $Button__3
        If $idEvent = $__Timer_DLL[0] Then
                Global $i_ControlFocus
                If $__bttxtFlag = 0 Then
                        If $Button__1 <> '' Then ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                        If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                        If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        WinActivate($s__title, $s__text)
                        $i_ControlFocus = ControlGetFocus($s__title, $s__text)
                        $__bttxtFlag = 1
                EndIf
                If $v__TimerJS = 9 Then
                        If $i_ControlFocus = 'Button1' Then
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__1 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button2' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__2 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button3' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__3 & StringFormat(' %s', $v__ttc - $v__zt))
                        EndIf
                        If $v__zt = $v__ttc Then
                                ControlClick($s__title, $s__text, $i_ControlFocus, '', 2)
                        EndIf
                        $v__zt += 1
                        $v__TimerJS = 0
                Else
                        $v__TimerJS += 1
                EndIf
        EndIf
EndFunc   ;==>__Timer
 楼主| 发表于 2019-2-20 13:43:55 | 显示全部楼层
使用自定义按钮文本时,应该注意下按钮标志选择:当需要三个按钮时最好选$MB_ABORTRETRYIGNORE(2),两个按钮时选$MB_YESNO(4),这样可以随便自定义按钮,不用考虑右上角的X关闭按钮干扰选择!
发表于 2019-2-20 14:26:16 | 显示全部楼层
没有看明白你的意思!
 楼主| 发表于 2019-2-20 15:15:07 | 显示全部楼层
redapple2008 发表于 2019-2-20 14:26
没有看明白你的意思!

感谢关注,就是修改A版的_MsgBoxDJS函数,增加按钮文字自定义,遇到问题。但这个问题原帖中有说时X64位系统的导致的,解决方法就是注释掉DllCallbackFree($___Timer),所以我就跟着注释掉了那两个DllCallbackFree($___Timer),结果运行_MsgBoxDJS总会出现倒计时异常。才来求助各位,现在问题似乎解决了。正在继续观察。。。
 楼主| 发表于 2019-2-20 15:24:16 | 显示全部楼层
至于强迫症说的问题,我想参考这个帖子http://www.autoitx.com/forum.php ... t=MsgBox&page=1应该能解决吧。
 楼主| 发表于 2019-2-20 15:26:23 | 显示全部楼层
不过那得等以后学习了DllCall再说了。。
 楼主| 发表于 2019-2-21 08:33:52 | 显示全部楼层
;又小改一下,目前使用一切正常,没白折腾,至少知道了 Return $rtMsg 这句上面的 DllCallbackFree($___Timer) 不能像下面链接中有人说的简单的注释掉!再次感谢A版发布_MsgBoxDJS!
Local $MsgBox_DJS = _MsgBoxDJS(2 + 64 + 0 + 262144, '提示', '按钮1、按钮2、按钮3位置可以自由修改成想要的文字了!如果用不到按钮2和按钮3留空或删除。', 300, '', '按钮1', '按钮2', '按钮3')
MsgBox(262144, '', '按下按钮:' & $MsgBox_DJS)
;_MsgBoxDJS函数 链接 http://www.autoitx.com/forum.php ... =%B5%B9%BC%C6%CA%B1 作者:afan版主
Func _MsgBoxDJS($flag, $title, $text, $timeout = 10, $hwnd = '', $Button1 = '', $Button2 = '', $Button3 = '')
        Global $___Timer = DllCallbackRegister('__Timer', 'int', 'hwnd;uint;uint;dword')
        If $timeout = '' Or $timeout = -1 Then $timeout = 10
        Global $s__title = $title, $s__text = $text, $v__zt = 1, $v__ttc = $timeout, $__bttxtFlag = 0, $Button__1 = $Button1, $Button__2 = $Button2, $Button__3 = $Button3
        Global $__Timer_DLL = DllCall('user32.dll', 'uint', 'SetTimer', 'hwnd', 0, 'uint', 0, 'int', 100, 'ptr', DllCallbackGetPtr($___Timer))
        Local $rtMsg = MsgBox($flag, $title, $text, 0, $hwnd)
        DllClose($__Timer_DLL)
        DllCallbackFree($___Timer)
        Return $rtMsg
EndFunc   ;==>_MsgBoxDJS
Func __Timer($hwnd, $uiMsg, $idEvent, $dwTime)
        Global $__Timer_DLL, $__bttxtFlag, $s__title, $v__ttc, $s__text, $v__zt, $___Timer, $v__TimerJS, $Button__1, $Button__2, $Button__3
        If $idEvent = $__Timer_DLL[0] Then
                Global $i_ControlFocus
                If $__bttxtFlag = 0 Then
                        If $Button__1 <> '' Then ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                        If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                        If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        WinActivate($s__title)
                        $i_ControlFocus = ControlGetFocus($s__title)
                        $__bttxtFlag = 1
                EndIf
                If $v__TimerJS = 9 Then
                        If $i_ControlFocus = 'Button1' Then
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__1 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__2 <> '' Then ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button2' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__2 & StringFormat(' %s', $v__ttc - $v__zt))
                                If $Button__3 <> '' Then ControlSetText($s__title, $s__text, 'Button3', $Button__3)
                        ElseIf $i_ControlFocus = 'Button3' Then
                                ControlSetText($s__title, $s__text, 'Button1', $Button__1)
                                ControlSetText($s__title, $s__text, 'Button2', $Button__2)
                                ControlSetText($s__title, $s__text, $i_ControlFocus, $Button__3 & StringFormat(' %s', $v__ttc - $v__zt))
                        EndIf
                        If $v__zt = $v__ttc Then
                                ControlClick($s__title, $s__text, $i_ControlFocus, 'primary', 2)
                        EndIf
                        $v__zt += 1
                        $v__TimerJS = 0
                Else
                        $v__TimerJS += 1
                EndIf
        EndIf
EndFunc   ;==>__Timer
发表于 2019-2-21 08:55:54 | 显示全部楼层
楼主也是较真的人,支持一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 17:24 , Processed in 0.070024 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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