Modify

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#3549 closed Bug (Rejected)

GUI Reference - OnEvent Mode: missing include in code sample

Reported by: nnovich-OK@… Owned by:
Milestone: Component: Documentation
Version: 3.3.14.2 Severity: None
Keywords: Cc:

Description

Section: GUI Reference
Article: GUI OnEvent Mode
Topic: Advanced Operations and Multiple Windows

Code snippet doesn't contain "#include <MsgBoxConstants.au3>", so script complains on not defined "$MB_OK".

Small optional suggestion for this section: making "dummy" window visible and not overlapped with main window is more illustrative and gives chance to experiment with closing both windows. So I would add additional call to GUISetState(@SW_SHOW) before switching to main window and correct initial coordinates of dummy window. This part is IMHO, so feel free to ignore, while code snippet must work properly to not frighten newcomers such as me.

Attachments (0)

Change History (3)

comment:1 by J-Paul Mesnage, 9 years ago

Thanks

just post what what you optional suggestion can be

comment:2 by J-Paul Mesnage, 8 years ago

Resolution: Rejected
Status: newclosed

closed as no info supplied

comment:3 by mLipok, 8 years ago

I think @OP mean that "Dummy GUI for testing" should be visible to be able to test anything.

Here is my proposal:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $hMainGUI, $hDummyGUI
_Example()
Func _Example()
	$hMainGUI = GUICreate("Hello World", 300, 100)
	GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
	GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
	Local $iOKButton = GUICtrlCreateButton("OK", 70, 50, 60)
	GUISetState(@SW_SHOW) ; show $hMainGUI

	; GUICtrlSetOnEvent is related to desired ControlID
	GUICtrlSetOnEvent($iOKButton, "OKButton")

	$hDummyGUI = GUICreate("Dummy GUI for testing", 300, 100, 200)
	GUISetState(@SW_SHOW) ; show $hDummyGUI

	; GUISetOnEvent is not related to specyfic GUI
	GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")

	While 1
		Sleep(10) ; Sleep to reduce CPU usage
	WEnd
EndFunc   ;==>_Example

Func OKButton()
	; Note: At this point @GUI_CtrlId would equal $iOKButton
	MsgBox($MB_OK, "GUI Event", "You selected OK!")
EndFunc   ;==>OKButton

Func CLOSEButton()
	; Note: at this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE,
	; @GUI_WinHandle will be either $hMainGUI or $hDummyGUI
	If @GUI_WinHandle = $hMainGUI Then
		MsgBox($MB_OK, "GUI Event", "You selected CLOSE in the main window! Exiting...")
		Exit
	EndIf
EndFunc   ;==>CLOSEButton

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.