请教如何用GUIOnEventMode模式实现窗口按钮操作????
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 编辑 ] 那INPUT框也要用事件了。。。不然就要循环检测了。 GUISetOnEvent吗??
先试试,不行再请教:face (25): 还是不得要领,还更严重。。。。
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 GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
记得是这个,自己改下事件代码。参考下这个。
http://www.autoitx.com/forum.php?mod=viewthread&tid=3779&extra=page%3D2 谢谢叁恨,有点进展了:face (33): :face (33): 搞定后把代码放出来让大家学习学习 基本上就是这样了,测试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 编辑 ]
页:
[1]