baoquocphan Posted January 17, 2014 Posted January 17, 2014 I'm using GUIOnEventMode like this (just example): Opt("GUIOnEventMode",1) $hMainForm = GUICreate( "Main form", 580, 320) $hSubFormButton = GUICtrlCreateButton( "Sub Form", 10, 10, 100, 100) GUICtrlSetOnEvent(-1,"SubForm") GUISetState(@SW_SHOW,$hMainForm) While 1 Sleep(10) WEnd ; ... Func SubForm() $hSubForm=GUICreate( "Sub Form", 100, 100) GUISetState(@SW_SHOW,$hSubForm) EndFunc But if I click "Sub Form" Button (SubForm appears) and then I click it again, a duplicate SubForm appears. I don't want a duplicate SubForm, so there is a way to solve this problem? Thanks a lot! PS: srr, I'm newbie and my English is bad
Moderators Solution Melba23 Posted January 17, 2014 Moderators Solution Posted January 17, 2014 baoquocphan,One solution would be to disable the button until the subform has been deleted:#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $hSubForm = 9999 $hMainForm = GUICreate("Main form", 580, 320) GUISetOnEvent($GUI_EVENT_CLOSE, "_Main_Exit") $hSubFormButton = GUICtrlCreateButton("Sub Form", 10, 10, 100, 100) GUICtrlSetOnEvent(-1, "SubForm") GUISetState(@SW_SHOW, $hMainForm) While 1 Sleep(10) WEnd Func SubForm() GUICtrlSetState($hSubFormButton, $GUI_DISABLE) $hSubForm = GUICreate("Sub Form", 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub_Delete") GUISetState(@SW_SHOW, $hSubForm) EndFunc ;==>SubForm Func _Sub_Delete() GUIDelete($hSubForm) $hSubForm = 9999 GUICtrlSetState($hSubFormButton, $GUI_ENABLE) EndFunc Func _Main_Exit() GUIDelete($hMainForm) Exit EndFuncPlease ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
baoquocphan Posted January 17, 2014 Author Posted January 17, 2014 baoquocphan, One solution would be to disable the button until the subform has been deleted: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $hSubForm = 9999 $hMainForm = GUICreate("Main form", 580, 320) GUISetOnEvent($GUI_EVENT_CLOSE, "_Main_Exit") $hSubFormButton = GUICtrlCreateButton("Sub Form", 10, 10, 100, 100) GUICtrlSetOnEvent(-1, "SubForm") GUISetState(@SW_SHOW, $hMainForm) While 1 Sleep(10) WEnd Func SubForm() GUICtrlSetState($hSubFormButton, $GUI_DISABLE) $hSubForm = GUICreate("Sub Form", 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "_Sub_Delete") GUISetState(@SW_SHOW, $hSubForm) EndFunc ;==>SubForm Func _Sub_Delete() GUIDelete($hSubForm) $hSubForm = 9999 GUICtrlSetState($hSubFormButton, $GUI_ENABLE) EndFunc Func _Main_Exit() GUIDelete($hMainForm) Exit EndFunc Please ask if anything is unclear. M23 Thanks, M23. Now I know the method. But I don't understand the line $hSubForm=9999 Is it use to reset the $hSubForm variable?
michaelslamet Posted January 17, 2014 Posted January 17, 2014 Thanks, M23. Now I know the method. But I don't understand the line $hSubForm=9999 Is it use to reset the $hSubForm variable? You can assign any number/string to that variable, it will work. For example, try to change it to $hSubForm="abc" it will work. But if we dont declare and assign a value on it, it will error
baoquocphan Posted January 17, 2014 Author Posted January 17, 2014 You can assign any number/string to that variable, it will work. For example, try to change it to $hSubForm="abc" it will work. But if we dont declare and assign a value on it, it will error Thank you, I've got it.
Moderators Melba23 Posted January 17, 2014 Moderators Posted January 17, 2014 baoquocphan,The $hSubForm variable is referenced in 2 separate functions - so it needs to be in Global scope so it can be seen inside both of them. See the Variables - using Global, Local, Static and ByRef tutorial in the Wiki for more information on scoping in AutoIt. When you declare Global variables to hold handles and ControlIDs it is usually a good idea to use placeholder values - leaving them blank can lead to problems when AutoIt accesses them and they have not been set. This is more likely to be true in MessageLoop mode, but it is a good habit to get into. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now