Sign in to follow this  
Followers 0
remin

Accelerator keys, where to place them?

17 posts in this topic

#1 ·  Posted (edited)

I'm a bit confused about accelerator keys and checkboxes.

1) See my code below: Is this the correct way how I put them in the script?

    (First: reading the ini file to see if the checkbox is enabled then setting the checkbox state before "GUISetState(@SW_SHOW"

     Second: After having created the GUI, if the status of the checkbox changes disable or enable the accelerator keys (Case $CB3)

     Third: when the GUI is closed, write checkbox status in ini)

2) I've read in a reply of Melba in another topic that in order to disable the accelerator keys (in my case {enter})

    It is needed to Send a CR to the control

    "ControlSend($hGUI, "", $hFocus, @CR)"
    I don't know why this is, I haven't understand it very well and I don't know where to put it in my case.
    (but it seems to work fine in my code without it)
3) In my code below I have inserted only 2 buttons (search and images)
    In reality I have a lot more buttons.
    The code between ";Focus and Accelerator key" and ";END Focus and Accelerator key" is almost the same in all Cases.
    The only thing different is the value of $focus. The value of $focus is the Case name. 
    Is there a way to put this code in an external function to avoid multiplying the code many times?
    (I noted in the help file that there is not a GUI ID in GUICtrlSetState and GUISetAccelerators)
 
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <EditConstants.au3>


HotKeySet("^4", "SearchMenu")


While 1
    Sleep(10000)
WEnd


Func SearchMenu()

;========GUI=============
$MyFile = "d:\temp\RW-autoit.ini"
Global $url


 $Form5=          GUICreate("Search Menu", 345, 140, @DesktopWidth*0.65, @DesktopHeight*0.21)
 $RWSearch =      GuiCtrlCreateEdit("",                               16,  10, 270, 50)
 $textGoogle  =   GUICtrlCreateLabel("Google:",                       20,  90, 100, 20)
 $bsearch =       GUICtrlCreateButton("Search",                      110,  90,  60, 20)
 $bimages =       GUICtrlCreateButton("Images",                      175,  90,  60, 20)
 $CB3  =          GUICtrlCreateCheckbox("Enter=Send (^Enter=Enter)", 110, 120, 145, 20)


 If FileExists($MyFile) Then
     $State = IniRead($MyFile,"CheckBox","CB3",0)
     If $State == 1 Then
        GUICtrlSetState(($CB3), BitOr($GUI_ENABLE, $GUI_CHECKED))
     Else
        GUICtrlSetState(($CB3), BitOr($GUI_ENABLE, $GUI_UNCHECKED))
     EndIf
     $Focus = IniRead($MyFile,"Focus","Button",0)
 Else
     GUICtrlSetState(($CB3, BitOr($GUI_ENABLE, $GUI_CHECKED))
     $Focus = "bsearch"
 EndIf
GUISetState(@SW_SHOW)
;========END GUI==========


Local $aAccelKeys[1][2] = [["{ENTER}", eval($focus)]]


If _GUICtrlButton_GetCheck($CB3) Then
   GUISetAccelerators($aAccelKeys)
   Global $EnterSubmit = true
Else
   GUISetAccelerators(0)
   Global $EnterSubmit = false
EndIf


; Set the Default Key
GUICtrlSetState(eval($focus), $GUI_DEFBUTTON)


While 1
$nMsg = GUIGetMsg()
Switch $nMsg


   Case $GUI_EVENT_CLOSE
        ; write status checkboxes in ini
        If FileExists($MyFile) Then
            If _GUICtrlButton_GetCheck($CB3) Then
              IniWrite($MyFile, "CheckBox", "CB3", 1)
            Else
              IniWrite($MyFile, "CheckBox", "CB3", 0)
            EndIf
        EndIf


        ; write focus in ini
        IniWrite($MyFile, "Focus", "Button", $Focus)


        GuiDelete($Form5)
        ExitLoop


      Case $CB3
           If _GUICtrlButton_GetCheck($CB3) Then
               GUISetAccelerators($aAccelKeys)
               Global $EnterSubmit = true
           Else
               GUISetAccelerators(0)
               Global $EnterSubmit = false
           EndIf


      Case $bsearch
           $RWSearch1 = GUICtrlRead($RWSearch)
           $RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")


           ;Focus and Accelerator key
           $focus = "bsearch"
           GUICtrlSetState(eval($focus), $GUI_DEFBUTTON)
           If $EnterSubmit then
             GUISetAccelerators($aAccelKeys)
           Else
             GUISetAccelerators(0)
           Endif
           ;End Focus and Accelerator key


           $url = "https://www.google.com/search?q=" & $RWSearch2
           SearchMenuExec()


      Case $bimages
           $RWSearch1 = GUICtrlRead($RWSearch)
           $RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")


           ;Focus and Accelerator key
           $focus = "bsearch"
           GUICtrlSetState(eval($focus), $GUI_DEFBUTTON)
           If $EnterSubmit then
             GUISetAccelerators($aAccelKeys)
           Else
             GUISetAccelerators(0)
           Endif
           ;End Focus and Accelerator key


           $url = "http://images.google.com/images?hl=en&q=" & $RWSearch2
           SearchMenuExec()
EndSwitch
 WEnd
EndFunc ;==>SearchMenu


Func SearchMenuExec()
 ClipPut($url)
 ShellExecute($url)
EndFunc ;==>SearchMenuExec
Edited by remin

Share this post


Link to post
Share on other sites



remin,

 

I've read in a reply of Melba in another topic that in order to disable the accelerator keys (in my case {enter}) - It is needed to Send a CR to the control

Can you point me to where you found that because it is wrong and I cannot remember having said such a thing. :wacko:

How you are setting/cancelling the Accelerator keys is fine - just pass a non-array value to the function. :)

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

