Jump to content

Recommended Posts

Posted

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
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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?

Posted

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

Posted

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
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...