Jump to content

[Solved] Looking for a smarter way to make a gui


Recommended Posts

Hi everyone,

I'm trying to make a menu which changes with the icons at the bottom of the gui, as in it changes "pages" my idea was simple, i would delete everything from the old page and make a new one with differnt stuff on it, how ever. I've run in to a problem with trying to make buttons on differnt pages, it will run them because the button does not yet exsist.

I've added a zip file with the script and all the pictures so the script won't fail all to horribly

Does anyone have a smart idea on how to make this work? or a work around? or in general just improve my coding? any help is very appreciated!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GUIListBox.au3>




Global Const $SC_DRAGMOVE = 0xF012
Global $icn_dll = @ScriptDir & "\hat.dll"
global $Printerlist, $Brugernavnstext, $Brugernavn, $kodeordstext, $PasswordEdit, $Networktext, $Combo1, $Button1, $BClose, $BAddPrinter
global $Drive1, $Drive1text, $Drive2, $Drive2text, $Drive3, $Drive3text, $Drive4, $Drive4text, $Drive5, $Drive5text, $Drive6, $Drive6text


$Th1 = GUICreate("Th 3.0.0", 220, 320, 429, 285,BitOR($WS_POPUP,$WS_BORDER))
$Label1 = GUICtrlCreateLabel("Th 3.0.0", 5, 5, 160, 25)
GUICtrlSetFont($Label1, 14, 1400, 0, "Verdana")
GUICtrlSetColor($Label1, 0xFFFFFF)
;~ GUICtrlCreateGraphic(0, 30, 600, 3)
;~ GUICtrlSetBkColor(-1, 0xFFFFFF)
;~ GUICtrlCreateGraphic(0, 270, 300, 2)
;~ GUICtrlSetBkColor(-1, 0xFFFFFF)
GUISetBkColor(0x333333)




$Label2 = GUICtrlCreateLabel("X", 205, 5, 130, 25)
GUICtrlSetFont($Label2, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Label2, 0xffffff)


$Icon0 = GUICtrlCreatePic("lock2.jpg", 15, 280, 32, 32)
$Icon1 = GUICtrlCreatePic("print.jpg", 55, 280, 32, 32)
$Icon2 = GUICtrlCreatePic("disk.jpg", 95, 280, 32, 32)
$Icon3 = GUICtrlCreatePic("link.jpg", 135, 280, 32, 32)
$Icon5 = GUICtrlCreatePic("indstillinger.jpg", 175, 280, 32, 32)

GUICtrlSetTip($Icon0, "Login")
GUICtrlSetTip($Icon1, "Tilføj printer")
GUICtrlSetTip($Icon2, "Tilføj drev")
GUICtrlSetTip($Icon3, "Links")
GUICtrlSetTip($Icon5, "Indstillingere")

GUICtrlSetCursor($Icon0, 0)
GUICtrlSetCursor($Icon1, 0)
GUICtrlSetCursor($Icon2, 0)
GUICtrlSetCursor($Icon3, 0)
GUICtrlSetCursor($Icon5, 0)

_Logingui()