remin,

 

Can you point me to where you found that because it is wrong and I cannot remember having said such a thing. :wacko:

How you are setting/cancelling the Accelerator keys is fine - just pass a non-array value to the function. :)

M23

 

Sure :)

'?do=embed' frameborder='0' data-embedContent>>

(the last post)

Can you please tell me what you mean with pass a non-array value to the function?  :unsure:

Share this post


Link to post
Share on other sites

remin,

That code is used because the OP wanted to to actually use the associated Accel key when another control had focus. The code looks to see which control has keyboard focus and then if required disables the Accel function, passes an ENTER to the control and then re-enables the Accel function:

Case $cEnter
            ; Get control with focus
            $hFocus = _WinAPI_GetFocus()
            If $hFocus = GUICtrlGetHandle($cInput) Then
                ; If input
                MsgBox(0, "Test", "Enter Pressed In Input")
            Else
                ; If not we need to disable the Accel key
                GUISetAccelerators(0)
                ; Send a CR to the control
                ControlSend($hGUI, "", $hFocus, @CR)
                ; And then reenable the Accel key
                GUISetAccelerators($aAccelKeys)
            EndIf
As you can see, the Accel keys are disabled/re-enabled in the 2 GUISetAccelerators lines - the ControlSend line has nothing to do with it. :)

A "non-array" value is exactly that - anything which is not an array. I tend to use a simple numeric value of 0 as you can see from the above code. ;)

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

#5 ·  Posted (edited)

Melba23,

I told you I'm confused about accelerators.  ;)

You told me to add a Non-array value in your 1st replay,

but I added one (or am I wrong?):  :unsure:

GUISetAccelerators(0)

Melba,

Have you seen also my 3rd question?

ps:  

does accelerators not work with $WS_SIZEBOX?

Edited by remin

Share this post


Link to post
Share on other sites
How you are setting/cancelling the Accelerator keys is fine - just pass a non-array value to the function.

 

 

Oh.. sorry, 

I didn't understand this phrase in the beginning.

I thought I had to add a non-array value to the function

but your way of writing is a confirmation of what I did.:)

About my 3rd question:

I'm curious to know if I can use GUICtrlSetState and GUISetAccelerators

in an external function.. there is no way to indicate the Gui-name in both functions ....

Share this post


Link to post
Share on other sites

remin,

Yes, you can use a function - this is how I might do it (although I have not tested the code as I have no idea what you are doing): ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <EditConstants.au3>

HotKeySet("^4", "SearchMenu")

Global $url,$Focus, $EnterSubmit ; Do not declare Global variables inside functions <<<<<<<<<<<<

