-----------------菜单项目控件事件-----------------[已解决]
本帖最后由 wu5cheng3 于 2011-2-4 15:43 编辑一般都用Switch...Case...EndSwitch来执行
例如
#include <GUIConstantsEx.au3>
#Include <GuiComboBoxEx.au3>
#include <Inet.au3>
#include <WindowsConstants.au3>
#include <Process.au3>
$bt = GUICreate("标题",600,500)
$cd1 = GUICtrlCreateMenu("菜单1","-1","0")
$ht = GUICtrlCreateMenuItem("画图",$cd1)
$cd2 = GUICtrlCreateMenu("菜单2","-1","1")
$jsq = GUICtrlCreateMenuItem("计算器",$cd2)
$cd3 = GUICtrlCreateMenu("菜单3","-1","2")
$jsb = GUICtrlCreateMenuItem("记事本",$cd3)
$cd4 = GUICtrlCreateMenu("菜单4","-1","3")
$lyj = GUICtrlCreateMenuItem("录音机", $cd4)
$cd5 = GUICtrlCreateMenu("菜单5","-1","4")
$xzb = GUICtrlCreateMenuItem("写字板", $cd5)
$cd6 = GUICtrlCreateMenu("菜单6")
$pmjp = GUICtrlCreateMenuItem("屏幕键盘", $cd6)
GUICtrlCreateGroup("分组控件1", 15, 410, 158, 60)
GUICtrlCreateGroup("分组控件2", 180, 410, 405, 60)
GUICtrlCreateLabel("静态标签控件1",55,435,100,16)
GUICtrlCreateLabel("静态标签控件2",350,435,100,16)
$bq1 = GUICtrlCreateTab(5, 135, 592, 270)
$bqykj1 = GUICtrlCreateTabItem("标签页1")
$bq2 = GUICtrlCreateTab(50, 135, 592, 270)
$bqykj2 = GUICtrlCreateTabItem("标签页2")
$bq3 = GUICtrlCreateTab(95, 135, 592, 270)
$bqykj3 = GUICtrlCreateTabItem("标签页3")
$bq4 = GUICtrlCreateTab(140, 135, 592, 270)
$bqykj4 = GUICtrlCreateTabItem("标签页4")
$bq5 = GUICtrlCreateTab(185, 135, 592, 270)
$bqykj5 = GUICtrlCreateTabItem("标签页5")
$bq6 = GUICtrlCreateTab(230,135,592,270)
$bqykj6 = GUICtrlCreateTabItem("标签页6")
$x = _GUICtrlComboBoxEx_Create($bt,"上下菜单控件", 40, 185, 100, 230)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch GUICtrlRead($bq1, 1)
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $ht
ShellExecute("mspaint.exe")
Case $msg = $jsq
ShellExecute("calc.exe")
Case $msg = $jsb
ShellExecute("notepad.exe")
Case $msg = $lyj
ShellExecute("sndrec32.exe")
Case $msg = $xzb
ShellExecute("wordpad.exe")
Case $msg = $pmjp
ShellExecute("osk.exe")
Case $bqykj1
ControlShow("","",$x)
Case $bqykj2
ControlHide("","",$x)
Case $bqykj3
ControlHide("","",$x)
Case $bqykj4
ControlHide("","",$x)
Case $bqykj5
ControlHide("","",$x)
Case $bqykj6
ControlHide("","",$x)
EndSwitch
WEnd
有没有办法使用 If...Then 这个语句来执行,最好使用Func ... ... EndFunc这个函数 不用在 While...WEnd里执行!~ .....
一个是分支结构,一个是条件结构.
好吧,放开不谈这些.
While 1
$msg = GUIGetMsg()
;Switch GUICtrlRead($bq1, 1)
If $msg = $GUI_EVENT_CLOSE Then
Exit
ElseIf $msg = $ht Then
ShellExecute("mspaint.exe")
ElseIf $msg = $jsq Then
ShellExecute("calc.exe")
ElseIf $msg = $jsb Then
ShellExecute("notepad.exe")
ElseIf $msg = $lyj Then
ShellExecute("sndrec32.exe")
ElseIf $msg = $xzb Then
ShellExecute("wordpad.exe")
ElseIf $msg = $pmjp Then
ShellExecute("osk.exe")
EndIf
If GUICtrlRead($bq1, 1) = $bqykj1 Then
ControlShow("", "", $x)
ElseIf GUICtrlRead($bq1, 1) = $bqykj2 Then
ControlHide("", "", $x)
ElseIf GUICtrlRead($bq1, 1) = $bqykj3 Then
ControlHide("", "", $x)
ElseIf GUICtrlRead($bq1, 1) = $bqykj4 Then
ControlHide("", "", $x)
ElseIf GUICtrlRead($bq1, 1) = $bqykj5 Then
ControlHide("", "", $x)
ElseIf GUICtrlRead($bq1, 1) = $bqykj6 Then
ControlHide("", "", $x)
EndIf
WEnd
.....
一个是分支结构,一个是条件结构.
好吧,放开不谈这些.
ceoguang 发表于 2010-12-25 00:42 http://www.autoitx.com/images/common/back.gif
能不在 while....Wend 里面执行吗? 那就用事件模式 那就用事件模式
ceoguang 发表于 2010-12-25 00:47 http://www.autoitx.com/images/common/back.gif
举个例~~~ Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 389, 255)
GUISetOnEvent(-3, "GuiEvent")
$Tab1 = GUICtrlCreateTab(40, 32, 289, 193)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Button1 = GUICtrlCreateButton("Button1", 160, 128, 75, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$Button2 = GUICtrlCreateButton("Button2", 144, 128, 75, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
GUICtrlCreateTabItem("")
GUISetState()
While 1
Sleep(100)
WEnd
Func GuiEvent()
$hwnd = @GUI_CtrlId
If $hwnd = -3 Then
Exit
ElseIf $hwnd = $Button1 Then
MsgBox(0,0,"Button1")
ElseIf $hwnd = $Button2 Then
MsgBox(0,0,"Button2")
EndIf
EndFunc
RE: -----------------菜单项控件事件-----------------
回复 6# ceoguang非常感谢斑斑的讲解!~ 学习{:face (114):}{:face (332):} 很有耐心,版主伟大 很有耐心,版主伟大 好东西呀,学习啦
页:
[1]