$img_top_and_bottom = GUICtrlCreatePic(@ScriptDir & "\top and bottom.bmp", 0, 0, 600, 30, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
$img_top = GUICtrlCreatePic(@ScriptDir & "\top bar.jpg", 0, 30, 600, 12, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
$img_low = GUICtrlCreatePic(@ScriptDir & "\low bar.jpg", 0, 270, 600, 12, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $BClose, $Label2;, $Close
Exit
Case $GUI_EVENT_PRIMARYDOWN
_SendMessage($Th1, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
Case $Icon0
_Cleargui()
GUICtrlSetImage($Icon0, "lock2.jpg", 8)
_Logingui()
Case $Icon1
_Cleargui()
GUICtrlSetImage($Icon1, "print2.jpg", 8)
_Printgui()
Case $Icon2
_Cleargui()
GUICtrlSetImage($Icon2, "disk2.jpg", 8)
_Drevgui()
Case $Icon3
_Cleargui()
GUICtrlSetImage($Icon3, "link2.jpg", 8)

Case $Icon5
_Cleargui()
GUICtrlSetImage($Icon5, "indstillinger2.jpg", 8)

;~ ************************************** Remove this part to see how it works as intended (tho the button of course won't work)
Case $BAddPrinter
$testthis = _GUICtrlListBox_GetSelItems($Printerlist)
MsgBox(0, "", "You Chose " & $testthis[0] & " items.")

;~;~ ************************************** End
EndSwitch
WEnd


func _Cleargui()
GUICtrlSetImage($Icon0, "lock.jpg", 8)
GUICtrlSetImage($Icon1, "print.jpg", 8)
GUICtrlSetImage($Icon2, "disk.jpg", 8)
GUICtrlSetImage($Icon3, "link.jpg", 8)
GUICtrlSetImage($Icon5, "indstillinger.jpg", 8)

GUICtrlDelete($Brugernavnstext)
GUICtrlDelete($Brugernavn)
GUICtrlDelete($kodeordstext)
GUICtrlDelete($PasswordEdit)
GUICtrlDelete($Combo1)
GUICtrlDelete($Button1)
GUICtrlDelete($BClose)
GUICtrlDelete($Networktext)
GUICtrlDelete($Printerlist)
GUICtrlDelete($BAddPrinter)
GUICtrlDelete($Drive1)
GUICtrlDelete($Drive1text)
GUICtrlDelete($Drive2)
GUICtrlDelete($Drive2text)
GUICtrlDelete($Drive3)
GUICtrlDelete($Drive3text)
GUICtrlDelete($Drive4)
GUICtrlDelete($Drive4text)
GUICtrlDelete($Drive5)
GUICtrlDelete($Drive5text)
GUICtrlDelete($Drive6)
GUICtrlDelete($Drive6text)
EndFunc





Func _Logingui()
$Brugernavnstext = GUICtrlCreateLabel("Brugernavn", 8, 48, 150, 20, 0)
GUICtrlSetFont($Brugernavnstext, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Brugernavnstext, 0xFFFFFF)
$Brugernavn = GUICtrlCreateInput("", 8, 70, 200, 21)
$kodeordstext = GUICtrlCreateLabel("Kodeord", 8, 104, 150, 17, 0)
GUICtrlSetFont($kodeordstext, 12, 1000, 0, "Verdana")
GUICtrlSetColor($kodeordstext, 0xFFFFFF)
$PasswordEdit = GUICtrlCreateInput("", 8, 124, 200, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Networktext = GUICtrlCreateLabel("Forbind til netværk", 8, 160, 200, 20, 0)
GUICtrlSetFont($Networktext, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Networktext, 0xFFFFFF)
$Combo1 = GUICtrlCreateCombo("", 8, 180, 201, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, "Automatisk|Trådløst Herningsholm|Trådløst Eksamen|VPN|Manuel", "Automatisk")
GUICtrlSetFont(-1, 10, 1000, 0, "Arial")
$Button1 = GUICtrlCreateButton("Tilslut", 8, 225, 90, 25)
GUICtrlSetFont(-1, 10, 1000, 0, "Arial")
$BClose = GUICtrlCreateButton("Luk", 118, 225, 90, 25)
GUICtrlSetFont(-1, 10, 1000, 0, "Arial")
EndFunc

Func _Printgui()
$Printerlist = GUICtrlCreateList("", 8, 48, 200, 97,BitOR($LBS_SORT, $WS_HSCROLL, $WS_VSCROLL, $WS_BORDER, $LBS_HASSTRINGS, $LBS_MULTIPLESEL))
GUICtrlSetData($Printerlist, "U-01-0-064-HP2015|U-01-0-084-HP2700C|U-01-0-086-HP2700C|U-01-0-088-HP2700C|U-01-1-018-HP4015|U-01-1-054-HP4015|U-01-1-073-HP2055|U-01-1-073-HP4700C|U-01-2-018-HP4250|U-01-2-018-HP4700C|U-01-2-052-HP4015|U-01-2-052-OKI561C")
$BAddPrinter = GUICtrlCreateButton("Tilføj Printer", 8, 225, 90, 25)
GUICtrlSetFont(-1, 10, 1000, 0, "Arial")
EndFunc

Func _Drevgui()
$Drive1 = GUICtrlCreateCheckbox("", 8, 49, 15, 15)
$Drive1text = GUICtrlCreateLabel("H-Drev", 27, 48, 70, 20, 0)
GUICtrlSetFont($Drive1text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive1text, 0xFFFFFF)

$Drive2 = GUICtrlCreateCheckbox("", 8, 74, 15, 15)
$Drive2text = GUICtrlCreateLabel("O-Drev", 27, 73, 70, 20, 0)
GUICtrlSetFont($Drive2text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive2text, 0xFFFFFF)

$Drive3 = GUICtrlCreateCheckbox("", 8, 99, 15, 15)
$Drive3text = GUICtrlCreateLabel("Q-Drev", 27, 98, 70, 20, 0)
GUICtrlSetFont($Drive3text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive3text, 0xFFFFFF)

$Drive4 = GUICtrlCreateCheckbox("", 8, 124, 15, 15)
$Drive4text = GUICtrlCreateLabel("G-Drev", 27, 123, 70, 20, 0)
GUICtrlSetFont($Drive4text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive4text, 0xFFFFFF)

$Drive5 = GUICtrlCreateCheckbox("", 8, 149, 15, 15)
$Drive5text = GUICtrlCreateLabel("J-drev", 27, 148, 70, 20, 0)
GUICtrlSetFont($Drive5text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive5text, 0xFFFFFF)

$Drive6 = GUICtrlCreateCheckbox("", 8, 174, 15, 15)
$Drive6text = GUICtrlCreateLabel("I-Drev", 27, 173, 70, 20, 0)
GUICtrlSetFont($Drive6text, 12, 1000, 0, "Verdana")
GUICtrlSetColor($Drive6text, 0xFFFFFF)

EndFunc
Edited by CartoonDragon
Link to comment
Share on other sites

In a similar thread a few days ago it was suggested to create all the GUIs you need at the start of the script and then switch between them.

This is much faster than deleting/creating the controls every time.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks Water, but that brings me to another question then

Do I make 1 main gui with 5 sub gui's that move along with the main gui to make it pretend it's just 1 gui?

Or do I make 5 gui's that look almost alike and try to make them open and close at the excact same location to pretend to be 1 gui?

Link to comment
Share on other sites

For the subGUI part you could have a look at this written by Melba23.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

In a similar thread a few days ago it was suggested to create all the GUIs you need at the start of the script and then switch between them.

This is much faster than deleting/creating the controls every time.

Correct me if I'm wrong, but wouldn't all that information then be held in memory?

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

@OP check out using tabs instead of buttons. Then you can just load all of your controls into each tab so when the tab is selected, the controls will populate for that tab.

http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTab.htm

It has a good example in the help file to follow as well.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Thanks Water,

That was the thing i initially tried to use, but it got to confusing and i ran in to a few issues with it, but i will give it another try

mechaflash213,

I've tried to use tabs, but my users don't see them, this has been an issue with many users of my program. There for i'm trying to do it with pictures because that seems to work more intuitive for my users.

Link to comment
Share on other sites

You could combine both worlds.

Put a button on each page to switch to the appropriate tab. Advanced users can select the needed tab directly.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I added the buttons to the example GUI like how water suggested. Works nicely. Wish there was a way to hide the tabs for your use, but $GUI_HIDE doesn't work on the tab items =(

#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $msg, $tab[3], $button[3]

    GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered

    GUISetBkColor(0x00E0FFFF)
    GUISetFont(9, 300)

    $tabpane = GUICtrlCreateTab(10, 10, 200, 100)

    $tab[0] = GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

    $tab[1] = GUICtrlCreateTabItem("tab----1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    $tab[2] = GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("") ; end tabitem definition

    GUICtrlCreateLabel("label3", 20, 130, 50, 20)

    $button[0] = GUICtrlCreateButton("Tab 1", 20, 130, 80, 40)
    $button[1] = GUICtrlCreateButton("Tab 2", 110, 130, 80, 40)
    $button[2] = GUICtrlCreateButton("Tab 3", 200, 130, 80, 40)

    GUICtrlSetState($tabpane, $GUI_HIDE) ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $button[0]
                GUICtrlSetState($tab[0], $GUI_SHOW)
            Case $button[1]
                GUICtrlSetState($tab[1], $GUI_SHOW)
            Case $button[2]
                GUICtrlSetState($tab[2], $GUI_SHOW)
        EndSwitch
    WEnd
EndFunc   ;==>Example

EDIT: AIYAAA! Hide the whole tab control! See green arrows

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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