While 1
    Sleep(10) ; 10 is quite sufficient <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Func SearchMenu()

    ;========GUI=============
    $MyFile = "d:\temp\RW-autoit.ini"

    $Form5 = GUICreate("Search Menu", 345, 140, @DesktopWidth * 0.65, @DesktopHeight * 0.21)
    $RWSearch = GUICtrlCreateEdit("", 16, 10, 270, 50)
    $textGoogle = GUICtrlCreateLabel("Google:", 20, 90, 100, 20)
    $bsearch = GUICtrlCreateButton("Search", 110, 90, 60, 20)
    $bimages = GUICtrlCreateButton("Images", 175, 90, 60, 20)
    $CB3 = GUICtrlCreateCheckbox("Enter=Send (^Enter=Enter)", 110, 120, 145, 20)

    If FileExists($MyFile) Then
        $State = IniRead($MyFile, "CheckBox", "CB3", 0)
        If $State = 1 Then ; == means case-sensitive string comparison, so not needed here <<<<<<<<<<<<<<<<<<<<<<<
            GUICtrlSetState(($CB3), BitOR($GUI_ENABLE, $GUI_CHECKED))
        Else
            GUICtrlSetState(($CB3), BitOR($GUI_ENABLE, $GUI_UNCHECKED))
        EndIf
        $Focus = IniRead($MyFile, "Focus", "Button", 0)
    Else
        GUICtrlSetState($CB3, BitOR($GUI_ENABLE, $GUI_CHECKED))
        $Focus = "bsearch"
    EndIf
    GUISetState(@SW_SHOW)
    ;========END GUI==========

    Local $aAccelKeys[1][2] = [["{ENTER}", Eval($Focus)]]

    ;If _GUICtrlButton_GetCheck($CB3) Then
    If GUICtrlRead($CB3) = $GUI_CHECKED Then ; Use native functions if possible <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUISetAccelerators($aAccelKeys)
        $EnterSubmit = True
    Else
        GUISetAccelerators(0)
        $EnterSubmit = False
    EndIf

    ; Set the Default Key
    GUICtrlSetState(Eval($Focus), $GUI_DEFBUTTON)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ; write status checkboxes in ini
                If FileExists($MyFile) Then
                    If GUICtrlRead($CB3) = $GUI_CHECKED Then
                        IniWrite($MyFile, "CheckBox", "CB3", 1)
                    Else
                        IniWrite($MyFile, "CheckBox", "CB3", 0)
                    EndIf
                EndIf
                ; write focus in ini
                IniWrite($MyFile, "Focus", "Button", $Focus)
                GUIDelete($Form5)
                ExitLoop
            Case $CB3
                If GUICtrlRead($CB3) = $GUI_CHECKED Then
                    GUISetAccelerators($aAccelKeys)
                    $EnterSubmit = True
                Else
                    GUISetAccelerators(0)
                    $EnterSubmit = False
                EndIf
            Case $bsearch
                $RWSearch1 = GUICtrlRead($RWSearch)
                $RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")

                _Focus_Accel("bsearch", $aAccelKeys) ; Call a function with suitable parameters <<<<<<<<<<<<<<<<<

                $url = "https://www.google.com/search?q=" & $RWSearch2
                SearchMenuExec()


            Case $bimages
                $RWSearch1 = GUICtrlRead($RWSearch)
                $RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")

                _Focus_Accel("bImages", $aAccelKeys) ; Call a function with suitable parameters <<<<<<<<<<<<<<<<<

                $url = "http://images.google.com/images?hl=en&q=" & $RWSearch2
                SearchMenuExec()
        EndSwitch
    WEnd
EndFunc   ;==>SearchMenu


Func SearchMenuExec()
    ClipPut($url)
    ShellExecute($url)
EndFunc   ;==>SearchMenuExec

Func _Focus_Accel($Focus, $aAccelKeys)

    $Focus = "bsearch"
    GUICtrlSetState(Eval($Focus), $GUI_DEFBUTTON)
    If $EnterSubmit Then
        GUISetAccelerators($aAccelKeys)
    Else
        GUISetAccelerators(0)
    EndIf

EndFunc
I have added a few comments as well - please ask if any of them are unclear. :)

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

#8 ·  Posted (edited)

Thank you for your reply Melba :)

It seems that something doesn't work.

Without the function (_Focus_Accel) it works fine.

With the function not (neither the Accelerator Keys nor the focus are updated).

........

