找回密码
 加入
搜索
查看: 2342|回复: 6

请教如何用GUIOnEventMode模式实现窗口按钮操作????

[复制链接]
发表于 2008-12-11 15:47:41 | 显示全部楼层 |阅读模式
input有输入时,button1才起作用,否则禁用
当Listview有被选中时button2,button3才有用
窗口右上角的X不起作用了
请问怎么转换成GUIOnEventMode模式的代码?
我对GUIOnEventMode还是一知半解的......谢谢啦

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
$Group1 = GUICtrlCreateGroup("1", 32, 32, 425, 89)
$Group2 = GUICtrlCreateGroup("2", 32, 144, 425, 153)
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)
$Button2 = GUICtrlCreateButton("Button1", 320, 168, 121, 25, 0)
$Button3 = GUICtrlCreateButton("Button1", 319, 217, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("数量:", 48, 64, 60, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25)
$ListView1 = GUICtrlCreateListView("1   |2   |3   |4   ", 48, 160, 258, 126)
$item1 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item2 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item3 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $Select1 = GUICtrlRead($Input1)
        If  $Select1= "" Then
                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then GUICtrlSetState($Button1, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) Then GUICtrlSetState($Button1, $GUI_ENABLE)
        EndIf
        $Select2 = GUICtrlRead($ListView1)
        If $Select2 = "" Then
                If BitAND(GUICtrlGetState($Button2), $GUI_ENABLE) Then GUICtrlSetState($Button2, $GUI_DISABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_ENABLE) Then GUICtrlSetState($Button3, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button2), $GUI_DISABLE) Then GUICtrlSetState($Button2, $GUI_ENABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_DISABLE) Then GUICtrlSetState($Button3, $GUI_ENABLE)
        EndIf
        
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd




[ 本帖最后由 waynelue 于 2008-12-12 00:48 编辑 ]

本帖子中包含更多资源

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

×
发表于 2008-12-11 18:16:15 | 显示全部楼层
那INPUT框也要用事件了。。。不然就要循环检测了。
 楼主| 发表于 2008-12-11 18:20:57 | 显示全部楼层
GUISetOnEvent吗??
先试试,不行再请教
 楼主| 发表于 2008-12-11 19:02:32 | 显示全部楼层
还是不得要领,还更严重。。。。
shanhen给个提示吧。。。我可能钻到牛角尖里去了
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
$Group1 = GUICtrlCreateGroup("1", 32, 32, 425, 89)
$Group2 = GUICtrlCreateGroup("2", 32, 144, 425, 153)
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)
$Button2 = GUICtrlCreateButton("Button1", 320, 168, 121, 25, 0)
$Button3 = GUICtrlCreateButton("Button1", 319, 217, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("数量:", 48, 64, 60, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25)
$ListView1 = GUICtrlCreateListView("1   |2   |3   |4   ", 48, 160, 258, 126)
$item1 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item2 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item3 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($Button1, "test")
GUISetOnEvent($Button2, "test")
GUISetOnEvent($Button2, "test")
GUISetOnEvent($Input1, "test")
GUISetOnEvent($ListView1, "test")

While 1
        Sleep(1000)
WEnd

Func test()
While 1
        $Select1 = GUICtrlRead($Input1)
        If  $Select1= "" Then
                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then GUICtrlSetState($Button1, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) Then GUICtrlSetState($Button1, $GUI_ENABLE)
        EndIf
        $Select2 = GUICtrlRead($ListView1)
        If $Select2 = "" Then
                If BitAND(GUICtrlGetState($Button2), $GUI_ENABLE) Then GUICtrlSetState($Button2, $GUI_DISABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_ENABLE) Then GUICtrlSetState($Button3, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button2), $GUI_DISABLE) Then GUICtrlSetState($Button2, $GUI_ENABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_DISABLE) Then GUICtrlSetState($Button3, $GUI_ENABLE)
        EndIf
        
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
EndFunc
发表于 2008-12-11 19:36:59 | 显示全部楼层
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
   
记得是这个,自己改下事件代码。参考下这个。
http://www.autoitx.com/forum.php ... &extra=page%3D2
 楼主| 发表于 2008-12-11 23:38:48 | 显示全部楼层
谢谢叁恨,有点进展了 搞定后把代码放出来让大家学习学习
 楼主| 发表于 2008-12-12 00:40:10 | 显示全部楼层
基本上就是这样了,测试OK,终于可以睡觉了
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)

Global Const $WM_NOTIFY = 0x004E
Global Const $WM_CTLCOLOREDIT = 0x0133

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")

$Group1 = GUICtrlCreateGroup("1", 32, 32, 425, 89)
$Group2 = GUICtrlCreateGroup("2", 32, 144, 425, 153)
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)
$Button2 = GUICtrlCreateButton("Button2", 320, 168, 121, 25, 0)
$Button3 = GUICtrlCreateButton("Button3", 319, 217, 121, 25, 0)

$Label1 = GUICtrlCreateLabel("数量:", 48, 64, 60, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25)
$ListView1 = GUICtrlCreateListView("1   |2   |3   |4   ", 48, 160, 258, 126)
$item1 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item2 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
$item3 = GUICtrlCreateListViewItem("1   |2   |3   |4   ",$ListView1)
GUISetState()
#EndRegion ### END Koda GUI section ###

GUICtrlSetOnEvent($Button1, "main")
GUICtrlSetOnEvent($Button2, "main")
GUICtrlSetOnEvent($Button3, "main")

GUIRegisterMsg($WM_NOTIFY, "test")
GUIRegisterMsg($WM_CTLCOLOREDIT, "test")

$getfocus=ControlFocus ( "Form1", "", $Input1)


While 1
        Sleep(1000)
WEnd

Func main()

        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0,"","button1")
                Case $Button2
                        MsgBox(0,"","button2")
                Case $Button3
                        MsgBox(0,"","button3")
                        
        EndSwitch
                
EndFunc
        
Func test()
        $Select1 = GUICtrlRead($Input1)
        If  $Select1= "" Then
                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then GUICtrlSetState($Button1, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) Then GUICtrlSetState($Button1, $GUI_ENABLE)
        EndIf
        $Select2 = GUICtrlRead($ListView1)
        If $Select2 = "" Then
                If BitAND(GUICtrlGetState($Button2), $GUI_ENABLE) Then GUICtrlSetState($Button2, $GUI_DISABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_ENABLE) Then GUICtrlSetState($Button3, $GUI_DISABLE)
        Else
                If BitAND(GUICtrlGetState($Button2), $GUI_DISABLE) Then GUICtrlSetState($Button2, $GUI_ENABLE)
                If BitAND(GUICtrlGetState($Button3), $GUI_DISABLE) Then GUICtrlSetState($Button3, $GUI_ENABLE)
        EndIf                
EndFunc


不过头文件要是加上
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
的话会出错如下图之类的

[ 本帖最后由 waynelue 于 2008-12-12 00:47 编辑 ]

本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 04:46 , Processed in 0.074280 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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