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

[AU3基础] 【已解决】窗口置顶按钮文字改变

[复制链接]
发表于 2021-10-30 02:45:46 | 显示全部楼层 |阅读模式
本帖最后由 hljkwan 于 2021-11-9 20:50 编辑

实在搞不定了,求大神给我帮一下,我现在给出来的代码是,点击一下【设置置顶】,窗口确实置顶了,问题按钮不显示【取消置顶】
想要达到的效果是点击一下【设置置顶】窗口置顶,按钮显示【取消置顶】,改了好几遍搞不定,原谅我的菜~~


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 0)
#Region ### START Koda GUI section ### Form=


$Form1_ = GUICreate("Form1", 617, 440, 192, 124)
$tab5buttonview2 = GUICtrlCreateButton("设置置顶", 128, 112, 233, 73)
GUICtrlSetFont(-1, 42, 400, 0, "宋体")
GUICtrlSetTip(-1, "推荐项只基于部分系统优化设置方面,当然您也可以在添加")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)




Local $bOnTop = False
GUISetState()


While 1
        
        
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE

                        Exit
                        
        
                Case -3
                        Exit
                Case $tab5buttonview2
                        $bOnTop = Not $bOnTop
                        WinSetOnTop($Form1_, '', $bOnTop)               


                Case $tab5buttonview2

                        If GUICtrlRead($tab5buttonview2) = "设置置顶" Then
                                GUICtrlSetData($tab5buttonview2, "取消置顶")
                                
                                
        

                        ElseIf GUICtrlRead($tab5buttonview2) = "取消置顶" Then
                                GUICtrlSetData($tab5buttonview2, "设置置顶")
                        EndIf


        EndSwitch

WEnd



;防重复运行
Func _MyProExists()
        $my_Version = "By lrcf"
        If WinExists($my_Version) Then Exit
        AutoItWinSetTitle($my_Version)
EndFunc   ;==>_MyProExists



While 1 ;基于表达式进行循环.
        $msg = GUIGetMsg() ;捕获窗口消息
        Select ;条件运行语句.
                Case $msg = $GUI_EVENT_CLOSE ;表达式

                        Exit ;终止并退出运行的脚本.

                        
                        ;--------------------------------------------------------------------------------------搜索应用Z
                        ;------------------------------------------------------------------------------------------------综合功能Z
        EndSelect
WEnd


 楼主| 发表于 2021-10-30 03:04:50 | 显示全部楼层
现在代码是点击【设置置顶】变成【取消置顶】,问题是窗口不置顶

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 0)
#Region ### START Koda GUI section ### Form=


$Form1_ = GUICreate("Form1", 617, 440, 192, 124)
$tab5buttonview2 = GUICtrlCreateButton("设置置顶", 128, 112, 233, 73)
GUICtrlSetFont(-1, 42, 400, 0, "宋体")
GUICtrlSetTip(-1, "推荐项只基于部分系统优化设置方面,当然您也可以在添加")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)


Local $bOnTop = False
GUISetState()


While 1
               
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE

                        Exit                               

                Case $tab5buttonview2

                        If GUICtrlRead($tab5buttonview2) = "设置置顶" Then                                               
                                GUICtrlSetData($tab5buttonview2, "取消置顶")

       
                        ElseIf GUICtrlRead($tab5buttonview2) = "取消置顶" Then
                                GUICtrlSetData($tab5buttonview2, "设置置顶")
                                               
                               
                        EndIf

        EndSwitch

WEnd


While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case -3
                        Exit
                Case $tab5buttonview2
                        $bOnTop = Not $bOnTop
                        WinSetOnTop($Form1_, '', $bOnTop)
        EndSwitch
WEnd


;防重复运行
Func _MyProExists()
        $my_Version = "By lrcf"
        If WinExists($my_Version) Then Exit
        AutoItWinSetTitle($my_Version)
EndFunc   ;==>_MyProExists