You wrote in your reply that you didn't understand what I'm trying to do.

What I would like to do with the checkbutton is:

- when the checkbutton CB3 (Enter=Send) is checked

  I would like to view an inputbox of 1 line  

$RWSearch = GUICtrlCreateInput("", 16, 10, 270, 25)

 (with accelerators enabled and focus active on last used button)

- when the checkbutton CB3 (label: Enter=Send) is unchecked

 I would like to view an editbox of 3 lines

$RWSearch = GUICtrlCreateEdit("", 16, 10, 270, 65)

(with accelerators disabled and focus active on last used button

I hope I made myself clear :)

Edited by remin

Share this post


Link to post
Share on other sites

remin,

I think I understand now. :)

I would code something like that rather differently. Most importantly I would create the GUI just once and then hide/show it as required - that way you do not need an ini file as the various values can be stored within the script itself. I have also shown how you can use a 2D array to have as many buttons as you want - although you will have to develop an algorithm to position them within your GUI, as well as making the GUI big enough to hold them. ;)

Take a look at this and see if it does what you want - then we can then look to developing the button algorithm:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>

HotKeySet("^4", "SearchMenu")

; These need to be Global as we retain their values between function calls
Global $RWSearch, $Focus = 9999

; Create an array to hold button data: ["Title", ControlID, "url to use"]
Global $aButton[3][3] = [[2, 0, 0], _
                        ["Search", -1, "https://www.google.com/search?q="], _
                        ["Images", -1, "http://images.google.com/images?hl=en&q="]]

$Form5 = GUICreate("Search Menu", 345, 140, @DesktopWidth * 0.65, @DesktopHeight * 0.21)
$textGoogle = GUICtrlCreateLabel("Google:", 20, 90, 100, 20)
For $i = 1 To $aButton[0][0]
    $aButton[$i][1] = GUICtrlCreateButton($aButton[$i][0], 45 + ($i * 65), 90, 60, 20)
Next
$CB3 = GUICtrlCreateCheckbox("Enter=Send (^Enter=Enter)", 110, 120, 145, 20)

GUISetState(@SW_HIDE)

While 1
    Sleep(10)
WEnd

Func SearchMenu()

    ; Check state of checkbox
    If GUICtrlRead($CB3) = $GUI_CHECKED Then
        ; Create correct sized input
        $RWSearch = GUICtrlCreateInput("", 16, 10, 270, 25, $ES_WANTRETURN)
        ; Set accel key
        If $Focus <> 9999 Then
            Local $aAccelKeys[1][2] = [["{ENTER}", $Focus]]
            GUISetAccelerators($aAccelKeys)
        EndIf
    Else
        ; Create correct sized input
        $RWSearch = GUICtrlCreateEdit("", 16, 10, 270, 65, BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
        ; Clear Accel key
        GUISetAccelerators(0)
    EndIf

    ; Set the Default Key
    GUICtrlSetState($Focus, $GUI_DEFBUTTON)

    ; Show GUI
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ; Delete search box
                GUICtrlDelete($RWSearch)
                ; Hide GUI
                GUISetState(@SW_HIDE)
                ExitLoop
            Case $CB3
                ; Delete current edit control
                GUICtrlDelete($RWSearch)
                ; Creat new edit control and adjust Accel keys as required
                If GUICtrlRead($CB3) = $GUI_CHECKED Then
                    ; Create correct sized input
                    $RWSearch = GUICtrlCreateInput("", 16, 10, 270, 25, $ES_WANTRETURN)
                    If $Focus = 9999 Then
                        ; No focus set so uncheck
                        GUICtrlSetState($CB3, $GUI_UNCHECKED)
                    Else
                        ; Set accel key
                        Local $aAccelKeys[1][2] = [["{ENTER}", $Focus]]
                        GUISetAccelerators($aAccelKeys)
                    EndIf
                Else
                    ; Create correct sized input
                    $RWSearch = GUICtrlCreateEdit("", 16, 10, 270, 65, BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
                    ; Clear accel key
                    GUISetAccelerators(0)
                EndIf

            Case Else
                ; Look through the buttons
                For $i = 1 To $aButton[0][0]
                    If $nMsg = $aButton[$i][1] Then
                        ; Found a button
                        $RWSearch1 = GUICtrlRead($RWSearch)
                        $RWSearch2 = StringRegExpReplace($RWSearch1, "(\s+)", "+")
                        ; Set focus for next round
                        $Focus = $aButton[$i][1]
                        $url = $aButton[$i][2] & $RWSearch2

                        MsgBox($MB_SYSTEMMODAL, "Actioning", $aButton[$i][0] & @CRLF & @CRLF & $url)

                        ;SearchMenuExec($url)

                        ; No point in looking further
                        ExitLoop
                    EndIf
                Next
        EndSwitch
    WEnd

EndFunc   ;==>SearchMenu


Func SearchMenuExec($url)
    ClipPut($url)
    ShellExecute($url)
EndFunc   ;==>SearchMenuExec
Let me know how it works - and if you have any questions. :)

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

#10 ·  Posted (edited)

:thumbsup: Thank you very much Melba! 

You've dedicated a lot of time to my script!

I resolved all my questions.

The only thing I didn't use is the dynamic button creator.

Most Urls's of my Cases are constructed and there 

is a lot more text then the single Url. :)

