Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] Dynamic GUI Creation

5 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I'm try to create a gui can be create element by itself. This is what i have done:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIResizeMode", BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))

Global Const $Element_For_Column = 5 ; Max number of element for column
Global Const $Max_Element = 15 ; Number of total element
Global $iCount = 1 ; Number 1 is used for basic element
Global $Move_Top, $Move_Left, $Temp_iCount
Global $Input_[1][1], $Label_[1][1], $Button_[1][2]

$hGUI = GUICreate("Dynamic GUI", 233, 107, -1, -1)
$Label_A1 = GUICtrlCreateLabel("This is a label n°1", 8, 26, 90, 17)
$Input_A1 = GUICtrlCreateInput("", 8, 43, 161, 21)
$Button_A1 = GUICtrlCreateButton("1", 176, 41, 51, 25)
$Button_A2 = GUICtrlCreateButton("Check Input", 8, 72, 75, 25)
$Button_Minus = GUICtrlCreateButton("-", 176, 2, 19, 25)
$Button_Plus = GUICtrlCreateButton("+", 210, 2, 19, 25)
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Button_A1
GUICtrlSetData($Input_A1, "You have clicked button 1")
Case $Button_A2
_Test_Func($Input_A1)
Case $Button_Plus
_Add_Element()
Case $Button_Minus
Delete_Element()
Case Else
For $i = 0 To UBound($Button_, 1) - 1
    Switch $msg
     Case $Button_[$i][0]
     GUICtrlSetData($Input_[$i][0], "You have clicked button " & $i + 1)
     Case $Button_[$i][1]
     _Test_Func($Input_[$i][0])
    EndSwitch
Next
EndSwitch
WEnd

Func _Test_Func($Value)
MsgBox(0, 0, "This is the value of Input: " & GUICtrlRead($Value) & @CRLF)
EndFunc ;==>_Test_Func

Func _Add_Element()
Global $hGUISize_Height = 89, $hGUISize_Width = 250
Local Const $Size = WinGetPos($hGUI)
$Temp_iCount += 1
$iCount += 1
$Move_Top += 90
If $Temp_iCount = $Element_For_Column Then
If $iCount <= $Max_Element Then
WinMove($hGUI, "", Default, Default, $Size[2] + $hGUISize_Width, Default)
_Middle($hGUI, "")
$Move_Top = 0 ; reset top
$Move_Left += 250 ; create left vaule
$Temp_iCount = 0 ; reset temp_element
EndIf
EndIf
If $iCount <= $Max_Element Then
ReDim $Label_[$iCount][$iCount]
ReDim $Input_[$iCount][$iCount]
ReDim $Button_[$iCount][$iCount * 2]
If $iCount <= $Element_For_Column Then
$Label_[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8, 26 + $Move_Top, 90, 17)
$Input_[$iCount - 1][0] = GUICtrlCreateInput("", 8, 43 + $Move_Top, 161, 21)
$Button_[$iCount - 1][0] = GUICtrlCreateButton($iCount, 176, 41 + $Move_Top, 51, 25)
$Button_[$iCount - 1][1] = GUICtrlCreateButton("Check Input", 8, 72 + $Move_Top, 75, 25)
WinMove($hGUI, "", Default, Default, Default, $Size[3] + $hGUISize_Height)
_Middle($hGUI, "")
Else
$Label_[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8 + $Move_Left, 26 + $Move_Top, 90, 17)
$Input_[$iCount - 1][0] = GUICtrlCreateInput("", 8 + $Move_Left, 43 + $Move_Top, 161, 21)
$Button_[$iCount - 1][0] = GUICtrlCreateButton($iCount, 176 + $Move_Left, 41 + $Move_Top, 51, 25)
$Button_[$iCount - 1][1] = GUICtrlCreateButton("Check Input", 8 + $Move_Left, 72 + $Move_Top, 75, 25)
EndIf
EndIf
If $iCount > $Max_Element Then
$iCount = $Max_Element
$Temp_iCount = $Element_For_Column - 1
EndIf
EndFunc ;==>_Add_Element

Func Delete_Element()
Local Const $Size = WinGetPos($hGUI)
Local $Temp_Move_Top = 90 ; Equal to $Move_Top
If $iCount = 1 Then ; No element
$iCount = 1
Return
Else
GUICtrlDelete($Label_[$iCount - 1][0]) ; delete element
GUICtrlDelete($Input_[$iCount - 1][0]) ; delete element
GUICtrlDelete($Button_[$iCount - 1][0]) ; delete element
GUICtrlDelete($Button_[$iCount - 1][1]) ; delete element
EndIf
If $iCount <> 0 Then
If $iCount <= $Element_For_Column Then
WinMove($hGUI, "", Default, Default, Default, $Size[3] - $hGUISize_Height) ; resize gui
_Middle($hGUI, "")
EndIf
EndIf
If $Temp_iCount = 0 Then ; New Column
WinMove($hGUI, "", Default, Default, $Size[2] - $hGUISize_Width, Default) ; resize gui
_Middle($hGUI, "")
$Move_Left -= 250 ; Remove left value
$Temp_iCount += $Element_For_Column ; Remove new colum
EndIf
$iCount -= 1 ; Delete one count
$Temp_iCount -= 1; Delete one temp count
If $Move_Top = 0 Then ; Equal to start posizion
$Move_Top = $Temp_Move_Top * ($Element_For_Column - 1)
Else
$Move_Top -= 90 ; Delete one position
EndIf
EndFunc ;==>Delete_Element

