Jump to content

GUI butttons - highlight


Go to solution Solved by Melba23,

Recommended Posts

Hi guys

I am creating a GUI with buttons containing bitmap pictures!

The gui will be controlled by a keyboard/gamepad, and not the mouse.

So highlighting of the active button is important. Right now it's only highlighted by a very thin blue line. (See screenshot)

GUI_menu_with_bitmap.png

 

Is there any way to create a thicker and more clear highlighting?

 

Here is my example code:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Mainscript()

Func Mainscript()
    Local $Button_1, $Button_2, $msg
    GUICreate("", 634, 320) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)
    $Button_1 = GUICtrlCreateButton("Button 1", 23, 30, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\Planatronics wireless headset new.bmp")

    $Button_2 = GUICtrlCreateButton("Button 2", 350, 30, 262, 262, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")


    GUISetBkColor(0xFFFFFF)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop




             Case $msg = $Button_1
;_______________________Button 1 START_______________________;

MsgBox(0,"","Button 1")

;_______________________Button 1 END_______________________;




             Case $msg = $Button_2
;_______________________Button 2 START_______________________;

MsgBox(0,"","Button 2")

;_______________________Button 2 END_______________________;




        EndSelect
    WEnd

EndFunc   ;==>Mainscript

- David

Link to comment
Share on other sites

  • Moderators
  • Solution

david1337,

Perhaps you could use background labels like this:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

Mainscript()

Func Mainscript()
    Local $Button_1, $Button_2, $msg

    GUICreate("", 634, 320) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)
    $cLabel_1 = GUICtrlCreateLabel("", 18, 25, 272, 272)
    GUICtrlSetBkColor($cLabel_1, 0x00FF00)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    $Button_1 = GUICtrlCreateButton("Button 1", 23, 30, 262, 262, $BS_BITMAP)
    
    $cLabel_2 = GUICtrlCreateLabel("", 345, 25, 272, 272)
    GUICtrlSetBkColor($cLabel_2, 0xFF0000)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    $Button_2 = GUICtrlCreateButton("Button 2", 350, 30, 262, 262, $BS_BITMAP)
    
    GUISetBkColor(0xFFFFFF)

    GUISetState()

    GUICtrlSetState($Button_1, $GUI_FOCUS)
    $hActive = GUICtrlGetHandle($Button_1)

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
             Case $msg = $Button_1
                MsgBox(0,"","Button 1")
             Case $msg = $Button_2
                MsgBox(0,"","Button 2")
        EndSelect

        $hCurrFocus = _WinAPI_GetFocus()
        If $hCurrFocus <> $hActive Then
            $hActive = $hCurrFocus
            Switch $hActive
                Case GUICtrlGetHandle($Button_1)
                    GUICtrlSetBkColor($cLabel_1, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_2, 0xFF0000)
                Case GUICtrlGetHandle($Button_2)
                    GUICtrlSetBkColor($cLabel_2, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_1, 0xFF0000)
            EndSwitch
        EndIf

    WEnd

EndFunc   ;==>Mainscript
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba, just the guy I was hoping for!

That is brilliant. Works exactly how I wanted it to! :)

Thanks you so much!

Additional question: (less important though :)) In the original script I have multiple rows with buttons. I can only navigate/jump from button to button from left to right, and right to left.

Would it be possible to jump up/down? So if I press the down arrow on my keyboard, the highlight will jump to the button below .

See script with 2 rows:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Mainscript()