While 1 ;基于表达式进行循环.
        $msg = GUIGetMsg() ;捕获窗口消息
        Select ;条件运行语句.
                Case $msg = $GUI_EVENT_CLOSE ;表达式

                        Exit ;终止并退出运行的脚本.

                       
        EndSelect
WEnd


 楼主| 发表于 2021-10-30 03:14:57 | 显示全部楼层
终于,测试出来了,大神们看看还有什么精简的好代码

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 0)
#Region ### START Koda GUI section ### Form=
$Form1_ = GUICreate("Form1", 617, 440, 192, 124)
$tab5buttonview2 = GUICtrlCreateButton("设置置顶", 128, 112, 233, 73)
GUICtrlSetFont(-1, 42, 400, 0, "宋体")
GUICtrlSetTip(-1, "推荐项只基于部分系统优化设置方面,当然您也可以在添加")
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)

Local $bOnTop = False
GUISetState()

While 1               
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit                               
                Case $tab5buttonview2
                        If GUICtrlRead($tab5buttonview2) = "设置置顶" Then                                               
                                GUICtrlSetData($tab5buttonview2, "取消置顶")
                        $bOnTop = Not $bOnTop
                        WinSetOnTop($Form1_, '', $bOnTop)       
                        ElseIf GUICtrlRead($tab5buttonview2) = "取消置顶" Then
                                GUICtrlSetData($tab5buttonview2, "设置置顶")                               
                        EndIf
        EndSwitch
WEnd

;防重复运行
Func _MyProExists()
        $my_Version = "By lrcf"
        If WinExists($my_Version) Then Exit
        AutoItWinSetTitle($my_Version)
EndFunc   ;==>_MyProExists

While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        Exit                        
        EndSelect
WEnd

发表于 2021-10-30 10:20:38 | 显示全部楼层
本帖最后由 862228699 于 2021-11-5 17:59 编辑
hljkwan 发表于 2021-10-30 03:14
终于,测试出来了,大神们看看还有什么精简的好代码


Opt("GUIOnEventMode", 1)
Global $bText[2] = ['窗口置顶', '取消置顶']
Global $Form1 = GUICreate($bText[0], 200, 200)
GUISetOnEvent(-3, "CLOSE")
$eButton = GUICtrlCreateButton($bText[0], 20, 50, 150, 70)
GUICtrlSetOnEvent(-1, "click")
GUISetState(@SW_SHOW)
While Sleep(10)
WEnd
Func click()
        WinSetOnTop($Form1, '', GUICtrlRead($eButton) = $bText[0])  
        GUICtrlSetData($eButton, GUICtrlRead($eButton) = $bText[0] ? $bText[1] : $bText[0])
EndFunc   ;==>click
Func CLOSE()
        Exit
EndFunc   ;==>CLOSE







发表于 2021-10-30 10:21:19 | 显示全部楼层
这种设置自身窗口的,最简单的方式通常是用复选框或菜单控件,直接以是否勾选来明示是否为该功能。
发表于 2021-10-30 10:25:31 | 显示全部楼层
Local $Form1 = GUICreate('')
Local $iCkb = GUICtrlCreateCheckbox("置顶", 320, 10, 70, 20)
GUISetState()
Local $bOnTop = False
GUISetState()

While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
                Case -3
                        Exit
                Case $iCkb
                        $bOnTop = Not $bOnTop
                        WinSetOnTop($Form1, '', $bOnTop)
        EndSwitch
WEnd
 楼主| 发表于 2021-10-30 14:19:41 | 显示全部楼层

没毛病老铁,但是不置顶
 楼主| 发表于 2021-10-30 14:20:59 | 显示全部楼层

这也是一种方式,非常感谢,昨晚一钻牛角尖给搞出来我想要的效果了,就是费点人,哈哈!
发表于 2021-11-5 18:01:30 | 显示全部楼层
hljkwan 发表于 2021-10-30 14:19
没毛病老铁,但是不置顶

加了一行。我以为你会自己加呢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 08:06 , Processed in 0.082840 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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