Jump to content

GUI butttons - highlight


Go to solution Solved by Melba23,

Recommended Posts

  • Moderators

dynamitemedia,

Quote

 is it possible to limit it to 5 across? or 4?

Quite possible - when I have a moment I will see what I can do.

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

dynamitemedia,

How about this:

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

#include "GUIScrollbars_Ex.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 = 525

    $iCol_Count = 5 ; Max buttons per row

    ; Determine rows required
    $iRow_Count = Ceiling($iCount / $iCol_Count)

    ; Determine button width
    $iButton_Dim = Floor(($iDialog_Width - 10) / $iCol_Count)

    ; Determine required depth
    $iMax_Depth = ($iButton_Dim * $iRow_Count)

    If $iMax_Depth < $iDialog_Depth Then
        $iDialog_Depth = $iMax_Depth
    EndIf

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

    If $iMax_Depth > $iDialog_Depth Then
        _GUIScrollbars_Generate($hDialog, 0, $iMax_Depth)
    EndIf

    ; 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)
        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()

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case Else
                For $i = 0 To $iCount - 1
                    If $iMsg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i + 1)
                        ExitLoop
                    EndIf
                Next
        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 $iCount - 1
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $iCount - 1
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)
                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript

Better?

M23

Edit: You will need my Scrollbars UDF - look in my sig for the link.

Edited by Melba23

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

yes  awesome 2 things....

how can i get the padding between each of the buttons a bit wider?  i wopuld like more padding on the one farthest to the right next to scroll bar 

and now i can't get the vertical stop function to work

#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

;------    skins --------
#include ".\Skins\Cosmo.au3"
#include "_UskinLibrary.au3"

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))
; ------------------------


; Put your image paths in this array - sized to match required number of buttons
Global $aImage[22]; = ["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]
Global $appName =  "Watch me !!"


Mainscript()

Func Mainscript()


    ; Set max dialog size
    $iDialog_Width = 1500
    $iDialog_Depth = 900

    $iCol_Count = 4 ; Max buttons per row

    ; Determine rows required
    $iRow_Count = Ceiling($iCount / $iCol_Count)

    ; Determine button width
    $iButton_Dim = Floor(($iDialog_Width - 10) / $iCol_Count)

    ; Determine required depth
    $iMax_Depth = ($iButton_Dim * $iRow_Count)

    If $iMax_Depth < $iDialog_Depth Then
        $iDialog_Depth = $iMax_Depth
    EndIf

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

    If $iMax_Depth > $iDialog_Depth Then
        _GUIScrollbars_Generate($hDialog, 0, $iMax_Depth)
    EndIf

    ; 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)
        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()

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

            Case Else
                For $i = 0 To $iCount - 1
                    If $iMsg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i + 1)
                        ExitLoop
                    EndIf
                Next
        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 $iCount - 1
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $iCount - 1
                        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 $iCount - 1

            ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then

            ConsoleWrite( "active button: " & $aButton[$i] & @CRLF)

            ;Then determine index of the button above/below
            $iIndex = Mod($aButton[$i] + 4, 8)

            ; And set focus
            GUICtrlSetState($aButton[$i], $GUI_FOCUS)
            ;
        EndIf
    Next

EndFunc

I want to thank you very much for you help

Link to comment
Share on other sites

Ok got the padding between each somewhat the way i wanted...  up and down is working, but can prob be cleaned up.

the one issue i am having is when it gets to the final button and i push "UP"  it wont go up to the next row up and exits or just stops.  any ideas?

here is code here, and again i am sure it can be cleaned up, but it works!  99.9% lol
 

#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

;------    skins --------
#include ".\Skins\Cosmo.au3"
#include "_UskinLibrary.au3"

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))
; ------------------------


