Jump to content
satanttin

[Solved] Help Preventing double gui

Recommended Posts

satanttin

Hello,

Hope someone could help me out. I'm trying to open a gui with a hotkey and when it's already open to not open a new one.
The code i have so far is:

HotKeySet("+z", "Note")

Func Note()
If $Note = False Then
$Note = GUICreate("Note", 633, 504, 346, 297)
$dEdit = IniRead (@ScriptDir & "\Data\Note.ini" , "Note", "Note", @error)

$Edit = GUICtrlCreateEdit("", 0, 0, 632, 503)
GUICtrlSetData($Edit, StringReplace(IniRead(@ScriptDir & "\Data\Note.ini" , "Note", "Note", @error), "{ENTER}", @CRLF))
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "NoteFunc")

ElseIf $Note = True Then
GUIDelete($Note)
EndIf
EndFunc

If i press shift + z it will open the gui and a second press deletes it but when i use it a 3th time it doesn't do anything.

So basicly want to toggle a gui with a hotkey.

Edited by satanttin

Share this post


Link to post
Share on other sites
Melba23

satanttin,

I would just hide/show the GUI like this:

#include <GUIConstantsEx.au3>

HotKeySet("+z", "Note")

$bShow = True

$Note = GUICreate("Note", 633, 504, 346, 297)
$dEdit = IniRead (@ScriptDir & "\Data\Note.ini" , "Note", "Note", @error)

$Edit = GUICtrlCreateEdit("", 0, 0, 632, 503)
GUICtrlSetData($Edit, StringReplace(IniRead(@ScriptDir & "\Data\Note.ini" , "Note", "Note", @error), "{ENTER}", @CRLF))
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd



Func Note()

    $bShow = Not $bShow

    If $bShow Then
        GUISetState(@SW_SHOW, $Note)
    Else
        GUISetState(@SW_HIDE, $Note)
    EndIf

EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
JohnOne

What Melba posted is a better way to do this, but to answer your question.

ElseIf $Note = True Then
    GUIDelete($Note)
    $Note = False
EndIf

 

Edited by JohnOne
Code was incorrect

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
satanttin

Thanks Melba23 ^^

works like a charm :3 guess i will save this piece of code if i need it in the future :)

Share this post


Link to post
Share on other sites
satanttin

Thanks for the comment JohnOne:)

Share this post


Link to post
Share on other sites

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

×