Func Mainscript()

    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)
    $Button_1 = GUICtrlCreateButton("Button 1", 50, 30, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\Planatronics wireless headset new.bmp")

    $Button_2 = GUICtrlCreateButton("Button 2", 350, 30, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")

    $Button_3 = GUICtrlCreateButton("Button 3", 650, 30, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")

    $Button_4 = GUICtrlCreateButton("Button 4", 950, 30, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")

    $Button_5 = GUICtrlCreateButton("Button 5", 50, 330, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\Planatronics wireless headset new.bmp")

    $Button_6 = GUICtrlCreateButton("Button 6", 350, 330, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")

    $Button_7 = GUICtrlCreateButton("Button 7", 650, 330, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")

    $Button_8 = GUICtrlCreateButton("Button 8", 950, 330, 262, 262, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Blandet\Windows Styling\Ikoner\_Mit tema_\PS Controller - Turn off.bmp")


    GUISetBkColor(0xFFFFFF)

    GUISetState() ; will display a dialog box with 2 buttons

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop




             Case $msg = $Button_1
;_______________________Button 1 UNDER HER_______________________;

MsgBox(0,"","Button 1")

;_______________________Button 1 OVER HER_______________________;




             Case $msg = $Button_2
;_______________________Button 2 UNDER HER_______________________;

MsgBox(0,"","Button 2")

;_______________________Button 2 OVER HER_______________________;




             Case $msg = $Button_3
;_______________________Button 3 UNDER HER_______________________;

MsgBox(0,"","Button 3")

;_______________________Button 3 OVER HER_______________________;




             Case $msg = $Button_4
;_______________________Button 4 UNDER HER_______________________;

MsgBox(0,"","Button 4")

;_______________________Button 4 OVER HER_______________________;




             Case $msg = $Button_5
;_______________________Button 5 UNDER HER_______________________;

MsgBox(0,"","Button 5")

;_______________________Button 5 OVER HER_______________________;




             Case $msg = $Button_6
;_______________________Button 6 UNDER HER_______________________;

MsgBox(0,"","Button 6")

;_______________________Button 6 OVER HER_______________________;



             Case $msg = $Button_7
;_______________________Button 7 UNDER HER_______________________;

MsgBox(0,"","Button 7")

;_______________________Button 7 OVER HER_______________________;



             Case $msg = $Button_8
;_______________________Button 8 UNDER HER_______________________;

MsgBox(0,"","Button 8")

;_______________________Button 8 OVER HER_______________________;




        EndSelect
    WEnd

EndFunc   ;==>Mainscript
Link to comment
Share on other sites

  • Moderators

david1337,

Not that hard to do:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

Global $aButton[9]

Mainscript()

Func Mainscript()

    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)
    
    ; Get the button controlIDs into an array
    $aButton[1] = GUICtrlCreateButton("Button 1", 50, 30, 262, 262)
    $aButton[2] = GUICtrlCreateButton("Button 2", 350, 30, 262, 262)
    $aButton[3] = GUICtrlCreateButton("Button 3", 650, 30, 262, 262)
    $aButton[4] = GUICtrlCreateButton("Button 4", 950, 30, 262, 262)
    $aButton[5] = GUICtrlCreateButton("Button 5", 50, 330, 262, 262)
    $aButton[6] = GUICtrlCreateButton("Button 6", 350, 330, 262, 262)
    $aButton[7] = GUICtrlCreateButton("Button 7", 650, 330, 262, 262)
    $aButton[8] = GUICtrlCreateButton("Button 8", 950, 330, 262, 262)

    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    GUICtrlSetState($aButton[1], $GUI_FOCUS)

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $cDummy_Up
                _Vertical_TabStop()
            Case $msg = $cDummy_Dn
                _Vertical_TabStop()
        EndSelect
    WEnd

#cs
    ; Perhaps easier to use a Switch structure:
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()
        EndSwitch
    WEnd
#ce

EndFunc   ;==>Mainscript

Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 1 To 8
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, 8) ; This is the magic bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ; and set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc
Please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

david1337,

That is the "magic" Mod messing up - I have always hated modular calculations!

Give me a moment.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

david1337,

I needed to start the array from 0 and not 1 - this works for me:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

Global $aButton[8]

Mainscript()

Func Mainscript()

    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)

    ; Get the button controlIDs into an array
    $aButton[0] = GUICtrlCreateButton("Button 1", 50, 30, 262, 262)
    $aButton[1] = GUICtrlCreateButton("Button 2", 350, 30, 262, 262)
    $aButton[2] = GUICtrlCreateButton("Button 3", 650, 30, 262, 262)
    $aButton[3] = GUICtrlCreateButton("Button 4", 950, 30, 262, 262)
    $aButton[4] = GUICtrlCreateButton("Button 5", 50, 330, 262, 262)
    $aButton[5] = GUICtrlCreateButton("Button 6", 350, 330, 262, 262)
    $aButton[6] = GUICtrlCreateButton("Button 7", 650, 330, 262, 262)
    $aButton[7] = GUICtrlCreateButton("Button 8", 950, 330, 262, 262)

    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    GUICtrlSetState($aButton[1], $GUI_FOCUS)

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $cDummy_Up
                _Vertical_TabStop()
            Case $msg = $cDummy_Dn
                _Vertical_TabStop()
        EndSelect
    WEnd

#cs
    ; Perhaps easier to use a Switch structure:
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()
        EndSwitch
    WEnd
#ce

EndFunc   ;==>Mainscript

Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To 7
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, 8) ; This is the magic bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            ConsoleWrite($iIndex & @CRLF)

            ; and set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

david1337,

No problem - do ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Okay now for the dumb question :>


After arranging the buttons into array, how do I make the case correct?

Case $msg = $Button[0]
MsgBox(0,"","Button 1 is clicked")


Case $msg = $aButton[0]
MsgBox(0,"","Button 1 is clicked")


Case $msg = $aButton1
MsgBox(0,"","Button 1 is clicked")


Case $msg = $Button1
MsgBox(0,"","Button 1 is clicked")

All the above gives me: "Case" statement with no matching "Select"or "Switch" statement.

Edited by david1337
Link to comment
Share on other sites

  • Moderators

david1337,

Have you placed the case statememts inside the Switch/Select structure like this?

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $cDummy_Up
                _Vertical_TabStop()
            Case $msg = $cDummy_Dn
                _Vertical_TabStop()
            Case $msg = $aButton[0]
                MsgBox(0,"","Button 1 is clicked")
            Case $msg = $aButton[1]
                MsgBox(0,"","Button 2 is clicked")
        EndSelect
    WEnd

#cs
    ; Perhaps easier to use a Switch structure:
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()
            Case $aButton[0]
                MsgBox(0,"","Button 1 is clicked")
            Case $aButton[1]
                MsgBox(0,"","Button 2 is clicked")
        EndSwitch
    WEnd
#ce
That works fine for me.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba,

I tried to implement both the highlighting and the up/down parts into the actual script. The up/down part went fine, but my brain can't figure out the highlighting label numbers!  :blink:

It's quite a mess! :o

Have been troubleshooting it for hours now, can you help me? :>

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

Global $aButton[8]

Mainscript()

Func Mainscript()

    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)

    ;Button controlIDs are sorted into arrays [1] - [7]


    $cLabel_1 = GUICtrlCreateLabel("", 45, 25, 266, 266)
    GUICtrlSetBkColor($cLabel_1, 0x00FF00)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    $aButton[0] = GUICtrlCreateButton("Button 1", 50, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\KODI02.bmp")

    $cLabel_2 = GUICtrlCreateLabel("", 345, 25, 266, 266)
    GUICtrlSetBkColor($cLabel_2, 0x00FF00)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    $aButton[1] = GUICtrlCreateButton("Button 2", 350, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Skype.bmp")

    $cLabel_3 = GUICtrlCreateLabel("", 645, 25, 266, 266)
    GUICtrlSetBkColor($cLabel_3, 0x00FF00)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    $aButton[2] = GUICtrlCreateButton("Button 3", 650, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Headset.bmp")

    $cLabel_4 = GUICtrlCreateLabel("", 945, 25, 266, 266)
    GUICtrlSetBkColor($cLabel_4, 0x00FF00)
    GUICtrlSetState($cLabel_4, $GUI_DISABLE)
    $aButton[3] = GUICtrlCreateButton("Button 4", 950, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Speaker.bmp")

    $cLabel_5 = GUICtrlCreateLabel("", 45, 325, 266, 266)
    GUICtrlSetBkColor($cLabel_5, 0x00FF00)
    GUICtrlSetState($cLabel_5, $GUI_DISABLE)
    $aButton[4] = GUICtrlCreateButton("Button 5", 50, 330, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\PS Controller - Turn off.bmp")

    $cLabel_6 = GUICtrlCreateLabel("", 345, 325, 266, 266)
    GUICtrlSetBkColor($cLabel_6, 0x00FF00)
    GUICtrlSetState($cLabel_6, $GUI_DISABLE)
    $aButton[5] = GUICtrlCreateButton("Button 6", 350, 330, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Fish2.bmp")

    $cLabel_7 = GUICtrlCreateLabel("", 645, 325, 266, 266)
    GUICtrlSetBkColor($cLabel_7, 0x00FF00)
    GUICtrlSetState($cLabel_7, $GUI_DISABLE)
    $aButton[6] = GUICtrlCreateButton("Button 7", 650, 330, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Fireplace.bmp")

    $cLabel_8 = GUICtrlCreateLabel("", 945, 325, 266, 266)
    GUICtrlSetBkColor($cLabel_8, 0x00FF00)
    GUICtrlSetState($cLabel_8, $GUI_DISABLE)
    $aButton[7] = GUICtrlCreateButton("Button 8", 950, 330, 256, 256, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\BILLEDE.bmp")


   GUISetBkColor(0xFFFFFF)

    GUICtrlSetState($aButton[1], $GUI_FOCUS)
    $hActive = GUICtrlGetHandle($aButton[1])


    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    GUICtrlSetState($aButton[1], $GUI_FOCUS)

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $cDummy_Up
                _Vertical_TabStop()
            Case $msg = $cDummy_Dn
                _Vertical_TabStop()


                             Case $msg = $aButton[0]
;_______________________Button 1 UNDER HER_______________________;

ShellExecute("C:\Program Files (x86)\Kodi\Kodi.exe")

Exit

;_______________________Button 1 OVER HER_______________________;




             Case $msg = $aButton[1]
;_______________________Button 2 UNDER HER_______________________;

Call("SkypeSubmenu")
Exit

;_______________________Button 2 OVER HER_______________________;




             Case $msg = $aButton[2]
;_______________________Button 3 UNDER HER_______________________;

Run("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0")
WinWaitActive("Sound")
send("{DOWN}")
send("!{s}")
WinClose("Sound")

   SplashTextOn("", "Default Sound: Wireless Headset", 380, 55)
   Sleep(2000)
   SplashOff()

Exit

;_______________________Button 3 OVER HER_______________________;




             Case $msg = $aButton[3]
;_______________________Button 4 UNDER HER_______________________;

Run("rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0")
WinWaitActive("Sound")
send("{DOWN 2}")
send("!{s}")
WinClose("Sound")

   SplashTextOn("", "Default Sound: TV/Speakers", 280, 55)
   Sleep(2000)
   SplashOff()

Exit

;_______________________Button 4 OVER HER_______________________;




             Case $msg = $aButton[4]
;_______________________Button 5 UNDER HER_______________________;


MsgBox(0,"","Button 5")


;_______________________Button 5 OVER HER_______________________;




             Case $msg = $aButton[5]
;_______________________Button 6 UNDER HER_______________________;


run("C:\WINDOWS\DreamAquarium.scr")

Exit

;_______________________Button 6 OVER HER_______________________;



             Case $msg = $aButton[6]
;_______________________Button 7 UNDER HER_______________________;


run("C:\Program Files (x86)\Fireplace 3D Screensaver\Fireplace 3D Screensaver.exe")
Exit

;_______________________Button 7 OVER HER_______________________;



             Case $msg = $aButton[7]
;_______________________Button 8 UNDER HER_______________________;

MsgBox(0,"","Button 8")


;_______________________Button 8 OVER HER_______________________;


        EndSelect





        $hCurrFocus = _WinAPI_GetFocus()
        If $hCurrFocus <> $hActive Then
            $hActive = $hCurrFocus
            Switch $hActive
                Case GUICtrlGetHandle($aButton[0])
                    GUICtrlSetBkColor($cLabel_1, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_2, 0xFF0000)
                Case GUICtrlGetHandle($aButton[1])
                    GUICtrlSetBkColor($cLabel_2, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_1, 0xFF0000)
                Case GUICtrlGetHandle($aButton[2])
                    GUICtrlSetBkColor($cLabel_3, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_4, 0xFF0000)
                Case GUICtrlGetHandle($aButton[3])
                    GUICtrlSetBkColor($cLabel_4, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_3, 0xFF0000)
                Case GUICtrlGetHandle($aButton[4])
                    GUICtrlSetBkColor($cLabel_5, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_6, 0xFF0000)
                Case GUICtrlGetHandle($aButton[5])
                    GUICtrlSetBkColor($cLabel_6, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_5, 0xFF0000)
                Case GUICtrlGetHandle($aButton[6])
                    GUICtrlSetBkColor($cLabel_7, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_8, 0xFF0000)
                Case GUICtrlGetHandle($aButton[7])
                    GUICtrlSetBkColor($cLabel_8, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_7, 0xFF0000)
            EndSwitch
        EndIf

    WEnd

EndFunc   ;==>Mainscript


















Func SkypeSubmenu()
    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 4)
    $aButton[0] = GUICtrlCreateButton("Button 1", 50, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Skype.bmp")

    $aButton[1] = GUICtrlCreateButton("Button 2", 350, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Skype - answer call.bmp")

    $aButton[2] = GUICtrlCreateButton("Button 3", 650, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Skype - end call.bmp")

    $aButton[3] = GUICtrlCreateButton("Button 4", 950, 30, 256, 256, $BS_BITMAP)
    GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Skype call Rasmus.bmp")

    $aButton[4] = GUICtrlCreateButton("Button 5", 50, 330, 256, 256, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\KODI02.bmp")

    $aButton[5] = GUICtrlCreateButton("Button 6", 350, 330, 256, 256, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\PS Controller - Turn off.bmp")

    $aButton[6] = GUICtrlCreateButton("Button 7", 650, 330, 256, 256, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Headset.bmp")

    $aButton[7] = GUICtrlCreateButton("Button 8", 950, 330, 256, 256, $BS_BITMAP)
;~     GUICtrlSetImage(-1, "C:\Scripts\Gamepad App Starter\Icons\Speaker.bmp")

    GUISetBkColor(0xFFFFFF)

    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    GUICtrlSetState($aButton[1], $GUI_FOCUS)

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $cDummy_Up
                _Vertical_TabStop()
            Case $msg = $cDummy_Dn
                _Vertical_TabStop()




             Case $msg = $aButton[0]
;_______________________Button 1 UNDER HER_______________________;

If ProcessExists("Skype.exe") Then
   SplashTextOn("", "Skype is already running", 280, 55)
   Sleep(1500)
   SplashOff()

Else
ShellExecute("C:\Program Files (x86)\Skype\Phone\Skype.exe", "/minimized")
  SplashTextOn("", "Skype is started", 280, 55)
   Sleep(1500)
   SplashOff()
EndIf

;_______________________Button 1 OVER HER_______________________;




             Case $msg = $aButton[1]
;_______________________Button 2 UNDER HER_______________________;

Send("!{PgUp}")  ;Shortcuts must be activated in Skype
Exit

;_______________________Button 2 OVER HER_______________________;




             Case $msg = $aButton[2]
;_______________________Button 3 UNDER HER_______________________;

Send("!{PgDn}")  ;Shortcuts must be activated in Skype
Exit

;_______________________Button 3 OVER HER_______________________;




             Case $msg = $aButton[3]
;_______________________Button 4 UNDER HER_______________________;

ShellExecute("C:\Program Files (x86)\Skype\Phone\Skype.exe", "/callto:rasmus-frost")
Exit

;_______________________Button 4 OVER HER_______________________;




             Case $msg = $aButton[4]
;_______________________Button 5 UNDER HER_______________________;


MsgBox(0,"","Button 5")


;_______________________Button 5 OVER HER_______________________;




             Case $msg = $aButton[5]
;_______________________Button 6 UNDER HER_______________________;

;Genvejstaster skal være slået til i Skype

MsgBox(0,"","Button 6")


;_______________________Button 6 OVER HER_______________________;



             Case $msg = $aButton[6]
;_______________________Button 7 UNDER HER_______________________;

;Genvejstaster skal være slået til i Skype

MsgBox(0,"","Button 7")


;_______________________Button 7 OVER HER_______________________;



             Case $msg = $aButton[7]
;_______________________Button 8 UNDER HER_______________________;

MsgBox(0,"","Button 8")


;_______________________Button 8 OVER HER_______________________;




        EndSelect
    WEnd

EndFunc   ;==> SkypeSubmenu























Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To 7
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, 8) ; This is the magic bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            ConsoleWrite($iIndex & @CRLF)

            ; and set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc
Edited by david1337
Link to comment
Share on other sites

  • Moderators

david1337,

 

It's quite a mess!

That is putting it mildly!

I have cleaned it up and introduced you to a few new concepts - mainly aimed at saving the typing fingers when creating large numbers of controls which are located in a grid fashion:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

Global $aButton[8], $aLabel[8]

; Put your image paths in this array
Global $aImage[8] = ["Image_Path_1", "Image_Path_2", "Image_Path_3", "Image_Path_4", "Image_Path_5", "Image_Path_6", "Image_Path_7", "Image_Path_8"]

Mainscript()

Func Mainscript()

    GUICreate("", 1265, 625) ; will create a dialog box that when displayed is centered]
    GUISetBkColor(0xFFFFFF)

    Opt("GUICoordMode", 4)

    ; Create labels
    For $i = 0 To 1
        For $j = 0 To 3
            $iIndex = $j + ($i * 4)
            $aLabel[$iIndex] = GUICtrlCreateLabel("", 45 + (300 * $j), 25 + (300 * $i), 266, 266)
            GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF)
            GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE)
        Next
    Next

    ; Create buttons
    For $i = 0 To 1
        For $j = 0 To 3
            $iIndex = $j + ($i * 4)
            $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 50 + (300 * $j), 30 + (300 * $i), 256, 256, $BS_BITMAP)
            GUICtrlSetImage($aButton[$iIndex], $aImage[$iIndex])
        Next
    Next

    ; Set default button
    GUICtrlSetState($aButton[0], $GUI_FOCUS)
    GUICtrlSetBkColor($aLabel[0], 0x00FF00)
    $hActive = GUICtrlGetHandle($aButton[0])

    ; Create dummy controls
    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()
            Case $aButton[0]
;_______________________Button 1 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 1")
;_______________________Button 1 OVER HER_______________________;
            Case $aButton[1]
;_______________________Button 2 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 2")
;_______________________Button 2 OVER HER_______________________;
            Case $aButton[2]
;_______________________Button 3 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 3")
;_______________________Button 3 OVER HER_______________________;
            Case $aButton[3]
;_______________________Button 4 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 4")
;_______________________Button 4 OVER HER_______________________;
            Case $aButton[4]
;_______________________Button 5 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 5")
;_______________________Button 5 OVER HER_______________________;
            Case $aButton[5]
;_______________________Button 6 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 6")
;_______________________Button 6 OVER HER_______________________;
            Case $aButton[6]
;_______________________Button 7 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 7")
;_______________________Button 7 OVER HER_______________________;
            Case $aButton[7]
;_______________________Button 8 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 8")
;_______________________Button 8 OVER HER_______________________;
        EndSwitch

        ; Get focused control
        $hCurrFocus = _WinAPI_GetFocus()
        ; If it has changed
        If $hCurrFocus <> $hActive Then
            ; See if it is a button
            For $i = 0 To 7
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To 7
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)
                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript

Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To 7
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, 8)
            ; And set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc
Look over the code and do ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Wow haha! What I meant with "mess" was this part:

Case GUICtrlGetHandle($aButton[0])
                    GUICtrlSetBkColor($cLabel_1, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_2, 0xFF0000)
                Case GUICtrlGetHandle($aButton[1])
                    GUICtrlSetBkColor($cLabel_2, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_1, 0xFF0000)
                Case GUICtrlGetHandle($aButton[2])
                    GUICtrlSetBkColor($cLabel_3, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_4, 0xFF0000)
                Case GUICtrlGetHandle($aButton[3])
                    GUICtrlSetBkColor($cLabel_4, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_3, 0xFF0000)
                Case GUICtrlGetHandle($aButton[4])
                    GUICtrlSetBkColor($cLabel_5, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_6, 0xFF0000)
                Case GUICtrlGetHandle($aButton[5])
                    GUICtrlSetBkColor($cLabel_6, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_5, 0xFF0000)
                Case GUICtrlGetHandle($aButton[6])
                    GUICtrlSetBkColor($cLabel_7, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_8, 0xFF0000)
                Case GUICtrlGetHandle($aButton[7])
                    GUICtrlSetBkColor($cLabel_8, 0x00FF00)
                    GUICtrlSetBkColor($cLabel_7, 0xFF0000)

But you referred to my entire script! :lol:

I didn't know that you could create a GUI like that. It's much cleaner as you put it.

I have much to learn, as I am still in the early Padawan years! :>

Once again thanks for a very detailed and qualified help Melba!

David

Edited by david1337
Link to comment
Share on other sites

  • 8 months later...

i have been working on this code trying to  make it work with a set of images i get from a xml file...  i haven't gotten that far yet i'm just setting the image count and later will get that  here is the code i have so far....

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <Skin.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include "GUIScrollbars_Ex.au3"

#include ".\Skins\Cosmo.au3"
#include "_UskinLibrary.au3"

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))


Global $X = 195, $Count = 0, $Width = 1250, $Height = 750
Global $sImagePath = @ScriptDir & "\Imgs\"

; Put your image paths in this array
;Global $aImage[8] = [$sImagePath & "League of Legends.bmp", $sImagePath & "Team Fortress 2.bmp", "Image_Path_3", "Image_Path_4", "Image_Path_5", "Image_Path_6", "Image_Path_7", "Image_Path_8"]

Global $aImage[4000], $Button[4000] , $aLabel[4000], $aButton[4000], $aLabel[4000]
Global $imgCount = 100


MainGui()

Func MainGui()
   $MainGUI = GUICreate("", $Width, $Height) ; will create a dialog box that when displayed is centered]
    Opt("GUICoordMode", 20)

  For $i = 1 To $imgCount
        $X += 100
     Next

    _GUIScrollbars_Generate($MainGUI, 0, $X)
   GUICtrlSetResizing(-1, $GUI_DOCKAUTO)


    ; Create labels
    For $i = 0 To $imgCount - 1
       ; $Count += 1
        For $j = 0 To 3
            $iIndex = $j + ($i * 4)
            $aLabel[$iIndex] = GUICtrlCreateLabel("", 45 + (300 * $j), 25 + (300 * $i), 266, 266)
            GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF)
            GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE)
        Next
    Next

    ; Create buttons
    For $i = 0 To $imgCount - 1
       ; $Count += 1
        For $j = 0 To 3
            $iIndex = $j + ($i * 4)
            $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 50 + (300 * $j), 30 + (300 * $i), 256, 256, $BS_BITMAP)
            GUICtrlSetImage($aButton[$iIndex], $aImage[$iIndex])
        Next
    Next


    ; Set default button
    GUICtrlSetState($aButton[0], $GUI_FOCUS)
    GUICtrlSetBkColor($aLabel[0], 0x00FF00)
    $hActive = GUICtrlGetHandle($aButton[0])

    ; Create dummy controls
    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()

            Case $aButton[$i]
                  MsgBox($MB_SYSTEMMODAL, "Pressed", $aButton[$i])
        EndSwitch


        ; Get focused control
        $hCurrFocus = _WinAPI_GetFocus()
        ; If it has changed
        If $hCurrFocus <> $hActive Then
            ; See if it is a button
            For $i = 0 To $imgCount
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $imgCount
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)
                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
     WEnd

EndFunc   ;==>Mainscript

Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To 4
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, $imgCount)
            ; And set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc

Now a couple issues i am having and maybe you can see the simple mistak9s)

