Jump to content

Any way to create a button/input inside a function, while keeping the main gui's while functioning?


CrewXp
 Share

Recommended Posts

Hey, I have a GUI, and at the top of the Gui, I have 5 buttons going across, which after clicking on, changes those buttons into different buttons with different events. I click the back button I created, it hides the different buttons and shows the old buttons.

Well my question is...

I'm trying to have one of those sub-buttons at the top triggering a function. Then the function creates an input in my GUI, as well as an 'OK' button that reads the data after hitting it, then saving it in a variable.

But I don't want to create another while, because then it disrupts my Main GUI's while loop (this dis-allowing me to use the top buttons after triggering the function). And I would also like to click on any other button at the top to trigger whatever that button does.

The code's really long, so here is the main idea

#include <GUIConstants.au3>

Opt("TrayOnEventMode",1)
MainGui()

Func MainGui()
$maingui=GuiCreate("MyKit",240,180)
Draw()
EnableMain()
GuiSetState(@SW_SHOW)
While 1
$msg=GuiGetMsg()
    
    If $msg = $1networkpkg Then Blank()
    If $msg = $2links Then Blank()
    If $msg = $3misc Then Misc()
    If $msg = $4download Then Blank()
    If $msg = $5about Then Blank()
    If $msg = $6close Then GuiSetState(@SW_HIDE,$maingui);ExitLoop
    If $msg = $6back Then EnableMain()
    If $msg = $1login Then INPUTBUTTON()
    If $msg = $2chat Then Blank()
    If $msg = $3lockscreen Then Blank()
    If $msg = $4settings Then Blank()
    If $msg = $5more Then Blank()
    If $msg = $6back Then EnableMain()
WEnd
GuiDelete()
EndFunc

Func Draw()
GLOBAL $1login = GUICtrlCreateButton ("Login", 0,0,40,40,$BS_ICON)
GLOBAL $2chat = GUICtrlCreateButton ("Chat", 40,00,40,40,$BS_ICON)
GLOBAL $3lockscreen = GUICtrlCreateButton ("Power Lock", 80,00,40,40,$BS_ICON)
GLOBAL $4settings = GUICtrlCreateButton ("Settings", 120,0,40,40,$BS_ICON)
GLOBAL $5more = GUICtrlCreateButton ("More", 160,0,40,40,$BS_ICON)
GLOBAL $6back = GUICtrlCreateButton ("Back", 200,0,40,40,$BS_ICON)
;
GLOBAL $1networkpkg = GUICtrlCreateButton ("xHome Management", 0,0,40,40,$BS_ICON)
GLOBAL $2links = GUICtrlCreateButton ("Links", 40,00,40,40,$BS_ICON)
GLOBAL $3misc = GUICtrlCreateButton ("Misc", 80,00,40,40,$BS_ICON)
GLOBAL $4download = GUICtrlCreateButton ("Send To Tray", 120,0,40,40,$BS_ICON)
GLOBAL $5about = GUICtrlCreateButton ("About", 160,0,40,40,$BS_ICON)
GLOBAL $6close = GUICtrlCreateButton ("Close", 200,0,40,40,$BS_ICON)


EndFunc

Func EnableMain()
GUICtrlSetState( $1login, $GUI_HIDE)
GUICtrlSetState( $2chat, $GUI_HIDE)
GUICtrlSetState( $3lockscreen, $GUI_HIDE)
GUICtrlSetState( $4settings, $GUI_HIDE)
GUICtrlSetState( $5more, $GUI_HIDE)
GUICtrlSetState( $6back, $GUI_HIDE)
GUICtrlSetState( $1networkpkg, $GUI_SHOW)
GUICtrlSetState( $2links, $GUI_SHOW)
GUICtrlSetState( $3misc, $GUI_SHOW)
GUICtrlSetState( $4download, $GUI_SHOW)
GUICtrlSetState( $5about, $GUI_SHOW)
GUICtrlSetState( $6close, $GUI_SHOW)
EndFunc

Func Blank()
    Msgbox(4096,"CrewKit","This Function is not yet available. Check back for future updates")
EndFunc

Func Misc()
GUICtrlSetState( $1networkpkg, $GUI_HIDE)
GUICtrlSetState( $2links, $GUI_HIDE)
GUICtrlSetState( $3misc, $GUI_HIDE)
GUICtrlSetState( $4download, $GUI_HIDE)
GUICtrlSetState( $5about, $GUI_HIDE)
GUICtrlSetState( $6close, $GUI_HIDE)
GUICtrlSetState( $1login, $GUI_SHOW)
GUICtrlSetState( $2chat, $GUI_SHOW)
GUICtrlSetState( $3lockscreen, $GUI_SHOW)
GUICtrlSetState( $4settings, $GUI_SHOW)
GUICtrlSetState( $5more, $GUI_SHOW)
GUICtrlSetState( $6back, $GUI_SHOW)
EndFunc

