FMS

[SOLVED]Could Autoit write it's own code?

18 posts in this topic

#1 ·  Posted (edited)

Hello,

Does anyone know if Autoit could write its own commands?
Whit this i mean :
i got a GUI whit labels or buttons written like this :

$Label1 = GUICtrlCreateLabel("Label1", 24, 184, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 24, 208, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 24, 232, 36, 17)

and i want to do someting like this :

$r = 1
Do
    GUICtrlSetData ($label.$r , "here is another label text")
    $r = $r + 1
Until $r = 3

notice here the  $label.$r  part and ofcourse this isnt working :) but I think I  made mine point / question :)
does somebode know how this is possible?
 

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



FMS,

You mean like this?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$Label1 = GUICtrlCreateLabel("Label1", 24, 184, 36, 17)
$Label2 = GUICtrlCreateLabel("Label2", 24, 208, 36, 17)
$Label3 = GUICtrlCreateLabel("Label3", 24, 232, 36, 17)

For $i = 4 To 6
    GUICtrlCreateLabel("Label" & $i, 24, 156 + ($i * 24), 36, 17)
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

just store the ControlIDs in an array if you need them later.

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

#3 ·  Posted (edited)

no sorry @Melba23, i was using -->

GUICtrlSetData

not create :) i wanted to change the text in the labels ..

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

FMS,

Not that difficult(unless you have again edited the requirement)

#include <GUIConstantsEx.au3>

Global $aCID[4]

$hGUI = GUICreate("Test", 500, 500)

For $i = 1 To 3
    $aCID[$i] = GUICtrlCreateLabel("Label" & $i, 24, 156 + ($i * 24), 100, 17)
Next

$cChange = GUICtrlCreateButton("Change", 10, 10, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cChange
            For $i = 1 To 3
                GUICtrlSetData($aCID[$i], "New label " & $i * 100)
            Next
    EndSwitch
WEnd

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

thanks @Melba23 , this was totaly what i needed :)

I din't know you could create them in a array. :>

Unfortanly i need to rearange the whole GUI and functions 4500 lines long ... :D 

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The best way to lay out the controls of a GUI is to use arrays. 2D arrays work well for menus. I frequently do something like this:

#include <GUIConstants.au3>

Local $hGUI = GUICreate('labels', 350, 100)
Local $ahControl[4] = ['label 1','label 2', 'label 3', 'label 4'] ; I often start with names in the array

Local $iHorz = 5
For $i = 0 To UBound($ahControl) -1
    $ahControl[$i] = GUICtrlCreateLabel($ahControl[$i], 10 + $i * (40 + $iHorz), 10, 40)
Next

GUISetState(@SW_SHOW)

Local $msg
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $ahControl[0]
            MsgBox(0, "", "You clicked label 1")
        Case $ahControl[1]
            MsgBox(0, "", "You clicked label 2")
        Case $ahControl[2]
            MsgBox(0, "", "You clicked label 3")
        Case $ahControl[3]
            MsgBox(0, "", "You clicked label 4")
    EndSwitch
WEnd

Even if the telephone hadn't interrupted me, I still wouldn't have beaten Melba.

Actually the original question is interesting. Code generating programs are not new, but they can be very tricky. :shifty:

Edited by czardas

Share this post


Link to post
Share on other sites

even though a real great example @czardas :)  also kudo's for you :D

1 person likes this

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

building on czardas's example...a more flexible approach...

#include <GUIConstants.au3>

Local $hGUI = GUICreate('labels', 350, 100)
Local $ahControl[4]

Local $iHorz = 5
For $i = 0 To UBound($ahControl) -1
    $ahControl[$i] = GUICtrlCreateLabel('', 10 + $i * (70 + $iHorz), 20, 70, 25)
    guictrlsetdata($ahControl[$i],'LABEL # ' & $i+1)
Next

GUISetState(@SW_SHOW)

Local $msg
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    Case $ahControl[0] to $ahControl[ubound($ahControl)-1]
            MsgBox(0, "", 'You clicked ' & guictrlread($msg))
    EndSwitch
WEnd

hmmm...I gotta get a job:'(


Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

all great examples i must say , i realy learned from all three example scripts in how to build the GUI.

But i must say in furhter functions its hard to know whish label is whish.
even thougt it kinde creeps me in whis is a faster / better way vs each label or button his own name for the overall speed of the script?

like - $label_for_input_1 VS $ahControl[3]


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

FMS,

