如何触发combo的选择事件
本帖最后由 sky808 于 2010-1-18 19:10 编辑我希望在单击选中某下拉菜单时触发事件应该怎样实现呢
是否需要做一个消息循环来case呢
多谢!!! GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $IdFrom, $iCode
$IdFrom = BitAnd($wParam, 0x0000FFFF)
$iCode = BitShift($wParam, 16)
Switch $iCode
Case 1
Switch $IdFrom
Case $Combo804
........
EndSwitch
EndSwitch
endfunc 多谢了.
在我这里无法运行,是否有什么头文件未包含呢? 把问题说清楚啊,未能运行,具体什么错误啊,$WM_COMMAND未定义? 对的,提示变量未声明.
Line 2(File "E:\Click.au3"):
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg(^ ERROR
Error: 变量没有在开始声明. 可以INLUDE WindowsConstants.au3这个文件
或者直接定义 $WM_COMMAND = 0x0111 不知道怎样用呢
我是希望在单击下拉菜单时就消息提示那种.
简单的修改了下,麻烦你看看该如何修改.
未能完全理解其含义,麻烦帮忙改正.
#Include <GUIConstants.au3>
#Include <StaticConstants.au3>
#Include <GuiListBox.au3>
#Include <GUIComboBox.au3>
GUICreate("hello",200,100)
$Combo=GUICtrlCreateCombo("",10,10)
GUICtrlSetData($Combo,"item1|item2|item3")
guisetstate()
While 1
GUIRegisterMsg($Combo,"WM_COMMAND")
if GUIGetMsg()=$GUI_EVENT_CLOSE Then Exit
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $IdFrom, $iCode
$IdFrom = BitAnd($wParam, 0x0000FFFF)
$iCode = BitShift($wParam, 16)
Switch $iCode
Case 1
msgbox(0,"ok","1")
Switch $IdFrom
Case $Combo804
msgbox(0,"ok","2")
EndSwitch
EndSwitch
endfunc
上述例子中当我单击下拉菜单的item2时自动调用msgbox()函数。
多谢! #Include <GUIConstants.au3>
#Include <StaticConstants.au3>
#Include <GuiListBox.au3>
#Include <GUIComboBox.au3>
GUICreate("hello",200,100)
$Combo=GUICtrlCreateCombo("",10,10,160,20)
GUICtrlSetData($Combo,"item1|item2|item3")
guisetstate()
GUIRegisterMsg(0x0111,"WM_COMMAND")
While 1
Sleep(50)
if GUIGetMsg()=$GUI_EVENT_CLOSE Then Exit
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $IdFrom, $iCode
$IdFrom = BitAnd($wParam, 0x0000FFFF)
$iCode = BitShift($wParam, 16)
Switch $iCode
Case 1
Switch $IdFrom
Case $Combo
$thesel=_GUICtrlComboBox_GetCurSel($Combo)
If $thesel=0 Then
MsgBox(0,"","选择了第一个哦")
ElseIf $thesel=1 Then
MsgBox(0,"","选择了第二个哦")
ElseIf $thesel=2 Then
MsgBox(0,"","选择了第三个哦")
EndIf
EndSwitch
EndSwitch
endfunc
本帖最后由 afan 于 2010-1-18 18:47 编辑
GUICreate("hello", 200, 100)
$Combo = GUICtrlCreateCombo("", 10, 10, 160, 20)
GUICtrlSetData($Combo, "item1|item2|item3")
GUISetState()
GUIRegisterMsg(0x0111, "WM_COMMAND")
While 1
If GUIGetMsg() = -3 Then Exit
WEnd
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $IdFrom, $iCode
$IdFrom = BitAND($wParam, 0x0000FFFF)
$iCode = BitShift($wParam, 16)
If $iCode = 1 Then
If $IdFrom = $Combo Then
MsgBox(0, "", GUICtrlRead($Combo))
EndIf
EndIf
EndFunc ;==>WM_COMMAND貌似会实用点~ 感谢楼上的两位朋友! 不用这么麻烦吧?把 $combo当按钮用就好了
#Include <GUIConstants.au3>
GUICreate("hello",200,100)
$Combo=GUICtrlCreateCombo("",10,10,160,20)
GUICtrlSetData($Combo,"item1|item2|item3")
guisetstate()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo
MsgBox (0,"","你选择了:"&GUICtrlRead ($Combo))
EndSwitch
WEnd
嘿嘿,真的哎,很管用哦
学习了。。不过我用不大上,我一般用事件模式的 回复 12# llztt
呵呵,我也是用事件模式的,这个事件模式也可以用。
#Include <GUIConstants.au3>
opt ("GUIOnEventMode",1)
GUICreate("hello",200,100)
GUISetOnEvent ($GUI_EVENT_CLOSE,"_exit")
$Combo=GUICtrlCreateCombo("",10,10,160,20)
GUICtrlSetOnEvent(-1,"click_combo")
GUICtrlSetData($Combo,"item1|item2|item3")
guisetstate()
While 1
sleep (1000)
WEnd
Func click_combo ()
MsgBox (0,"","你选择了:"&GUICtrlRead ($Combo))
EndFunc
Func _exit ()
Exit
EndFunc
厉害。。。。。。。。 还是不怎么懂事件,学习下
页:
[1]
2