Just a few remarks:

--------

While 1
    Sleep(10)
WEnd
Can I change it to Sleep(1000) or Sleep(10000)?
Higher values takes less CPU I've noted.
(I still don't understand very well what it does)
--------
I haven't added (for now) 
        ExitLoop

to all Case.

It seems to work fine without.

But I added to Case $GUI_EVENT_CLOSE:
        GuiDelete($Form5)
        ExitLoop

Is it correct to do it without ExitLoop in all other CASE

--------
Now when my Search Script is ready I'll add it to my general script file with other scripts, isn't it?
There will no conflicts I believe because the search script is invoked by hotkey isn't it?
--------
You've told me to write the global keys at the top of the file.
I have many hotkeys in my general script file.
Do I have to declare the global keys below the hotkeys or can it also be between the hotkeys?
 
Is this correct?
<includes.......>

HotKeySet("^4", "SearchMenu")
Global $url,$Currenttab .....
HotKeySet("^5", "emptyclipb")
HotKeySet("^+5", "empty2ndclipb")

--------

You wrote in a previous reply:

$State = IniRead($MyFile, "CheckBox", "CB3", 0)         
If $State = 1 Then ; == means case-sensitive string comparison, so not needed here <<<<<<<<<<<<<<<<<<<<<<<

I still don't understand exactly what you mean by this.

--------

My convertion from AHK to AI is almost done :)

One thing I haven't converted till now:

My autotext lines

:?*:\\em::myname@domain.com 
etc..

This isn't possible in autoit isn't it?

--------

Melba, thank you again for all you did.

I'm glad I switched to autoit.

Have a nice day.

Edited by remin

Share this post


Link to post
Share on other sites

remin,

 

I'm glad I switched to autoit

Good. I am glad you like the script - and it is my pleasure to help you. :)

Now to all the questions:

 

Can I change it to Sleep(1000) or Sleep(10000)?

Sleep(10) is the lowest script pause you can have and is quite suffcient to give the CPU time to breathe and personally I have never seen for than 1% CPU use on my machine when using that value. Certainly you can use a bigger value - but I doubt if would make that much difference to this script. :)

I haven't added (for now) ExitLoop to all Case

You do not need to. The only reason that it is present when we look for the buttons is that once we have found the pressed button there is no point looking any further. So we use ExitLoop to exit from the For $i = 1 To $aButton[0][0] loop. As the other Case codes do not use loops there is no need to exit them. ;)

 

There will no conflicts I believe because the search script is invoked by hotkey isn't it?

I have no idea as I have not seen the other script. :huh:

 

Do I have to declare the global keys below the hotkeys or can it also be between the hotkeys?

Autoit is pretty tolerant about where you place things, but I suggest that you try and structure your code in a sensible way - it helps debugging and is a boon when you return to a script after some time. I always try to structure my scripts like this:

Directives
Include files
Options
HotKeys
Global declarations
Main code
Functions
Handlers
Obviously you may wish to do something different, but coding in a structured manner, whatever it is, makes life much easier, believe me! ;)

 

case-sensitive string comparison, so not needed here <<<<<<<<<<<<<<<<<<<<<<<

I still don't understand exactly what you mean by this