I don't think speed is an issue here.  However, the organization of your script is a huge issue.

kylomas


Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites
3 minutes ago, kylomas said:

I don't think speed is an issue here.  However, the organization of your script is a huge issue.

I absolutely agree. Running GUI functions tends to be slow anyway, so saving a few ms doesn't generally make much difference. If readability involves a few extra lines of code, then so what?

Share this post


Link to post
Share on other sites
5 minutes ago, kylomas said:

However, the organization of your script is a huge issue.

what do you mean whit this?
Why is this a huge issue?


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Quote

hmmm...I gotta get a job:'(

Quote

Me too... 

We are hiring a SOC monkey, If you like Splunk and Austin, Tx. (which is the most :guitar: place ever)

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Here a other example to create dynamic controls:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Opt('MustDeclareVars', 1)
Global $aBtnIds[10][2]


Global $hGui = GUICreate('Buttontest', 105, 145)
Global $msg, $Handle, $aPos

For $i = 0 To 8
    $aBtnIds[$i][0] = GUICtrlCreateButton($i + 1, 10 + Mod($i, 3) * 30, 10 + Int($i / 3) * 30, 25, 25)
    ;$aBtnIds[$i][0] enthält jetzt die ID
    ConsoleWrite($i + 1 & ': ' & $aBtnIds[$i][0] & @CRLF)
    GUICtrlSetBkColor(-1, 0x12345678)
    $aBtnIds[$i][1] = 'leer'
Next
$aBtnIds[9][0] = GUICtrlCreateButton('OK', 10, 110, 90, 25)
ConsoleWrite('OK: ' & $aBtnIds[$i][0] & @CRLF)
GUISetState()

;Sleep(Random(500,1500))
;_click(Random(0,8,1),Random(0,1,1))

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aBtnIds[0][0] To $aBtnIds[8][0]
            _Click($msg - $aBtnIds[0][0], True)
        Case $aBtnIds[9][0]
            _Farben()
        Case $GUI_EVENT_SECONDARYUP
            $aPos = GUIGetCursorInfo()
            _Click($aPos[4] - $aBtnIds[0][0])
    EndSwitch
WEnd

Func _Click($iBtn, $bPrimary = False)
    Local $sButton
    ConsoleWrite('_Click: ' & $iBtn & @CRLF)
    If $bPrimary Then
        $sButton = 'Primary'
        ;If $aBtnIds[$iBtn][1]='leer' Then _
        GUICtrlSetBkColor($aBtnIds[$iBtn][0], 0x990000)
        $aBtnIds[$iBtn][1]='rot'
    Else
        $sButton = 'Secondary'
        ;If $aBtnIds[$iBtn][1]='leer' Then _
        GUICtrlSetBkColor($aBtnIds[$iBtn][0], 0x059122)
        $aBtnIds[$iBtn][1]='grün'
    EndIf
    MsgBox(0, $sButton & ' Buttonclick', 'Button with ID ' & $aBtnIds[$iBtn][0] & ' was clicked.' & @CRLF & 'The text of the button is: ' & ControlGetText('Buttontest', '', $aBtnIds[$iBtn][0]) & @CRLF, 5, $hGui)
    ConsoleWrite(GUICtrlRead($aBtnIds[$iBtn][0]) & @CRLF)
EndFunc   ;==>_Click
WinList

Func _Farben()
    Local $sText = '', $aBtns
    For $i = 0 To 8
        $sText &= $aBtnIds[$i][1]
        If $i < 8 Then $sText &= '|'
    Next
    ConsoleWrite($sText & @CRLF)
    $aBtns = StringSplit($sText, '|')
    $aBtns[0] = UBound($aBtns) - 1
    _ArrayDisplay($aBtns, 'Farben', '', 32)
EndFunc   ;==>_Farben

all of these controls must be created in one after the other (best way is a loop), so just basic math is needed to identify each.

Share this post


Link to post
Share on other sites

#17 ·  Posted

I'm not shure iff I need to open another question for this but I tried some of the options above and done some tests.
Noticbly better coding i must say , and lesser coding :D  (I'm feeling sush a noob ..:> )
I got 2 problems at the moment whit it and hope somebody could help me whit this test script of mine.
Here I realy do not know what I'm doing wrong.
these 2 functions don't work proparly and don't know where.
I realy want to learn a new way of coding so if somebody has some pointers about this scipt please advice :)

