找回密码
 加入
搜索
查看: 4334|回复: 10

[AU3基础] -----------------菜单项目控件事件-----------------[已解决]

  [复制链接]
发表于 2010-12-25 00:29:45 | 显示全部楼层 |阅读模式
本帖最后由 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  里执行!~
发表于 2010-12-25 00:42:45 | 显示全部楼层
.....
一个是分支结构,一个是条件结构.
好吧,放开不谈这些.

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
 楼主| 发表于 2010-12-25 00:45:20 | 显示全部楼层
.....
一个是分支结构,一个是条件结构.
好吧,放开不谈这些.
ceoguang 发表于 2010-12-25 00:42



   

能不在   while....Wend    里面执行吗?
发表于 2010-12-25 00:47:26 | 显示全部楼层
那就用事件模式
 楼主| 发表于 2010-12-25 00:49:05 | 显示全部楼层
那就用事件模式
ceoguang 发表于 2010-12-25 00:47






举个例~~~
发表于 2010-12-25 01:02:49 | 显示全部楼层
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
 楼主| 发表于 2010-12-25 13:02:08 | 显示全部楼层

RE: -----------------菜单项控件事件-----------------

回复 6# ceoguang




非常感谢斑斑的讲解!~
发表于 2011-3-7 20:52:11 | 显示全部楼层
学习
发表于 2011-3-7 21:56:54 | 显示全部楼层
很有耐心,版主伟大
发表于 2011-3-26 13:38:49 | 显示全部楼层
很有耐心,版主伟大
发表于 2011-7-7 10:08:52 | 显示全部楼层
好东西呀,学习啦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-1 23:33 , Processed in 0.084414 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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