AutoIt normally compares using the = operator. If both sides are numeric it does a numeric comparison; if both sides are strings it does a case-insensitive ASCII comparison; if there is a mix of datatypes it can go very wrong, so force the 2 sides into type you want using String or Number. If you use the == operator then AutoIt forces both sides into strings and does a case-sensitive ASCII comparison - this takes longer than a simple compare and so you should only use it if you really require such a comparison. In this case you are comparing 2 numbers and so there is no need. :)

 

:?*:em::myname@domain.com

I have no idea what an "autotext" line is supposed to do - so I cannot comment on whether AutoIt can do whatever it is. If you explain what you are trying to do we can probably come up with a solution. ;)

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

#12 ·  Posted (edited)

Good. I am glad you like the script - and it is my pleasure to help you.  :)

 

 

Thank you :)

Sleep(10) is the lowest script pause you can have and is quite suffcient to give the CPU time to breathe and personally I have never seen for than 1% CPU use on my machine when using that value. Certainly you can use a bigger value - but I doubt if would make that much difference to this script.  :)

 

The higher the sleep value the slower the response of the script isn't it?

AutoIt normally compares using the = operator. If both sides are numeric it does a numeric comparison; if both sides are strings it does a case-insensitive ASCII comparison; if there is a mix of datatypes it can go very wrong, so force the 2 sides into type you want using String or Number. If you use the == operator then AutoIt forces both sides into strings and does a case-sensitive ASCII comparison - this takes longer than a simple compare and so you should only use it if you really require such a comparison. In this case you are comparing 2 numbers and so there is no need.  :)

 

I still don't get it totally.

My code:

     $State = IniRead($MyFile,"CheckBox",$cbarray[$i],0)
     If $State == 1 Then
       GUICtrlSetState(eval($cbarray[$i]), BitOR($GUI_ENABLE, $GUI_CHECKED))
     Else
       GUICtrlSetState(eval($cbarray[$i]), BitOR($GUI_ENABLE, $GUI_UNCHECKED))
     EndIf

Do i have to change it like this  (is that what you mean?)

If IniRead($MyFile,"CheckBox",$cbarray[$i],0) Then
Else
Endif
I have no idea what an "autotext" line is supposed to do - so I cannot comment on whether AutoIt can do whatever it is. If you explain what you are trying to do we can probably come up with a solution.  ;)

 

 

Sorry :)
Autotext is the name of ahk text expanding.
 
p.e. in this case 
:?*:em::myname@domain.com
 
Typing "em" will expand to the email address "myname@domain.com"
 
Thanks again :)
 
ps:
 
In my search script I will use 3 global arrays with long strings inside.
I tried to declare the arrays above the scripts like this:
Global $BClass[3]
etc

and then use the array within the function like this:

$BClass[3] = ["text", "text", "text"]

but that doesn't seems to work.

What did I wrong Melba?
 
.
Edited by remin

Share this post


Link to post
Share on other sites

remin,

 

The higher the sleep value the slower the response of the script isn't it?

But only in MessageLoop mode where you should just use the built-in pause in GUIGetMsg - that waits up to 12-15ms when the CPU is very busy while the return almost instantaneous if it is idle. In OnEvent mode, and here when only HotKeys are used, the Sleep period has no effect. This is one reason I would not comment on the interaction between your current script and the one with which you wish to merge it - until I see exactly what is involved I am not prepared to say whether problem might arise. ;)

 

[=/==] I still don't get it totally

In this case as you are comparing numbers, you do not need a case-sensitive string comparison. All you need do is replace the == operator with =:

If $State == 1 Then

; should become

If $State = 1 Then

Autotext is the name of ahk text expanding

I see. In Autoit you have 2 options:

 

- 1. Use a variable to contain the expanded text:

; Declare the content
$sEM = "myname@domain.com"

; And use it like this
$url = $sEM & "\section\item.html"

$url will then hold myname@domain.comsectionitem.html

-2. Use the Abbrev manager in SciTE4AutoIt3 to create an abbreviation which you can expand as you type. Look under the <Help - SciTE Help - SciTE4AutoIt3 - User Abbreviations> and <Help - SciTE Help - Extra Utilities - Abbrev Manager> to learn more. If you do not have the full SciTE4AutoIt3 package I highly recommend that you download it from here - you get lots of helpful utilities to help you code in AutoIt. ;)

M23

1 person likes this

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