; Put your image paths in this array - sized to match required number of buttons
Global $aImage[22]; = ["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)
Global $aCount = $iCount + 2


; Create array to hold button and label ControlIDs
Global $aButton[$iCount], $aLabel[$iCount]
Global $appName =  "Watch me !!"


Mainscript()

Func Mainscript()


    ; Set max dialog size
    $iDialog_Width = 1280
    $iDialog_Depth = 720

    $iCol_Count = 5 ; Max buttons per row

    ; Determine rows required
    $iRow_Count = Ceiling($iCount / $iCol_Count)

    ; Determine button width
    $iButton_Dim = Floor(($iDialog_Width - 10) / $iCol_Count)

    ; Determine required depth
    $iMax_Depth = ($iButton_Dim * $iRow_Count)

    If $iMax_Depth < $iDialog_Depth Then
        $iDialog_Depth = $iMax_Depth
    EndIf

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

    If $iMax_Depth > $iDialog_Depth Then
        _GUIScrollbars_Generate($hDialog, 0, $iMax_Depth)
    EndIf

    ; 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("", 5 + ($iButton_Dim * $j), 5 + ($iButton_Dim * $i), $iButton_Dim - 20, $iButton_Dim - 20)
            GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF)
            GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE)
            GUICtrlSetResizing($aLabel[$iIndex], $GUI_DOCKALL)
        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), 10 + ($iButton_Dim * $j), 10 + ($iButton_Dim * $i), $iButton_Dim - 30, $iButton_Dim - 30, $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()

; ------------- 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
                $upLabel = $aLabel[$i] - 2
                $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $upLabel = $aButton[$i] - 24
                           If $upLabel < $iCount then
                              GUICtrlSetState($aButton[$upLabel] - 6, $GUI_FOCUS)
                              ConsoleWrite( "Pressed up: " & $upLabel & @CRLF)
                           Elseif $upLabel = $iCount then
                              ConsoleWrite( "end of list " & @CRLF)
                           EndIf
                           ExitLoop
                       EndIf
                    Next
             Case $msg = $cDummy_Dn
               $dwnLabel = $aLabel[$i] - 2
               $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $dwnLabel = $aButton[$i] - 24
                           If $dwnLabel < $iCount then
                              GUICtrlSetState($aButton[$dwnLabel] + 4, $GUI_FOCUS)
                                   ConsoleWrite( "pressed  down: " & $dwnLabel & @CRLF)
                            Elseif $dwnLabel = $iCount then
                              ConsoleWrite( "end of list " & @CRLF)
                           EndIf
                           ExitLoop
                       EndIf
                    Next
             Case Else
                For $i = 0 To $iCount - 1
                    If $Msg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i + 1)
                        ExitLoop
                    EndIf
                 Next
        EndSelect

        ; Get focused control
        $hCurrFocus = _WinAPI_GetFocus()
        ; If it has changed
        If $hCurrFocus <> $hActive Then
            ; See if it is a button
            For $i = 0 To $iCount - 1
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $iCount - 1
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    $rLabel = $aLabel[$i] - 2
                    ;ConsoleWrite( "button: " & $rLabel & @CRLF)
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)

                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript

 

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

Quote

i wopuld like more padding on the one farthest to the right next to scroll bar 

Make allowance for the scrollbar width like this:

; Determine button width
$iButton_Dim = Floor(($iDialog_Width - 10 - _WinAPI_GetSystemMetrics(2)) / $iCol_Count)

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

Ok i got what seems to be working...  its not tossing any errors and seems to be doing what its supposed to...

if someone can look at this section and see if there is a way to clean up... honestly its odd seems no rhyme or reason why its working :(  just kept messing with the numbers.
 

Case $msg = $cDummy_Up
                $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $upLabel = $aButton[$i] - $aButton[0]
                           $upButton = $aButton[$i] - $aCount
                           $newUpLabel = $upLabel - 4

                                ConsoleWrite( "Pressed up: " & $newUpLabel & @CRLF)

                           If $upLabel < $iCount then
                              GUICtrlSetState($aButton[$newUpLabel] - 1, $GUI_FOCUS)
                              ConsoleWrite( "Pressed up: " & $newUpLabel & @CRLF)
                           Elseif $upLabel > $iCount then
                              ConsoleWrite( "end of Row " & @CRLF)
                           Elseif $upLabel = $iCount then
                              ConsoleWrite( "end of list " & @CRLF)
                           EndIf
                           ExitLoop
                       EndIf
                    Next
             Case $msg = $cDummy_Dn

               $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $dwnLabel = $aButton[$i] - $aButton[0]
                           $dwnButton = $aButton[$i] - ($iCount - 1)
                           $newDwnLabel = $dwnLabel + 6

                        ConsoleWrite( "newDwnLabel: " & $newDwnLabel & @CRLF)

                           If $newDwnLabel < $iCount then
                              GUICtrlSetState($aButton[$dwnButton] + 1 , $GUI_FOCUS)
                              ConsoleWrite( "pressed  down: " & $newDwnLabel & @CRLF)
                           Elseif $newDwnLabel > $iCount then
                              ConsoleWrite( "end of Row " & @CRLF)
                           Elseif $newDwnLabel = $iCount then
                              ConsoleWrite( "Last Button" & @CRLF)
                              GUICtrlSetState($aButton[$dwnButton] + 1 , $GUI_FOCUS)
                           EndIf
                           ExitLoop
                       EndIf
                    Next

and full code here:

#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <Process.au3>
#include <Constants.au3>
#include <String.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

;------    skins --------
#include ".\Skins\Cosmo.au3"
#include "_UskinLibrary.au3"

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))
; ------------------------


