GUI事件之父窗口-生动的例子[已解决]
本帖最后由 Huiseyu 于 2015-9-15 18:53 编辑有三个窗口,不知道怎么关掉其中一个。GUI还是没搞懂。{:face (197):}$hGUI = GUICreate('GUI-MAIN' ,250,300 ,Default ,Default ,0x10070000)
$oGUI = GUICreate('windows1' ,200,150 ,-250 ,Default ,0x10070000 ,0x0000040 ,$hGUI)
$iGUI = GUICreate('windows2' ,200,150 ,250 ,Default ,0x10070000 ,0x0000040 ,$oGUI)
While 1
If GUIGetMsg($hGUI) = -3 then Exit ;退出
If GUIGetMsg($oGUI) = -3 then GUIDelete($oGUI) ;关掉 $oGUI ,这个不会
If GUIGetMsg($iGUI) = -3 then GUIDelete($iGUI) ;关掉 $iGUI ,......
WEnd
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('GUI-MAIN', 250, 300, Default, Default, 0x10070000)
$b1 = GUICtrlCreateButton('window1', 20, 50)
$b2 = GUICtrlCreateButton('window2', 150, 50)
GUISetState()
While 1
$msg = GUIGetMsg(1)
If Not IsArray($msg) Then ContinueLoop
Switch $msg
Case -3
If $msg = $hGUI Then
Exit
ElseIf $msg = $hGUI1 Then
GUIDelete($hGUI1)
$hGUI1 = -1
ElseIf $msg = $hGUI2 Then
GUIDelete($hGUI2)
$hGUI2 = -1
EndIf
Case $b1
If $hGUI1 = -1 Then
$hGUI1 = GUICreate('windows1', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
Else
WinActivate($hGUI1)
EndIf
Case $b2
If $hGUI2 = -1 Then
$hGUI2 = GUICreate('windows2', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
Else
WinActivate($hGUI2)
EndIf
EndSwitch
WEnd 用事件模式,更一目了然Opt('guioneventmode', 1)
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('GUI-MAIN', 250, 300, Default, Default, 0x10070000)
GUISetOnEvent(-3, '_exit')
$b1 = GUICtrlCreateButton('window1', 20, 50)
GUICtrlSetOnEvent(-1, '_hGui1')
$b2 = GUICtrlCreateButton('window2', 150, 50)
GUICtrlSetOnEvent(-1, '_hGui2')
GUISetState()
While 1
Sleep(100)
WEnd
Func _exit()
Exit
EndFunc
Func _hGui1()
If $hGUI1 = -1 Then
$hGUI1 = GUICreate('windows1', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
GUISetOnEvent(-3, '_del_gui1')
Else
WinActivate($hGUI1)
EndIf
EndFunc ;==>_hGui1
Func _hGui2()
If $hGUI2 = -1 Then
$hGUI2 = GUICreate('windows2', 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI)
GUISetOnEvent(-3, '_del_gui2')
Else
WinActivate($hGUI2)
EndIf
EndFunc ;==>_hGui2
Func _del_gui1()
GUIDelete($hGUI1)
$hGUI1 = -1
EndFunc ;==>_del_gui1
Func _del_gui2()
GUIDelete($hGUI2)
$hGUI2 = -1
EndFunc ;==>_del_gui2 嫌3楼函数过多太散乱,可以整合一下。Opt('guioneventmode', 1)
Local $hGUI1 = -1, $hGUI2 = -1
$hGUI = GUICreate('主窗口', 250, 300, Default, Default, 0x10070000)
GUISetOnEvent(-3, '_exit')
$b1 = GUICtrlCreateButton('子窗口1', 20, 50)
GUICtrlSetOnEvent(-1, '_c_c_windows')
$b2 = GUICtrlCreateButton('子窗口2', 150, 50)
GUICtrlSetOnEvent(-1, '_c_c_windows')
GUISetState()
While 1
Sleep(100)
WEnd
Func _exit()
Switch @GUI_WinHandle
Case $hGUI
Exit
Case $hGUI1
GUIDelete($hGUI1)
$hGUI1 = -1
Case $hGUI2
GUIDelete($hGUI2)
$hGUI2 = -1
EndSwitch
EndFunc
Func _c_c_windows()
Local $i = @GUI_CtrlId - 2
If Eval('hGUI' & $i) = -1 Then
Assign('hGUI' & $i, GUICreate('子窗口' & $i, 200, 150, -250, Default, 0x10070000, 0x0000040, $hGUI))
GUISetOnEvent(-3, '_exit')
Else
WinActivate(Eval('hGUI' & $i))
EndIf
EndFunc 嫌3楼函数过多太散乱,可以整合一下。
Alam 发表于 2015-9-14 21:56 http://www.autoitx.com/images/common/back.gif
完爆解决+收藏。。。{:face (356):},谢谢这么多生动的例子,非常感谢。
页:
[1]