1.)  when button is clicked  it starts with saying button presses was the number 403 and stops at 504
2.)  i cant go up and down ,  i can go down 3 and then it stops
3.) the highlighting only goes so far and just stops which is actually 503
4.) its showing more than 100 buttons
5.) the scroll bar should stop at the last row and i cant seem to get that to work either

I feel i am so close but so far :(

any help and explanation to what i am missing would be awesome

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

Here is the code reworked to show any number of buttons. All you need to do is set the $aImage array to the size you require and then set the required max $iDialog_Width & $iDialog_Depth sizes. The code then determines suitable row/column values and button size, draws the buttons and then resizes the dialog to make it look as if it was designed to fit:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

; Put your image paths in this array - sized to match required number of buttons
Global $aImage[12]; = ["Image_Path_1", "Image_Path_2", "Image_Path_3", "Image_Path_4", "Image_Path_5", "Image_Path_6", "Image_Path_7", "Image_Path_8"]
$iCount = UBound($aImage)
; Create array to hold button and label ControlIDs
Global $aButton[$iCount], $aLabel[$iCount]

Mainscript()

Func Mainscript()

    ; Set max dialog size
    $iDialog_Width = 1265
    $iDialog_Depth = 625

    ; Determine aspect ratio of preset sizes
    $nAspect = Floor(($iDialog_Width - 10) / ($iDialog_Depth - 10))
    ; Determine best combination of rows and columns
    Local $iRow_Count, $iCol_Count
    For $i = 1 To $iCount
        $iRow_Count = $i
        $iCol_Count = $i * $nAspect
        If ($iRow_Count * $iCol_Count) >= $iCount - 1 Then ExitLoop
    Next
    ; Set button size
    $iButton_Dim = Floor(($iDialog_Width - 10) / $iCol_Count)

    ; Creqate dialog
    $hDialog = GUICreate("", $iDialog_Width, $iDialog_Depth) ; will create a dialog box that when displayed is centered]
    GUISetBkColor(0xFFFFFF)

    Opt("GUICoordMode", 4)

    ; Create variables to hold actual dialog size
    Local $iMax_Width, $iMax_Depth

    ; Create labels
    For $i = 0 To $iRow_Count - 1
        For $j = 0 To $iCol_Count - 1
            $iIndex = $j + ($i * $iCol_Count)
            If $iIndex > $iCount - 1 Then ExitLoop
            $aLabel[$iIndex] = GUICtrlCreateLabel("", 10 + ($iButton_Dim * $j), 10 + ($iButton_Dim * $i), $iButton_Dim - 10, $iButton_Dim - 10)
            GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF)
            GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE)
            GUICtrlSetResizing($aLabel[$iIndex], $GUI_DOCKALL)
            ; Determine actual dialog size required
            If $iButton_Dim * ($j + 1) > $iMax_Width Then
                $iMax_Width = $iButton_Dim * ($j + 1)
            EndIf
            If $iButton_Dim * ($i + 1) > $iMax_Depth Then
                $iMax_Depth = $iButton_Dim * ($i + 1)
            EndIf
        Next
    Next

    ; Create buttons
    For $i = 0 To $iRow_Count - 1
        For $j = 0 To $iCol_Count - 1
            $iIndex = $j + ($i * $iCol_Count)
            If $iIndex > $iCount - 1 Then ExitLoop
            $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 15 + ($iButton_Dim * $j), 15 + ($iButton_Dim * $i), $iButton_Dim - 20, $iButton_Dim - 20, $BS_BITMAP)
            GUICtrlSetImage($aButton[$iIndex], $aImage[$iIndex])
            GUICtrlSetResizing($aButton[$iIndex], $GUI_DOCKALL)
        Next
    Next

    ; Set default button
    GUICtrlSetState($aButton[0], $GUI_FOCUS)
    GUICtrlSetBkColor($aLabel[0], 0x00FF00)
    $hActive = GUICtrlGetHandle($aButton[0])

    ; Create dummy controls
    $cDummy_Up = GUICtrlCreateDummy()
    $cDummy_Dn = GUICtrlCreateDummy()

    GUISetState()

    ; Resize dialog to fit buttons
    $aPos = WinGetPos($hDialog)
    WinMove($hDialog, "", Default, Default, $iMax_Width + ($aPos[2] - $iDialog_Width) + 10, $iMax_Depth + ($aPos[3] - $iDialog_Depth) + 10)

    ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active
    Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]]
    GUISetAccelerators($aAccelKeys)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up, $cDummy_Dn
                _Vertical_TabStop()
            Case $aButton[0]
