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:

  Reveal hidden contents

 

Posted

  On 1/17/2014 at 10:39 AM, Melba23 said:

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

  On 1/17/2014 at 11:42 AM, baoquocphan said:

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

  On 1/17/2014 at 11:46 AM, michaelslamet said:

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:

  Reveal hidden contents

 

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...