#14 ·  Posted (edited)

I'll read more about GUIGetMsg :)

In this case as you are comparing numbers, you do not need a case-sensitive string comparison. All you need do is replace the == operator with =:

 

 

Oh.. I see the error I've made :sweating:   :)

Thank you also for the autotext info.

I'll study it a bit more.

I added one more thing in my previous post but you were too fast answering ;)

------------

In my search script I will use 3 global arrays with long strings inside.
I tried to declare the arrays above the scripts like this:
Global $BClass[3]
etc

and then use the array within the function like this:

$BClass[3] = ["text", "text", "text"]

but that doesn't seems to work.

What did I wrong Melba?
------------
 
Remin

Edited by remin

Share this post


Link to post
Share on other sites

remin,

 

you were too fast answering

I will try to do worse in future. :D

You need to declare the arrays and their contents at the same time - otherwise you can only assign individual elements:

; This will work
Global $BClass[3] = ["text", "text", "text"]

; As will this if you use the Beta
Global $BClass[] = ["text", "text", "text"]

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

; Or you need to declare the array at the beginning of the script
Global $BClass[3]

; And then assign the elements individually
$BClass[0] = "text"
$BClass[1] = "text"
$BClass[2] = "text"
Al clear? :)

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

You need to declare the arrays and their contents at the same time - otherwise you can only assign individual elements:

 

Or just declare them in the function self?

Melba, thank you very much for the time you've dedicated to my script.

Thanks for all :)

Share this post


Link to post
Share on other sites

remin,

 

Or just declare them in the function self?

You can always redeclare arrays - but you still need to either declare the contents at the same time or assign the individual elements separately. ;)