; Put your image paths in this array - sized to match required number of buttons
Global $aImage[222] = ["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)
Global $aCount = $iCount + 2

; Create array to hold button and label ControlIDs
Global $aButton[$iCount], $aLabel[$iCount]
Global $appName =  "Watch me !!"

Mainscript()

Func Mainscript()

    ; Set max dialog size
    $iDialog_Width = 1280
    $iDialog_Depth = 720

    $iCol_Count = 5 ; Max buttons per row

    ; Determine rows required
    $iRow_Count = Ceiling($iCount / $iCol_Count)

    ; Determine button width
    $iButton_Dim = Floor(($iDialog_Width - 35 - _WinAPI_GetSystemMetrics(2)) / $iCol_Count)

    ; Determine required depth
    $iMax_Depth = ($iButton_Dim * $iRow_Count)

    If $iMax_Depth < $iDialog_Depth Then
        $iDialog_Depth = $iMax_Depth
    EndIf

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

    If $iMax_Depth > $iDialog_Depth Then
        _GUIScrollbars_Generate($hDialog, 0, $iMax_Depth)
    EndIf

    ; 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("", 30 + ($iButton_Dim * $j), 30 + ($iButton_Dim * $i), $iButton_Dim - 20, $iButton_Dim - 20)
            GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF)
            GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE)
            GUICtrlSetResizing($aLabel[$iIndex], $GUI_DOCKALL)
        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), 35 + ($iButton_Dim * $j), 35 + ($iButton_Dim * $i), $iButton_Dim - 30, $iButton_Dim - 30, $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()

; ------------- 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
                $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $upLabel = $aButton[$i] - $aButton[0]
                           $upButton = $aButton[$i] - $aCount
                           $newUpLabel = $upLabel - 4

                                ConsoleWrite( "Pressed up: " & $newUpLabel & @CRLF)

                           If $upLabel < $iCount then
                              GUICtrlSetState($aButton[$newUpLabel] - 1, $GUI_FOCUS)
                              ConsoleWrite( "Pressed up: " & $newUpLabel & @CRLF)
                           Elseif $upLabel > $iCount then
                              ConsoleWrite( "end of Row " & @CRLF)
                           Elseif $upLabel = $iCount then
                              ConsoleWrite( "end of list " & @CRLF)
                           EndIf
                           ExitLoop
                       EndIf
                    Next
             Case $msg = $cDummy_Dn

               $hActive = _WinAPI_GetFocus()
                   For $i = 0 To $iCount - 1
                       If $hActive = GUICtrlGetHandle($aButton[$i]) Then
                           $dwnLabel = $aButton[$i] - $aButton[0]
                           $dwnButton = $aButton[$i] - ($iCount - 1)
                           $newDwnLabel = $dwnLabel + 6

                        ConsoleWrite( "newDwnLabel: " & $newDwnLabel & @CRLF)

                           If $newDwnLabel < $iCount then
                              GUICtrlSetState($aButton[$dwnButton] + 1 , $GUI_FOCUS)
                              ConsoleWrite( "pressed  down: " & $newDwnLabel & @CRLF)
                           Elseif $newDwnLabel > $iCount then
                              ConsoleWrite( "end of Row " & @CRLF)
                           Elseif $newDwnLabel = $iCount then
                              ConsoleWrite( "Last Button" & @CRLF)
                              GUICtrlSetState($aButton[$dwnButton] + 1 , $GUI_FOCUS)
                           EndIf
                           ExitLoop
                       EndIf
                    Next
             Case Else
                For $i = 0 To $iCount - 1
                    If $Msg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i + 1)
                        ExitLoop
                    EndIf
                 Next
        EndSelect

        ; Get focused control
        $hCurrFocus = _WinAPI_GetFocus()
        ; If it has changed
        If $hCurrFocus <> $hActive Then
            ; See if it is a button
            For $i = 0 To $iCount - 1
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $iCount - 1
                        GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF)
                    Next
                    ; Highlight the correct label
                    $rLabel = $aLabel[$i] - 2
                    ;ConsoleWrite( "button: " & $rLabel & @CRLF)
                    GUICtrlSetBkColor($aLabel[$i], 0x00FF00)

                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript

Thanks everyone so much hope this can help someone...  im hoping to continue to build on it

anyone think that pagination would be better? 

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

Perhaps something like this:

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

#include "GUIScrollbars_Ex.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]
; Max buttons per row
Global $iCol_Count = 5
; Determine rows required
$iRow_Count = Ceiling($iCount / $iCol_Count)

Mainscript()

Func Mainscript()

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

    ; Determine button width
    $iButton_Dim = Floor(($iDialog_Width - 10 - _WinAPI_GetSystemMetrics(2)) / $iCol_Count)

    ; Determine required depth
    $iMax_Depth = ($iButton_Dim * $iRow_Count)

    If $iMax_Depth < $iDialog_Depth Then
        $iDialog_Depth = $iMax_Depth
    EndIf

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

    If $iMax_Depth > $iDialog_Depth Then
        _GUIScrollbars_Generate($hDialog, 0, $iMax_Depth)
    EndIf

    ; 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)
        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()

    ; 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
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up
                _Vertical_TabStop()
            Case $cDummy_Dn
                _Vertical_TabStop(True)
            Case Else
                For $i = 0 To $iCount - 1
                    If $iMsg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", "Button " & $i + 1)
                        ExitLoop
                    EndIf
                Next
        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 $iCount - 1
                If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then
                    ; Reset all the labels
                    For $j = 0 To $iCount - 1
                        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($bDown = False)

    Local $iNext_Row, $iNext_Button
    Local $iRow_Count = Ceiling($iCount / $iCol_Count)

    ; Get active control
    $hActive = _WinAPI_GetFocus()
    For $i = 0 To $iCount - 1
        ; If it is a button
        If $hActive = GUICtrlGetHandle($aButton[$i]) Then

            ; Determine row
            $iRow = Int($i / $iCol_Count)

            ; Set default value for next button
            $iNext_Button = $i

            If $bDown Then
                ; Not if in bottom row or there no button below
                If ($iRow < $iRow_Count - 1) And ($i + $iCol_Count < $iCount) Then
                    $iNext_Button += $iCol_Count
                EndIf
                Else
                ; Not if in top row
                If $iRow Then
                    $iNext_Button -= $iCol_Count
                EndIf
            EndIf
            ; Set focus to new button
            GUICtrlSetState($aButton[$iNext_Button], $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

dynamitemedia,

Quote

it paints very odd and flashes

Like only 50 per page?

Just how many images are you thinking of using in total? If you are using hundreds of images, then I am  not at all surprised that the GUI "flashes" as you scroll given the massive amount of redrawing that must be happening.

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

ViciousXUSMC,

Just for future info, you can follow a thread without posting in it using the "Follow This / Following" tag at top right of the page.

M23

Edited by Melba23
Both tag titles

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

ViciousXUSMC,

No probs - just pointing it out.

dynamitemedia,

How about using tabs? With 10 or 15 per tab that should allow for a reasonable viewing size.

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

can you explain what you mean by Tabs?

i was thinking maybe 20 at a time then a "Next" button... im working on some of that now...

thinking of having a   <<<   Previous           then a   HOME                then a Next >>>>

trying to get it to work where if only this amount displayed show only  Next,  almost got it i think lol

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

16 minutes ago, dynamitemedia said:

can you explain what you mean by Tabs?

Look at GUICtrlCreateTab - the idea would be to have 10-15 images per tab.

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