Func INPUTBUTTON()
;Button that reads the input box without disrupting the top buttons.
$file = GUICtrlCreateInput ( "Password :: ", 10,  100, 300, 20)
$btn = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
;Also.. if another button at the top is pressed... need to find a way to erase the input box and button... call CleanUp()???
EndFunc
Edited by CrewXp
Link to comment
Share on other sites

Hi,

No offence meant.. but Dude, the code you posted doesn't run...

First error upon trying to run:

GuiSetState(@SW_SHOW,$background)

Your Gui isn't in the variable $background......

Next error:

{If's...}

Next error same again:

{If's...}

The errors just follow 1 after the other an I havent even got to the point of your Gui actually loading..

Could you provide an example that I can run then I can look at the error your trying to fix.

Should I rewrite your code so I can debug?

Cheers

Link to comment
Share on other sites

eh...

"The code's really long, so here is the main idea"

it wasn't meant to be the full code. my full code is about 30 pages long. Each button along the top has sub-buttons, and so forth...

I just wrote a basic idea.... The {}'s are my pseudo-code.

Edit:

sigh.. took a while.. but it's shortened without all the functions and side stuff.... This is a basic working program

And also... I need to find a way to get rid of the inputbox and button if another main button (the ones at the top) are pressed, that i can run in EnableMain()..

like...

Func CleanUp()

;Deletes junk in the main area that was called from another button

EndFunc

Anywho...

I edited the above code....

post-4499-1187249380_thumb.jpg

Edited by CrewXp
Link to comment
Share on other sites

Declare the $Btn variable before creating the button, this way when you assign a Ctrl ID to the variable it will work in your loop...

Sorry about the changes , but it's still the same thing.

#include <GUIConstants.au3>

Opt("TrayOnEventMode",1)

Global $Button[13], $x, $file, $btn = 1
Global $SPN = StringSplit("xHome Management|Links|Misc|Send To Tray|About|Close|Login|Chat|" & _
                            "Power Lock|Settings|More|Back", "|")

MainGui()

Func MainGui()
    $MainGui=GuiCreate("MyKit",240,180)
    For $b = 1 To 12
        If $b = 7 Then $x = 0
        $Button[$b] = GUICtrlCreateButton ($SPN[$b], $x, 0, 40, 40,$BS_ICON)
        GUICtrlSetTip(-1, $SPN[$b])
        If $b >= 7 Then GUICtrlSetState(-1, $GUI_HIDE + $GUI_DISABLE)
        $x += 40
    Next
    GUISetState(@SW_SHOW)
    
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button[6] ; Exit/ Close
            ExitLoop
            Case $msg = $Button[1] ;xHome Management
                Blank()
            Case $msg = $Button[2] ;Links
                Blank()
            Case $msg = $Button[3] ;Misc
                DisableMain()
            Case $msg = $Button[4] ;Send To Tray            
                Blank()
            Case $msg = $Button[5] ;About
                Blank()
            Case $msg = $Button[7] ;Login
                INPUTBUTTON()
            Case $msg = $Button[8] ;Chat            
                Blank()
            Case $msg = $Button[9] ;Power Lock
                Blank()
            Case $msg = $Button[10] ;Settings
                Blank()
            Case $msg = $Button[11] ;More
                Blank()
            Case $msg = $Button[12] ;Back       
                EnableMain()
            Case $msg = $btn ; Declare the btn
                MsgBox(0,"Password Entered Was..", GUICtrlRead($file))
                GUICtrlDelete($file)
                GUICtrlDelete($btn)
        EndSelect
    WEnd
EndFunc

Func EnableMain()
    For $b = 1 To 6
        GUICtrlSetState($Button[$b], $GUI_ENABLE + $GUI_SHOW)
        GUICtrlSetState($Button[$b + 6], $GUI_HIDE + $GUI_DISABLE)
    Next    
EndFunc

Func DisableMain()
    For $b = 1 To 6
        GUICtrlSetState($Button[$b], $GUI_HIDE + $GUI_DISABLE)
        GUICtrlSetState($Button[$b + 6], $GUI_ENABLE + $GUI_SHOW)
    Next    
EndFunc

Func Blank()
    Msgbox(4096,"CrewKit","This Function is not yet available. Check back for future updates")
EndFunc

Func INPUTBUTTON()
;Button that reads the input box without disrupting the top buttons.
$file = GUICtrlCreateInput ( "Password :: ", 10,  100, 220, 20)
$btn = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
;Also.. if another button at the top is pressed... need to find a way to erase the input box and button... call CleanUp()???
EndFunc

Cheers

Link to comment
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
 Share

  • Recently Browsing   0 members

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