Func _Middle(Const $win, Const $txt) ; Snippet Valuater - cdkid
Local Const $Size = WinGetClientSize($win, $txt)
Local Const $y = (@DesktopHeight / 2) - ($Size[1] / 2)
Local Const $x = (@DesktopWidth / 2) - ($Size[0] / 2)
Return WinMove($win, $txt, $x, $y)
EndFunc ;==>_Middle

1) The gui can create element but the size of the width is good only for the second element, then increase every 3°, 4° etc.

2) Buttons don't work because i don't know how to set in the While...WEnd and the realtive function

3) I don't know how to make the creation of 3 element for column until the $Max_Element is reached

4) I don't know how to delete group element ( except the first )

Thanks ;)

EDIT: No more to go, if someone has suggestion/improvement just ask ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this and see if it aint what you want.

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Opt("GUIResizeMode",  BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))

Global Const $Element_For_Column = 3 ; Max number of element for column

Global Const $Max_Element = 9 ; Number of total element

Global $iCount = 1 ; Number 1 is used for basic element

Global $Move_Top

Global $Move_Left

Global $Temp_iCount

Global Const $hGUI = GUICreate("Dynamic GUI", 233, 107, -1, -1)

Global Const $Label_A1 = GUICtrlCreateLabel("This is a label n°1", 8, 26, 90, 17)

Global Const $Input_A1 = GUICtrlCreateInput("", 8, 43, 161, 21)

Global Const $Button_A1 = GUICtrlCreateButton("1", 176, 41, 51, 25)

Global Const $Button_A2 = GUICtrlCreateButton("Check Input", 8, 72, 75, 25)

Global Const $Button_Minus = GUICtrlCreateButton("-", 176, 2, 19, 25)

Global Const $Button_Plus = GUICtrlCreateButton("+", 210, 2, 19, 25)

Global $ctrl_array[1][4]

GUISetState(@SW_SHOWNORMAL)

Global $msg = ''

Do
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button_A1
            GUICtrlSetData($Input_A1, "You have clicked button 1")

        Case $Button_A2
            _Test_Func($Input_A1)

        Case $Button_Plus
            _Add_Element()

        Case $Button_Minus
            Delete_Element()

        Case Else
            Global $ctrl_array_upbound = UBound($ctrl_array, 1)

            For $i = 0 To $ctrl_array_upbound - 1
                Switch $msg
                    Case $ctrl_array[$i][2]
                        GUICtrlSetData($ctrl_array[$i][1], "You have clicked button " & $i + 1)

                    Case $ctrl_array[$i][3]
                        _Test_Func($ctrl_array[$i][1])
                EndSwitch
            Next
    EndSwitch
Until False

Func _Test_Func(Const $Value)
    ConsoleWrite("This is the value of Input: " & GUICtrlRead($Value) & @crlf)
EndFunc   ;==>_Test_Func

Func _Add_Element()
    Local Const $Size = WinGetClientSize($hGUI, '')

    $Temp_iCount += 1

    $iCount += 1

    $Move_Top += 90

    If $Temp_iCount = $Element_For_Column Then
        If $iCount <= $Max_Element Then
            Local Const $hGUISize_Width = 250

            WinMove($hGUI, "", Default, Default, $Size[0] + $hGUISize_Width, Default)

            _Middle($hGUI, "")

            $Move_Top = "" ; reset top

            $Move_Left += 240 ; create left vaule

            $Temp_iCount = "" ; reset temp_element
        EndIf
    EndIf

    If $iCount <= $Max_Element Then
        ReDim $ctrl_array[$iCount][$iCount * 4]

        If $iCount <= $Element_For_Column Then
            $ctrl_array[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8, 26 + $Move_Top, 90, 17) ; how to set the variable name?

            $ctrl_array[$iCount - 1][1] = GUICtrlCreateInput("", 8, 43 + $Move_Top, 161, 21)

            $ctrl_array[$iCount - 1][2] = GUICtrlCreateButton($iCount, 176, 41 + $Move_Top, 51, 25)

            $ctrl_array[$iCount - 1][3] = GUICtrlCreateButton("Check Input", 8, 72 + $Move_Top, 75, 25)

            Local Const $hGUISize_Height = 120

            WinMove($hGUI, "", Default, Default, Default, $Size[1] + $hGUISize_Height)

            _Middle($hGUI, "")
        Else
            $ctrl_array[$iCount - 1][0] = GUICtrlCreateLabel("This is a label n°" & $iCount, 8 + $Move_Left, 26 + $Move_Top, 90, 17) ; how to set the varable name?

            $ctrl_array[$iCount - 1][1] = GUICtrlCreateInput("", 8 + $Move_Left, 43 + $Move_Top, 161, 21)

            $ctrl_array[$iCount - 1][2] = GUICtrlCreateButton($iCount, 176 + $Move_Left, 41 + $Move_Top, 51, 25)

            $ctrl_array[$iCount - 1][3] = GUICtrlCreateButton("Check Input", 8 + $Move_Left, 72 + $Move_Top, 75, 25)
        EndIf
    EndIf
