PDA

Показать полную графическую версию : [решено] Как сделать чтобы дочернее окно при выходе не закрывало основное окно


assch
19-07-2010, 00:00
В Autoit есть пример там дочернее окно при закрытии не закрывает основное окно, но там без кнопки а кнопку на тот пример поставить мне не удалось.
Вот пример с кнопкой, при нажатии создаётся дочернее окно а при выходе оно закрывает основное.
Как сделать так чтобы оно при закрытии не закрывало основное окно?


#include <GUIConstants.au3>
Global $2
$1 = GUICreate("1")
$But = GUICtrlCreateButton("1", 50, 50, 80, 40 , $BS_FLAT)
GUISetState ()

While 1
$iMsg = GUIGetMsg()

Select

Case $iMsg = $But
Function()

Case $iMsg = $GUI_EVENT_CLOSE
Exit

EndSelect

Wend

Func Function()
$2 = GUICreate("2", 333, 333, -1, -1, -1, -1, $1)
GUISetState()
EndFunc

FlatX007
19-07-2010, 00:21
;====================================================
;============= Example of a child window ============
;====================================================
; AutoIt version: 3.0.103
; Language: English
; Author: "SlimShady"
;
; ----------------------------------------------------------------------------
; Script Start
; ----------------------------------------------------------------------------

;Include constants
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()

;Initialize variables
Local $GUIWidth = 250, $GUIHeight = 250
Local $ParentWin, $ParentWin_Pos, $ChildWin, $msg

;Create main/parent window
$ParentWin = GUICreate("Parent GUI", $GUIWidth, $GUIHeight)
;Save the position of the parent window
$ParentWin_Pos = WinGetPos($ParentWin, "")
;Show the parent window/Make the parent window visible
GUISetState(@SW_SHOW)

;Create child window and add the parameter to make it the child of the parent window
$ChildWin = GUICreate("Child GUI", $GUIWidth, $GUIHeight, $ParentWin_Pos[0] + 100, $ParentWin_Pos[1] + 100, -1, -1, $ParentWin)
;Show the child window/Make the child window visible
GUISetState(@SW_SHOW)

;Switch to the parent window
GUISwitch($ParentWin)

;Loop until:
;- user presses Esc when focused to the parent window
;- user presses Alt+F4 when focused to the parent window
;- user clicks the close button of the parent window
While 1
;After every loop check if the user clicked something in the GUI windows
$msg = GUIGetMsg(1)
Select
;Check if user clicked on a close button of any of the 2 windows
Case $msg[0] = $GUI_EVENT_CLOSE
;Check if user clicked on the close button of the child window
If $msg[1] = $ChildWin Then
MsgBox(64, "Test", "Child GUI will now close.")
;Switch to the child window
GUISwitch($ChildWin)
;Destroy the child GUI including the controls
GUIDelete()
;Check if user clicked on the close button of the parent window
ElseIf $msg[1] = $ParentWin Then
MsgBox(64, "Test", "Parent GUI will now close.")
;Switch to the parent window
GUISwitch($ParentWin)
;Destroy the parent GUI including the controls
GUIDelete()
;Exit the script
Exit
EndIf

EndSelect

WEnd
EndFunc ;==>_Main

assch
19-07-2010, 00:28
Про этот пример я и писал
Но этот пример без кнопки
А кнопку на этот пример почему то поставить проблематично

Creat0R
19-07-2010, 01:11
assch, код нужно заключать в теги [cоde].

Вот пример с кнопкой, при нажатии создаётся дочернее окно а при выходе оно закрывает основное.
Как сделать так чтобы оно при закрытии не закрывало основное окно? »

#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <ButtonConstants.au3>

Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $2

$1 = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("1")
$But = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)("1", 50, 50, 80, 40, $BS_FLAT)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)()

While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)(1)

Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg[0]
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $But
Function()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $nMsg[1] = $2 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_HIDE (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_hide), $2)
Else (http://www.autoitscript.com/autoit3/docs/keywords.htm#Else)
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) Function()
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) IsHWnd (http://www.autoitscript.com/autoit3/docs/functions/IsHWnd.htm)($2) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
$2 = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("2", 333, 333, -1, -1, -1, -1, $1)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)

GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show), $2)
WinActivate (http://www.autoitscript.com/autoit3/docs/functions/WinActivate.htm)($2)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)

FlatX007
19-07-2010, 01:18
Про этот пример я и писал »

Что то даже отдалённо не напоминает этот пример...

assch
19-07-2010, 02:11
Спасибо Creat0R




© OSzone.net 2001-2012