【已解决】窗口置顶按钮文字改变
本帖最后由 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
现在代码是点击【设置置顶】变成【取消置顶】,问题是窗口不置顶
#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
终于,测试出来了,大神们看看还有什么精简的好代码
#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
本帖最后由 862228699 于 2021-11-5 17:59 编辑
hljkwan 发表于 2021-10-30 03:14
终于,测试出来了,大神们看看还有什么精简的好代码
Opt("GUIOnEventMode", 1)
Global $bText = ['窗口置顶', '取消置顶']
Global $Form1 = GUICreate($bText, 200, 200)
GUISetOnEvent(-3, "CLOSE")
$eButton = GUICtrlCreateButton($bText, 20, 50, 150, 70)
GUICtrlSetOnEvent(-1, "click")
GUISetState(@SW_SHOW)
While Sleep(10)
WEnd
Func click()
WinSetOnTop($Form1, '', GUICtrlRead($eButton) = $bText)
GUICtrlSetData($eButton, GUICtrlRead($eButton) = $bText ? $bText : $bText)
EndFunc ;==>click
Func CLOSE()
Exit
EndFunc ;==>CLOSE
这种设置自身窗口的,最简单的方式通常是用复选框或菜单控件,直接以是否勾选来明示是否为该功能。 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 862228699 发表于 2021-10-30 10:20
没毛病老铁,但是不置顶 afan 发表于 2021-10-30 10:25
这也是一种方式,非常感谢,昨晚一钻牛角尖给搞出来我想要的效果了,就是费点人,哈哈! hljkwan 发表于 2021-10-30 14:19
没毛病老铁,但是不置顶
加了一行。我以为你会自己加呢:face (10):
页:
[1]