If i made an array ( $GL_APS_name & $GL_APS_set in this example) whit _Crypt_EncryptData & _Crypt_DecryptData theese 2 functions won't work.
Iff i made thoose 2 array's whit "clean info" the functions work.

At first i thought i needed to

$GL_GUI_ctrl[$i][1] = BinaryToString ($GL_APS_set[$i])

when u use that data.

I'm realy shure that i have the data in the globals i checked it.

The decryping is looking simalar like this

$GL_APS_name[$i] = BinaryToString(_Crypt_DecryptData($encrypted_APS_names, "somekey", $CALG_AES_128))

I realy don't know if it's not working because the GUI creation is faulty or the binarytostring is faulty.
I hope somebody got good advice or know what going wrong here.

Thanks in advance.

Func GUI_APS()
;~    _ArrayDisplay($GL_APS_name)
;~    _ArrayDisplay($GL_APS_set)

;~    Global $GL_APS_base_count = 5
;~    Global $GL_APS_name[$GL_APS_base_count] = [$GL_APS_base_count ,'label 1','label 2', 'label 3', 'label 4']
;~    Global $GL_APS_set[$GL_APS_base_count] = [$GL_APS_base_count ,'input 1','input 2', 'input 3', 'input 4']
      Global $GL_APS_name_lbl[$GL_APS_base_count]
      Global $GL_APS_set_input[$GL_APS_base_count]
      _ArrayDisplay($GL_APS_name)
      _ArrayDisplay($GL_APS_set)
      Global $GL_GUI_ctrl[$GL_APS_base_count][2]
MsgBox($MB_SYSTEMMODAL, "Title", "$GL_APS_base_count = " & $GL_APS_base_count)
      For $i = 0 To $GL_APS_base_count -1
         $GL_GUI_ctrl[$i][0] = 0
         $GL_GUI_ctrl[$i][1] = BinaryToString ($GL_APS_set[$i])
      Next

_ArrayDisplay($GL_GUI_ctrl)
      $GUI_APS = GUICreate("SRMT settings", 722, 280, 100, 100)
         Local $iHorz = 5
         For $i = 0 To $GL_APS_name[0] - 1 ;==    text            left                 top  width
            $GL_APS_name_lbl[$i] = GUICtrlCreateLabel(BinaryToString ($GL_APS_name[$i]), 8 ,10 + $i * (40 + $iHorz), 90)
         Next

         For $i = 0 To $GL_APS_set[0] - 1 ;==    text            left                 top  width
            $GL_APS_set_input[$i] = GUICtrlCreateInput(BinaryToString($GL_GUI_ctrl[$i][1]),60 ,10 + $i * (40 + $iHorz), 90)
         Next

         $cancel = GUICtrlCreateButton("cancel", 544, 240, 75, 25)
         $save = GUICtrlCreateButton("save", 632, 240, 75, 25)
      GUISetState(@SW_SHOW)

      GUIRegisterMsg($WM_COMMAND, "nmsg_get")
      Local $nmsg
      While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
            Case $GUI_EVENT_CLOSE , $cancel
               GUIDelete($GUI_APS)
               ExitLoop
            Case $save
               _ArrayDisplay($GL_GUI_ctrl, "$GL_GUI_ctrl")
               For $i = 0 To $GL_APS_set[0] - 1
                  If $GL_GUI_ctrl[$i][0] = 1 Then
                     $GL_APS_set[$i] =  GUICtrlRead($GL_APS_set_input[$i])
                  EndIf
               Next
               _ArrayDisplay($GL_APS_set , "$GL_APS_set")
         EndSwitch
      WEnd
;~    EndIf
EndFunc

Func nmsg_get($hWnd, $nMsg, $iwParam, $ilParam)
   Local $setHK = False
   $nNotifyCode = BitShift($iwParam, 16)
   $nID = BitAND($iwParam, 0x0000FFFF)
   $hCtrl = $ilParam

   If $nNotifyCode = $EN_CHANGE Then
      For $i = 0 To $GL_APS_base_count - 1
         If $hCtrl = GUICtrlGetHandle($GL_APS_set_input[$i]) Then
            $GL_GUI_ctrl[$i][0] = 1
         EndIf
      Next

      If @error Then
         MsgBox($MB_SYSTEMMODAL, "Title", "error = " & @error)
      EndIf
   EndIf

   Return $GUI_RUNDEFMSG
EndFunc

ddd


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

#18 ·  Posted

nvm i found the problem :)
it was the $i to ... function Thanks anyway :)


as finishing touch god created the dutch

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