EndFunc   ;==>_Add_Element

Func Delete_Element()
    ;???
EndFunc   ;==>Delete_Element

Func _Middle(Const $win, Const $txt) ; Snippet Valuater - cdkid
    Local Const $Size = WinGetClientSize($win, $txt)

    Local Const $y = (@DesktopHeight / 2) - ($Size[1] / 2)

    Local Const $x = (@DesktopWidth / 2) - ($Size[0] / 2)

    Return WinMove($win, $txt, $x, $y)
EndFunc   ;==>_Middle

I'll leave deleting them as an exercise for you. =)

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

Thanks, i have make some little change ( i have make 4 different array for every element ) and i have added the deleting func...but it's a little bugged :D

The script is on the first post. Can you/someone check it out?

Thanks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have resolved the 99% of the problems with Delete_Element() ( i have updated the script on the first post ) i have only the last

When i created 6 element ( with 5 = Max element for column, so it created a new column with 1 element ) and i try to delete the 6° and recreate it, work fine and no problems

When i created 6 element ( with 5 = Max element for column, so it created a new column with 1 element ) and i try to delete the 6° and the 5° ( the result is only one column with four element ) and recreate the 5° again, i don't see anything

Tips?

EDIT: I have resolve the last problem, seems work fine now. Waiting for expert if the have improvement-suggestion on this script. Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Silence gives consent ( i hope )

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Skeletor
      By Skeletor
      MS Splash Screens
      The office 2016/17 office suite has made many people turn heads with its functions and especially their splash screen.
      I now present to you, the MS Style Splash Screen. For Rookies, Novices and anyone who wants a ready made splash screen for your gui application.

      You can now download it and also try it out yourself.
      You have three colors to choose from:
      Blue
      Red
      Green
      All three colours are from the famous programs.
      I also included the KODA form to you can have freedom with this splash screen.
      Note: the KODA form does not have the three colours as well as the correct blue. 

      Have fun and enjoy.
      Note:
      I will update the splash to add the automated 3 dots animation at a later stage. 
       
       
    • Skeletor
      By Skeletor
      A gui splash screen. Themed after the famous MS Office Suite.
      Three colours to choose from, Red, Blue and Green.
      You can change the labels to your own application.

      Also bundled with this is the KODA form. So you can open up and see the basic structure of this splash screen.
       
      Splash Screen GUI.zip
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • SteveJM
      By SteveJM
      I have a working program currently driven largely through menu selections. I would like to add a toolbar where most of the tollbar button actions are basically the same as menu items, but quicker to access. I have been wading around in toolbar examples, MSDN pages etc, it's clearly going to be a bit of a slog to get everything right, including tooltips etc. I thought I would start with something simple to prove the principle.
      Using bits from the help file examples I have a small program that successfully displays a toolbar. However, what seemed like the most elegant way to deal with the button commands does not seem to work. My understanding was that a toolbar button fires a WM_COMMAND message, with the command Id set by the second parameter in the call to
      _GUICtrlToolbar_AddButton ( $hWnd, $iID, $iImage)
      so I though it would be a good idea to set this Id to the same value as my menu item Id; then it would run the same task which is what I wanted. This did not work. I am using message loop mode and would like to stick with this because some of my scripts run hardware at the same time as the gui; it is easier if I don't have to worry about code being interrupted with the hardware in an unknown state . So I added a handler for WM_COMMAND, with some cribbed display code to try and see why. The toolbar button defintely fired a WM_COMMAND message and the Id looked the same, so no explanation there.
      I guess the issue is with GUIGetMsg() which may be constructed to ignore all but a limited number of control handles, i.e. those made with the GuiCtrlCreate... commands; this is speculation.
      I would dearly love to find a tidy way to get around this. Having some controls handled in the message loop and some in a WM_COMMAND handler, performing the same task, feels ugly. I would be very grateful for further insight from someone experienced with handling a toolbar. Perhaps I should be trying to fire the menu item. I have attached a code snippet to try and illustrate the issue.
       
       
       
      ToolbarTrial.au3
    • XinYoung
      By XinYoung
      Hello all,
      I've been working on 4 standalone scripts. They each have their own GUI and are now independent .exe's. But instead of having 4 separate icons on my computer, is it possible to put them all together into one .exe?
      What I want is one interface with tabs. Each script's GUI would be on their own respective tab. Is this possible?
      The different scripts don't need to communicate with one another. I just want them all in one .exe.
      I can't find this anywhere... Any help would be greatly appreciated. Thank you!