找回密码
 加入
搜索
查看: 4123|回复: 7

[GUI管理] 求助:与radio相关的$GUI_DISABLE问题

  [复制链接]
发表于 2010-6-4 14:06:41 | 显示全部楼层 |阅读模式
希望在选中某个radio的时候菜显示与其相关的内容,不选中的时候是disable的,代码如下:
$Group1 = GUICtrlCreateGroup("", 200, 56, 385, 41)
$Radio1 = GUICtrlCreateRadio("1111", 224, 72, 97, 17)
$Radio2 = GUICtrlCreateRadio("2222", 384, 72, 113, 17)
$Combo1 = GUICtrlCreateCombo("", 336, 160, 169, 25)
$Button1 = GUICtrlCreateButton("Button1", 512, 160, 57, 25, 0)

$Combo3 = GUICtrlCreateCombo("", 208, 216, 281, 25)
$Button2 = GUICtrlCreateButton("Button2 ", 504, 216, 81, 25, 0)

If BitAND(GUICtrlRead($Radio2), $GUI_UNCHECKED) = $GUI_UNCHECKED Then
        GUICtrlSetState($Combo1,$GUI_DISABLE)
        GUICtrlSetState($Button1,$GUI_DISABLE)
ElseIf BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($Combo1,$GUI_ENABLE)
        GUICtrlSetState($Button1,$GUI_ENABLE)
        EndIf
Do
$nMsg = GUIGetMsg()
       
select
Case  $nMsg=$Button1                       
msgbox(1,"","button1")               
Case  $nMsg=$Button2
msgbox(1,"","button2")               
EndSelect
               
Until $nMsg=$GUI_EVENT_CLOSE
期望的结果是radio2选中的时候,Combo1 和Button1 才是enabled状态,否则是灰色的
写了判断语句,但是不起效果
发表于 2010-6-5 00:42:06 | 显示全部楼层
判断部分放在循环外了 当然没效果了
发表于 2010-6-5 01:55:10 | 显示全部楼层
本帖最后由 netegg 于 2010-6-5 01:57 编辑

BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED这句什么意思,貌似不加等号后面的吧
sxd说的也是一方面
发表于 2010-6-5 13:25:33 | 显示全部楼层



关键思路:AdlibRegister注册一个Adlib 函数监控Radio,根据情况修改Combo和Button的控件状态
#include <GUIConstantsEx.au3>
GUICreate("与radio相关的$GUI_DISABLE问题",600, 300)
$Group1 = GUICtrlCreateGroup("", 200, 56, 385, 41)
$Radio1 = GUICtrlCreateRadio("隐藏", 224, 72, 97, 17)
$Radio2 = GUICtrlCreateRadio("显示", 384, 72, 113, 17)
$Combo1 = GUICtrlCreateCombo("1", 208, 160, 281, 25)
$Button1 = GUICtrlCreateButton("Button1", 504, 160, 81, 25)
$Combo3 = GUICtrlCreateCombo("2", 208, 216, 281, 25)
$Button2 = GUICtrlCreateButton("Button2 ", 504, 216, 81, 25)
GUICtrlSetState($Combo1,$GUI_DISABLE)
GUICtrlSetState($Button1,$GUI_DISABLE)
GUISetState()
AdlibRegister("MyAdlib")
While 1 
$nMsg = GUIGetMsg()
select
Case  $nmsg = $GUI_EVENT_CLOSE
ExitLoop
Case  $nMsg=$Button1                        
msgbox(1,"","button1")                
Case  $nMsg=$Button2
msgbox(1,"","button2")                
EndSelect
WEnd
Func MyAdlib()
If GUICtrlRead($Radio2) = $GUI_UNCHECKED Then
        GUICtrlSetState($Combo1,$GUI_DISABLE)
        GUICtrlSetState($Button1,$GUI_DISABLE)
ElseIf GUICtrlRead($Radio2)= $GUI_CHECKED Then
        GUICtrlSetState($Combo1,$GUI_ENABLE)
        GUICtrlSetState($Button1,$GUI_ENABLE)
        EndIf
EndFunc

将判断语句放在while循环也可以达到监控Radio和修改Combo和Button控件状态的目的
不过
自己测试下这种思路与AdlibRegister相比有何缺点?
#include <GUIConstantsEx.au3>
GUICreate("My GUI combo",600, 300)
$Group1 = GUICtrlCreateGroup("", 200, 56, 385, 41)
$Radio1 = GUICtrlCreateRadio("1111", 224, 72, 97, 17)
$Radio2 = GUICtrlCreateRadio("2222", 384, 72, 113, 17)
$Combo1 = GUICtrlCreateCombo("1", 208, 160, 281, 25)
$Button1 = GUICtrlCreateButton("Button1", 512, 160, 57, 25)
$Combo3 = GUICtrlCreateCombo("2", 208, 216, 281, 25)
$Button2 = GUICtrlCreateButton("Button2 ", 504, 216, 81, 25)
GUISetState()

While 1
If GUICtrlRead($Radio2) = $GUI_UNCHECKED Then
GUICtrlSetState($Combo1,$GUI_DISABLE)
GUICtrlSetState($Button1,$GUI_DISABLE)
ElseIf GUICtrlRead($Radio2)= $GUI_CHECKED Then
GUICtrlSetState($Combo1,$GUI_ENABLE)
GUICtrlSetState($Button1,$GUI_ENABLE)
EndIf
$nMsg = GUIGetMsg()
select
Case $nmsg = $GUI_EVENT_CLOSE
ExitLoop
Case $nMsg=$Button1 
msgbox(1,"","button1") 
Case $nMsg=$Button2
msgbox(1,"","button2") 
EndSelect
WEnd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-6-5 16:54:26 | 显示全部楼层
我自己是选用的while ,因为只有while是实时。

再说GUI最多用几秒,不影响资源,或者把While 1的条件改为(伪代码):while @SW_SHOW.
 楼主| 发表于 2010-6-7 16:24:19 | 显示全部楼层
感谢各位的回复哦!
对于楼上的AdlibRegister()这个函数我还是不太理解,这个在help file里面没有这个函数,可以直接调用的吗?
 楼主| 发表于 2010-6-7 16:32:44 | 显示全部楼层
还有 ,当把判断部分放在循环中时,combox和button都会不停的闪烁,是为什么呀?
 楼主| 发表于 2010-6-7 16:44:28 | 显示全部楼层
把AdlibRegister()换成AdlibEnable()就可以用了,谢谢
不过对于AdlibEnable()的作用还不太了解,help file里面也没有明确说,能否麻烦各位大侠帮忙解释下?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 05:37 , Processed in 0.109142 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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