piaoa_998 发表于 2010-6-4 14:06:41

求助:与radio相关的$GUI_DISABLE问题

希望在选中某个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状态,否则是灰色的
写了判断语句,但是不起效果

sxd 发表于 2010-6-5 00:42:06

判断部分放在循环外了 当然没效果了

netegg 发表于 2010-6-5 01:55:10

本帖最后由 netegg 于 2010-6-5 01:57 编辑

BitAND(GUICtrlRead($Radio2), $GUI_CHECKED) = $GUI_CHECKED这句什么意思,貌似不加等号后面的吧
sxd说的也是一方面

lynfr8 发表于 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

republican 发表于 2010-6-5 16:54:26

我自己是选用的while ,因为只有while是实时。

再说GUI最多用几秒,不影响资源,或者把While 1的条件改为(伪代码):while @SW_SHOW.

piaoa_998 发表于 2010-6-7 16:24:19

感谢各位的回复哦!
对于楼上的AdlibRegister()这个函数我还是不太理解,这个在help file里面没有这个函数,可以直接调用的吗?

piaoa_998 发表于 2010-6-7 16:32:44

还有 ,当把判断部分放在循环中时,combox和button都会不停的闪烁,是为什么呀?

piaoa_998 发表于 2010-6-7 16:44:28

把AdlibRegister()换成AdlibEnable()就可以用了,谢谢
不过对于AdlibEnable()的作用还不太了解,help file里面也没有明确说,能否麻烦各位大侠帮忙解释下?
页: [1]
查看完整版本: 求助:与radio相关的$GUI_DISABLE问题