Opened 7 years ago

Closed 6 years ago

Last modified 6 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: Severity: None
Keywords: Cc:


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 Changed 6 years ago by Jpm


just post what what you optional suggestion can be

comment:2 Changed 6 years ago by Jpm

  • Resolution set to Rejected
  • Status changed from new to closed

closed as no info supplied

comment:3 Changed 6 years ago by mLipok

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
Func _Example()
	$hMainGUI = GUICreate("Hello World", 300, 100)
	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

	While 1
		Sleep(10) ; Sleep to reduce CPU usage
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...")
EndFunc   ;==>CLOSEButton

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.