As always, my pleasure to help. :)

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

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

    • kawliga751
      By kawliga751
      I have a workplace GUI that has a search field function that pulls up customer records to allow changes. I am attempting to 1)LOGIN 2)Enter Search field, enter a number and then {ENTER} 3)change specific field once customer record loads. I have very limited experience in GUI manipulation but I am able to login using the below:
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/ASAG/index.htm') Call ("RacksheetSignIn") Func RacksheetSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/RackSheets/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc However I can't seem to use the _IEGetObjByName or Mouseclick to focus on the search field to allow me to enter my search criteria. When I "inspect element" in the Search field I get the attached:
       
      Any help would be MUCH appreciated
       
       
       

    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • FMS
      By FMS
      Hello,
      As I was searching this forum I came along something intresting what was new to me.
      CUI/GUI hybrid.
      Whish sounds very usefull to me to compile it all into 1 script.
      So i was fideling around whit it but couldn't get it to work.
      In the real script (not this simplified version) i got a lot of functions whish i can use whan talking to it by commandline and switches.
      I could not get this to work and hope somebody could give me some pointers on how to make it work.
      Also I was hoping iff somebody could help me whit the /? function?
      (I don't know how to output the help text back to the commandline or the function that can help me do it)
      please advice and thanks in advanced.
      #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #include <Process.au3> #include <Array.au3> If $CmdLine[0] = 0 Then If _ProcessGetName(ProcessGetParent(@AutoItPID)) = "cmd.exe" Then ;ConsoleWrite("Program was started in CMD" & @CRLF) If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!") If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!") For $i = 1 To $CmdLine[0] Step 2 If $CmdLine[$i] = "/switch" Then MsgBox(64, "Passed Parameters", "/switch is " & $CmdLine[$i+1]) If $CmdLine[$i] = "/?" Then MsgBox(64, "Passed Parameters", "/? " ) Next _ArrayDisplay($CmdLine) Else #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 239, 65, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 32, 24, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 120, 24, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 button1() Case $button2 button2() EndSwitch WEnd EndIf EndIf Exit Func button1() MsgBox(16, "title", "button1()!") EndFunc Func button2() MsgBox(16, "title", "button1()!") EndFunc Func ProcessGetParent($i_PID) ;get PID from parent process done by SmOke_N Local $TH32CS_SNAPPROCESS = 0x00000002 Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0) If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_PID) Local $tagPROCESSENTRY32 = _ DllStructCreate( _ "dword dwsize;" & _ "dword cntUsage;" & _ "dword th32ProcessID;" & _ "uint th32DefaultHeapID;" & _ "dword th32ModuleID;" & _ "dword cntThreads;" & _ "dword th32ParentProcessID;" & _ "long pcPriClassBase;" & _ "dword dwFlags;" & _ "char szExeFile[260]" _ ) DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32)) Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32) Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_PID) Local $a_pnext, $i_return = 0 If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) If $i_return Then Return $i_return Return $i_PID EndIf While @error = 0 $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") If $i_return Then ExitLoop $i_return = $i_PID ExitLoop EndIf WEnd DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) Return $i_return EndFunc ;==>ProcessGetParent  
    • Jibberish
      By Jibberish
      Hello,
      I have used this forum to get help many times. I thought it was time to (hopefully) help others.
      I created a script that reads a text file with a list of videos, displays the videos in a GUI with checkboxes next to the names, and displays the selected videos. This will become a part of a larger script I am creating to test a video player. The tough part for me was creating the GUI and Dynamic list of videos. I had a lot of trouble finding samples to help me, but finally found one  written by Melba23. The link is in the code, so he gets credit for helping! I also have not used arrays much and they are very picky about looping through the arrays without getting the dreaded error " Array variable has incorrect number of subscripts or subscript dimension range exceeded."  However diligence paid off!
      To run this code, take the video names commented below and create a videos.txt file in your script execution directory. You can put however many video names in this list. Thus the dynamic features of the code.
      Cheers!
      Jibberish
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = @ScriptDir & "\videos.txt" ;~ Videos in videos.txt are: ;~ bbb_1080_60s.mp4 ;~ bbb_1080_60s_1.mp4 ;~ bbb_1080_60s_2.mp4 ;~ tos_4K_60s_HEVC.mp4 ;~ tos_4K_60s_HEVC_1.mp4 ;~ tos_4K_60s_HEVC_2.mp4 ;~ ;~ Additional videos can be added to this list. The functions are Dynamic. Dim $aMediaManifest Local $aArrayFile Local $aVideos Local $sVideoName Local $i ; MAIN ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) Local $iVideoCount = UBound($aArrayFile) -1 ; Get the number of videos - 1 to prevent errors _ArrayDelete($aArrayFile, 0) ;Counter just gets in the way ; Move backwards through the array deleting the blank lines For $i = $iVideoCount - 1 To 0 Step -1 If $aArrayFile[$i] = "" Then _ArrayDelete($aArrayFile, $i) EndIf Next $aVideos = DisplayVideos($aArrayFile) $iVideoCount = UBound($aArrayFile) -1 _ArrayDisplay($aVideos) ; Display the checked videos ;~ End of MAIN ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; GUI to display Videos in checkboxes ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayVideos($aArrayFile) Local $iTop = -1 Local $iLeft = -1 Local $iWidth Local $iHeight = $iVideoCount * 30 Local $iL = 10 Local $iT = 10 Local $iRow = 0 Local $aVideo Local $iA = 0, $iB = 0 Local $sFill = "" $iMMCount = UBound($aArrayFile) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedVideos[$iMMCount] ; Put the Video File Names into an Array $hGUI = GUICreate("Video Checkbox", $iLeft, $iTop, $iWidth, $iHeight) GUICtrlCreateLabel("Videos", 180, $iT) $iT = $iT + 30 ; This is a great example of using arrays to create GUI check boxes or radio buttons For $i = 0 To $iMMNewCount Step 1 $sMP4Text = $aArrayFile[$i] $aGUICheckbox[$i] = GUICtrlCreateCheckbox($sMP4Text, 30, $iT) $iT += 30 Next $idClose1 = GUICtrlCreateButton("Start", $iL, $iT) GUISetState(@SW_SHOW) ; This section reads the checkboxes and puts the video names in an array in their original position ; in case this is important (as it is to me) ; This was the toughest part to code, and I found no samples online until I saw Melba23's sample here: ; https://www.autoitscript.com/forum/topic/119843-dynamic-gui-problem/#comment-832672 ; I got this working with only a little modification. THANK YOU MELBA23 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idClose1 For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aGUICheckbox[$i]) Case $GUI_CHECKED $aCheckedVideos[$i] = $aArrayFile[$i] Case $GUI_UNCHECKED EndSwitch Next ExitLoop EndSwitch WEnd GUIDelete($hGUI) Return $aCheckedVideos EndFunc ;==>DisplayVideos