;_______________________Button 1 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 1")
;_______________________Button 1 OVER HER_______________________;
            Case $aButton[1]
;_______________________Button 2 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 2")
;_______________________Button 2 OVER HER_______________________;
            Case $aButton[2]
;_______________________Button 3 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 3")
;_______________________Button 3 OVER HER_______________________;
            Case $aButton[3]
;_______________________Button 4 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 4")
;_______________________Button 4 OVER HER_______________________;
            Case $aButton[4]
;_______________________Button 5 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 5")
;_______________________Button 5 OVER HER_______________________;
            Case $aButton[5]
;_______________________Button 6 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 6")
;_______________________Button 6 OVER HER_______________________;
            Case $aButton[6]
;_______________________Button 7 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 7")
;_______________________Button 7 OVER HER_______________________;
            Case $aButton[7]
;_______________________Button 8 UNDER HER_______________________;
                MsgBox($MB_SYSTEMMODAL, "Pressed", "Button 8")
;_______________________Button 8 OVER HER_______________________;
        EndSwitch

        ; Get focused control
        $hCurrFocus = _WinAPI_GetFocus()
        ; If it has changed
        If $hCurrFocus <> $hActive Then
            ; See if it is a button
            For $i = 0 To 7
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To 7
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)
                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript

Func _Vertical_TabStop()

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To 7
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then
            ; Then determine index of the button above/below
            $iIndex = Mod($i + 4, 8)
            ; And set focus
            GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS)
            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc

Please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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