Jump to content

GUI butttons - highlight


Go to solution Solved by Melba23,

Recommended Posts

you know what i am noticing is  its flashing and resetting/ redrawing  the image on each click or arrow movement

when there are more images the flash is VERY obvious

#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))
; ------------------------
Global $type = "programs"
 Global $aFileList = _FileListToArray(@ScriptDir & "\thumbs\" & $type & "\", "*.bmp")
 Global $imgCount = UBound($aFileList) - 1

ConsoleWrite("aFileList : " & $aFileList[15] & @CRLF)


; Put your image paths in this array - sized to match required number of buttons
Global $aImage[15] = [@ScriptDir & "\thumbs\" & $type & "\" & $aFileList[15], @ScriptDir & "\thumbs\" & $type & "\" & $aFileList[2], @ScriptDir & "\thumbs\" & $type & "\" & $aFileList[2],@ScriptDir & "\thumbs\" & $type & "\" &  $aFileList[12],@ScriptDir & "\thumbs\" & $type & "\" &  $aFileList[22]]


$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

 

Link to comment
Share on other sites

let me know if this needs its own topic  @Melba23

but what i have gotten working so far is this:

#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.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 <GDIplus.au3>
#include <GuiButton.au3>
#Include "Curl.au3"
#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>


#include <WinAPIGdi.au3>

;------    skins --------

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

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))

Opt("GUIOnEventMode", 0) ; Change to OnEvent mode
Global $ico = @ScriptDir & "\bin\tv.ico"
; ----------   guis  --------

Global $hDialog, $hGUI
Global $FFmpegDir =  @ScriptDir & "\www\bin\"

;Find network or programs
Global $type = "programs"
Global $aFileList = _FileListToArray(@ScriptDir & "\thumbs\" & $type & "\", "*.bmp")

Global $imgCount = UBound($aFileList) - 1
; ConsoleWrite("count : " & $imgCount & @CRLF)

; Put your image paths in this array - sized to match required number of buttons
Global $aImage[$imgCount]

$iCount = UBound($aImage)
Global $aCount = $iCount + 2

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


; ---  this now is main gui ----->
programsGui($type)


Func programsGui($type)

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

    $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  +  100, -1, -1)
   ; GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
   GUISetIcon($ico, -1, $hDialog)


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


$programButton = GUICtrlCreateButton("Programs", 300, 30, 300, 65)
GUICtrlSetFont(-1, 16)

$networkButton = GUICtrlCreateButton("Networks", 650, 30, 300, 65)
GUICtrlSetFont(-1, 16)

    ; 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), 130 + ($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)
            $imgIndex = $j + ($i * $iCol_Count)

            If $iIndex > $iCount - 1 Then ExitLoop
               Local $imgLabel = StringTrimRight($aFileList[$imgIndex + 1], 4)
               local $img2Use = @ScriptDir & "\thumbs\" & $type & "\" & $imgLabel & ".bmp"

               $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 35 + ($iButton_Dim * $j), 135 + ($iButton_Dim * $i), $iButton_Dim - 30, $iButton_Dim - 30, $BS_BITMAP)

               GUICtrlSetImage($aButton[$iIndex], $img2use)
               GUICtrlSetResizing($aButton[$iIndex], $GUI_DOCKALL)
        Next
    Next

    ; Set default button
    GUICtrlSetState($aButton[0], $GUI_FOCUS)
    GUICtrlSetBkColor($aLabel[0], 0x005ED0)
    $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

               ;GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

                Exit
                
             Case $msg =  $programButton
               ConsoleWrite( "button clicked:    programs" & @CRLF)
               $type = "programs"
                  sleep ( 10 )
               _WinAPI_RedrawWindow ($hDialog)


            Case $msg = $networkButton
               ConsoleWrite( "button clicked:    Network" & @CRLF)
               $type = "networks"
               sleep ( 10 )
               _WinAPI_RedrawWindow ($hDialog)  
               
               
               
             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 $imgCount - 1
                    If $Msg = $aButton[$i] Then

                        $j = ($aButton[$i] - 5) - ($imgCount - 1)

                        Local $imgLabel = StringTrimRight($aFileList[$j], 4)
                        ConsoleWrite( "TV show : " & $imgLabel & @CRLF)
                        popUpGui($imgLabel)

                        ;MsgBox($MB_SYSTEMMODAL, "", "Pressed to watch: " & $imgLabel)

                        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], 0x494650)
                     GUICtrlSetBkColor($aLabel[$j], 0xffffff)
                    Next
                    ; Highlight the correct label
                    $rLabel = $aLabel[$i] - 2

                    ;ConsoleWrite( "button: " & $rLabel & @CRLF)
                    GUICtrlSetBkColor($aLabel[$i], 0x005ED0)

                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript


func popUpGui($imgLabel)

   ; ----------------  starts  show or network gui  ---------------
   Global $imageLabel = $imgLabel
   Global $hGUI = GUICreate("Program Name :    " & $imageLabel, 540, 415, -1, -1)

   GUISetIcon($ico, -1, $hGUI)

   local $img2Use = @ScriptDir & "\thumbs\" & $type & "\" & $imageLabel & ".bmp"

   Global $iBtnL = GUICtrlCreateButton("", 25, 25, 286, 364, BitOR($BS_BITMAP, $BS_DEFPUSHBUTTON) )
   GUICtrlSetImage($iBtnL, $img2Use)

   Global $streamButton = GUICtrlCreateButton("Stream to your TV", 272 + 62, 25, 172, 72)
   GUICtrlSetFont(-1, 13)

   Global $playButton = GUICtrlCreateButton("  Play  ", 272 + 62, 72 + 50, 172, 72)
   GUICtrlSetFont(-1, 13)

   GUISetState()

      While 1
          Switch GUIGetMsg()
          Case $GUI_EVENT_CLOSE

               _GDIPlus_Shutdown()
               GUISetState(@SW_ENABLE, $hDialog)
               WinActivate($hDialog)
               GUIDelete($hGUI)
               ExitLoop

            Case $streamButton

            Case $playButton

          EndSwitch
        WEnd

   ; --------------  end Gui ------------------------->

EndFunc

 But as you see  I have these two buttons

$programButton = GUICtrlCreateButton("Programs", 300, 30, 300, 65)
GUICtrlSetFont(-1, 16)

$networkButton = GUICtrlCreateButton("Networks", 650, 30, 300, 65)
GUICtrlSetFont(-1, 16)

well with these i need to redraw the gui with a new  $type 

i have tried Groups and hiding the groups,  tried making 2 guis at the start and hiding one... this here i like and works the best BUT i need to re declare $type and it wont let me,  i use the type to decide what folder the thumbs are in etc...   I need it when clicked change the type so it can draw the right amount of buttons,  and load images... been pulling my hair  out trying to get this and so many examples don't work here cause of the length of the while loop etc

Case $msg =  $programButton
               ConsoleWrite( "button clicked:    programs" & @CRLF)
               $type = "programs"
                  sleep ( 10 )
               _WinAPI_RedrawWindow ($hDialog)


         Case $msg = $networkButton
               ConsoleWrite( "button clicked:    Network" & @CRLF)
               $type = "networks"
               sleep ( 10 )
               _WinAPI_RedrawWindow ($hDialog)

 

Link to comment
Share on other sites

Ok i have been working on this and i seem to have something that is a work around and i like BUT i wish there was a way that there was not a flash when switching to a new gui

here is code i have, it works BUT  i don't like that flash i tried  using a sleep to make it wait a second before delete but no luck  thought about making it a random Gui name each time and let the new one come up and then delete the old after a sec or so... any better ideas?
 

#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.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 <GDIplus.au3>
#include <GuiButton.au3>
#Include "Curl.au3"
#include "GUIScrollbars_Ex.au3"
#include <Skin.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>


#include <WinAPIGdi.au3>

;------    skins --------

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

_Uskin_LoadDLL()
_USkin_Init(_Cosmo(True))


;Global $ico = @ScriptDir & "\bin\IPTV.ico"
Global $ico = @ScriptDir & "\bin\tv.ico"

Opt("GUIOnEventMode", 0) ; Change to OnEvent mode

; ----------   guis  --------

Global $hDialog, $hGUI , $type, $refresh, $newType
Global $FFmpegDir =  @ScriptDir & "\www\bin\"
Global $appName =  "Watch me !!"


;Find first Network channel  A & E  to start a new gui
Global $sFind = "https://www.arconaitv.me/ae/"

 If $newType = "" Then
    $newType = "programs"
EndIf


programsGui($newType, $refresh)


Func programsGui($newType,$refresh)
ConsoleWrite( "type is : " & $newType & @CRLF)
$type = $newType
Global $aFileList = _FileListToArray(@ScriptDir & "\thumbs\" & $type & "\", "*.bmp")

Global $imgCount = UBound($aFileList) - 1
; ConsoleWrite("count : " & $imgCount & @CRLF)

; Put your image paths in this array - sized to match required number of buttons
Global $aImage[$imgCount]

$iCount = UBound($aImage)
Global $aCount = $iCount + 2

; Create array to hold button and label ControlIDs
Global $aButton[$iCount], $aLabel[$iCount]

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

$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 $type = "networks" then
     $iMax_Depth =  $iMax_Depth + 30
EndIf

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

ConsoleWrite("refresh : " & $refresh & @CRLF)
If $refresh = "yes" then
   GUIDelete($hDialog)
EndIf

 ; Create dialog
$hDialog = GUICreate($appName, $iDialog_Width, $iDialog_Depth  +  100, -1, -1)
; GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
GUISetIcon($ico, -1, $hDialog)

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

$programButton = GUICtrlCreateButton("Programs", 300, 30, 300, 65)
GUICtrlSetFont(-1, 16)

$networkButton = GUICtrlCreateButton("Networks", 650, 30, 300, 65)
GUICtrlSetFont(-1, 16)

    ; 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), 130 + ($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)
            $imgIndex = $j + ($i * $iCol_Count)

            If $iIndex > $iCount - 1 Then ExitLoop
               Local $imgLabel = StringTrimRight($aFileList[$imgIndex + 1], 4)
               local $img2Use = @ScriptDir & "\thumbs\" & $type & "\" & $imgLabel & ".bmp"

               $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 35 + ($iButton_Dim * $j), 135 + ($iButton_Dim * $i), $iButton_Dim - 30, $iButton_Dim - 30, $BS_BITMAP)

               GUICtrlSetImage($aButton[$iIndex], $img2use)
               GUICtrlSetResizing($aButton[$iIndex], $GUI_DOCKALL)
        Next
    Next

    ; Set default button
    GUICtrlSetState($aButton[0], $GUI_FOCUS)
    GUICtrlSetBkColor($aLabel[0], 0x005ED0)
    $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
               ;GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
                Exit
            Case $msg =  $programButton
               ConsoleWrite( "button clicked:    programs" & @CRLF)
               $newType = "programs"
               Local $refreshYes = "yes"
               ConsoleWrite( "newType: " & $newType & @CRLF)

               programsGui($newType, $refreshYes)


            Case $msg = $networkButton
               ConsoleWrite( "button clicked:    Network" & @CRLF)
               $newType = "networks"
               Local $refreshYes = "yes"
               ;GUIDelete($hDialog)
               programsGui($newType,$refreshYes)

             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 $imgCount - 1
                    If $Msg = $aButton[$i] Then

                        $j = ($aButton[$i] - 5) - ($imgCount - 1)

                        Local $imgLabel = StringTrimRight($aFileList[$j], 4)
                        ConsoleWrite( "TV show : " & $imgLabel & @CRLF)
                        popUpGui($imgLabel)

                        ;MsgBox($MB_SYSTEMMODAL, "", "Pressed to watch: " & $imgLabel)

                        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], 0x494650)
                     GUICtrlSetBkColor($aLabel[$j], 0xffffff)
                    Next
                    ; Highlight the correct label
                    $rLabel = $aLabel[$i] - 2


                    ;ConsoleWrite( "button: " & $rLabel & @CRLF)
                    GUICtrlSetBkColor($aLabel[$i], 0x005ED0)

                    ExitLoop
                EndIf
            Next
            $hActive = $hCurrFocus
        EndIf
    WEnd

EndFunc   ;==>Mainscript






func popUpGui($imgLabel)

   ; ----------------  starts  show or network gui  ---------------
   Global $imageLabel = $imgLabel

   ; ------------------  grabs show from ArconaiTV from image label  ---------------->
   arconaiGetShows($type, $imageLabel)


   Global $hGUI = GUICreate("Program Name :    " & $imageLabel, 540, 415, -1, -1)

   GUISetIcon($ico, -1, $hGUI)

   local $img2Use = @ScriptDir & "\thumbs\" & $type & "\" & $imageLabel & ".bmp"
   ;Local $idPic = GUICtrlCreatePic($img2Use, 25, 25, 272, 350)

   ; GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")

   ; ----  if i want buttons --->
   Global $iBtnL = GUICtrlCreateButton("", 25, 25, 286, 364, BitOR($BS_BITMAP, $BS_DEFPUSHBUTTON) )
   GUICtrlSetImage($iBtnL, $img2Use)

   Global $streamButton = GUICtrlCreateButton("Stream to your TV", 272 + 62, 25, 172, 72)
   GUICtrlSetFont(-1, 13)

   Global $playButton = GUICtrlCreateButton("  Play  ", 272 + 62, 72 + 50, 172, 72)
   GUICtrlSetFont(-1, 13)

   GUISetState()

      While 1
          Switch GUIGetMsg()
          Case $GUI_EVENT_CLOSE

               _GDIPlus_Shutdown()
               GUISetState(@SW_ENABLE, $hDialog)
               WinActivate($hDialog)
               GUIDelete($hGUI)
               ExitLoop

               ;Case $iBtnL
               Case $streamButton

               Case $playButton
                  $MyBox = MsgBox(0+1, " ", $imageLabel & " will start playing soon on FFplay")

               ; -------  grabs the show and gets the URL   -------->
                  arocnaiTV($showName)

                  If $MyBox == 1 Then

                        ; MsgBox(0,"Message Box Title","You Pressed the OK button!")
                     ;  ------------  Play Locally ------------->


                     playVidTitle($imageLabel, $aURLstring[0])



                  ElseIf $MyBox == 2 Then
                    ; MsgBox(0,"Message Box Title","You Pressed Cancel!")
                EndIf

          EndSwitch
        WEnd

   ; --------------  end Gui ------------------------->

EndFunc

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

dynamitemedia,

Quote

why when you use the up and down arrows the scrolling does not go with it?

Because the script is not coded to do that! I am heavily involved in another problem at the moment, but 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,

Not too hard to manage - so here it is:

#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[37]; = ["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
    $iVisRows = 0
    While 1
        $iVisRows += 1
        If $iButton_Dim * $iVisRows > $iDialog_Depth Then
            $iVisRows -= 1
            ExitLoop
        EndIf
    WEnd
    $iDialog_Depth = ($iButton_Dim * $iVisRows) + 10

    ConsoleWrite($iVisRows & @CRLF)

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

    If $iRow_Count > $iVisRows Then
        _GUIScrollbars_Generate($hDialog, 0, $iButton_Dim * $iRow_Count)
    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()
    $cDummy_Left = GUICtrlCreateDummy()
    $cDummy_Right = GUICtrlCreateDummy()

    GUISetState()

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

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up
                _Move_Focus($hDialog, 1)
            Case $cDummy_Dn
                _Move_Focus($hDialog, 2)
            Case $cDummy_Left
                _Move_Focus($hDialog, 3)
            Case $cDummy_Right
                _Move_Focus($hDialog, 4)
            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 _Move_Focus($hDialog, $iMode)

    Local $iNext_Button, $iRow, $iNewRow
    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)
            $iNewRow = $iRow

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

            Switch $iMode
                Case 1
                    ; Not if in top row
                    If $iRow Then
                        $iNext_Button -= $iCol_Count
                        ; Set new row
                        $iNewRow -= 1
                    EndIf
                Case 2
                    ; 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
                        ; Set new row
                        $iNewRow += 1
                    EndIf
                Case 3
                    ; If not first button
                    If $i <> 0 Then
                        $iNext_Button -= 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
                Case 4
                    ; If not last button
                    If $i <> $iCount Then
                        $iNext_Button += 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
            EndSwitch

            ; Set focus to new button
            GUICtrlSetState($aButton[$iNext_Button], $GUI_FOCUS)

            ; Get button into view by scrolling to page which includes button
            _GUIScrollbars_Scroll_Page($hDialog, 0, Int($iNewRow / 2) + 1)

            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc

As usual, please ask if anything is unclear.

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

i have to do some changing around to meet my code as i posted,  going to be some hours of math to get it to work but at least i know where to start! lol

i it works perfect on yours but i had some mods so i need to figure out where to change those... if i can not get it will come back and ask for help, once again your amazing thanks

 

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

I see - looks like a child GUI might be the way to go here. I will see what I can do.

M23

Edit:

Not very difficult to code - now you just scroll the image buttons and leave the top ones in place:

#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[37]; = ["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
    $iVisRows = 0
    While 1
        $iVisRows += 1
        If $iButton_Dim * $iVisRows > $iDialog_Depth Then
            $iVisRows -= 1
            ExitLoop
        EndIf
    WEnd
    $iDialog_Depth = ($iButton_Dim * $iVisRows) + 10

    ; Add the space for the buttons to get the main GUI size
    $iMain_Depth = $iDialog_Depth + 100

    ; Create main GUI
    $hGUI = GUICreate("MainGUI", $iDialog_Width, $iMain_Depth)

    $cPrograms = GUICtrlCreateButton("Programs", ($iDialog_Width / 2) - 320, 20, 300, 60)
    $cNetWorks = GUICtrlCreateButton("NetWorks", ($iDialog_Width / 2) + 20, 20, 300, 60)

    GUISetState()

    ; Create dialog
    $hDialog = GUICreate("", $iDialog_Width, $iDialog_Depth, 0, 100, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
    GUISetBkColor(0xFFFFFF)

    If $iRow_Count > $iVisRows Then
        _GUIScrollbars_Generate($hDialog, 0, $iButton_Dim * $iRow_Count)
    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()
    $cDummy_Left = GUICtrlCreateDummy()
    $cDummy_Right = GUICtrlCreateDummy()

    GUISetState()

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

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy_Up
                _Move_Focus($hDialog, 1)
            Case $cDummy_Dn
                _Move_Focus($hDialog, 2)
            Case $cDummy_Left
                _Move_Focus($hDialog, 3)
            Case $cDummy_Right
                _Move_Focus($hDialog, 4)
            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 _Move_Focus($hDialog, $iMode)

    Local $iNext_Button, $iRow, $iNewRow
    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)
            $iNewRow = $iRow

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

            Switch $iMode
                Case 1
                    ; Not if in top row
                    If $iRow Then
                        $iNext_Button -= $iCol_Count
                        ; Set new row
                        $iNewRow -= 1
                    EndIf
                Case 2
                    ; 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
                        ; Set new row
                        $iNewRow += 1
                    EndIf
                Case 3
                    ; If not first button
                    If $i <> 0 Then
                        $iNext_Button -= 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
                Case 4
                    ; If not last button
                    If $i <> $iCount Then
                        $iNext_Button += 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
            EndSwitch

            ; Set focus to new button
            GUICtrlSetState($aButton[$iNext_Button], $GUI_FOCUS)

            ; Get button into view by scrolling to page which includes button
            _GUIScrollbars_Scroll_Page($hDialog, 0, Int($iNewRow / 2) + 1)

            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc   ;==>_Move_Focus

But looking at your code I see you are recursively calling the programsGui function - really not a good idea as it can only end in tears. You need to recast the code so that only the buttons are changed, rather than deleting and recreating the entire GUI each time. I will see what I can do to restructure the code this morning if I find time.

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

  • Moderators

dynamitemedia,

Here is a recast script which reloads the buttons/images without recursion - everything is nicely packaged in functions which means that only the buttons/images themselves are rewritten each time

It actually displays the contents of your AutoIt "Include" folder, switching between those files which hold constants and those which do not, but the basic principle is there. All you need to do to get your own content is adjust the _List_Images function and get the 2 buttons to set the correct filter:

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

#include <Array.au3>

#include "GUIScrollbars_Ex.au3"

; Declare global arrays to hold ControlIDs
Global $aImage, $aButton, $aLabel
; Declare image count
Global $iCount
; Max buttons per row
Global $iCol_Count = 5

Global $hActive, $iRow_Count, $hDialog

; Set default listing filter
$sListFilter = "Functions"

; 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 depths
$iVisRows = 0
While 1
    $iVisRows += 1
    If $iButton_Dim * $iVisRows > $iDialog_Depth Then
        $iVisRows -= 1
        ExitLoop
    EndIf
WEnd
$iDialog_Depth = ($iButton_Dim * $iVisRows) + 10

; Add the space for the buttons to get the main GUI size
$iMain_Depth = $iDialog_Depth + 100

Mainscript()

Func Mainscript()

    ; Liat the images to display
    $aImage = _List_Images($sListFilter)
    $iCount = UBound($aImage)
    ; Create arrays to hold button and label ControlIDs
    Global $aButton[$iCount], $aLabel[$iCount]

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

    ; Create main GUI
    $hGUI = GUICreate("MainGUI", $iDialog_Width, $iMain_Depth)

    $cPrograms = GUICtrlCreateButton("Functions", ($iDialog_Width / 2) - 320, 20, 300, 60)
    $cNetWorks = GUICtrlCreateButton("Constants", ($iDialog_Width / 2) + 20, 20, 300, 60)

    GUISetState()

    ; Create dialog
    $hDialog = GUICreate("", $iDialog_Width, $iDialog_Depth, 0, 100, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
    GUISetBkColor(0xFFFFFF)

    If $iRow_Count > $iVisRows Then
        _GUIScrollbars_Generate($hDialog, 0, $iButton_Dim * $iRow_Count)
    EndIf

    _Draw_Images()

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

    GUISetState()

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

    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cPrograms
                If $sListFilter <> "Functions" Then
                    $sListFilter = "Functions"
                    _Load_Images($sListFilter)
                EndIf

            Case $cNetWorks
                If $sListFilter <> "Constants" Then
                    $sListFilter = "Constants"
                    _Load_Images($sListFilter)
                EndIf

            Case $cDummy_Up
                _Move_Focus($hDialog, 1)
            Case $cDummy_Dn
                _Move_Focus($hDialog, 2)
            Case $cDummy_Left
                _Move_Focus($hDialog, 3)
            Case $cDummy_Right
                _Move_Focus($hDialog, 4)
            Case Else
                For $i = 0 To $iCount - 1
                    If $iMsg = $aButton[$i] Then
                        MsgBox($MB_SYSTEMMODAL, "Pressed", GUICtrlRead($aButton[$i]))
                        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 _Draw_Images()

    ; 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($aImage[$iIndex], 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])

EndFunc   ;==>_Draw_Images

Func _Load_Images($sListFilter)

    ; Remove current images, buttons and labels
    For $i = 0 To $iCount - 1
        GUICtrlDelete($aButton[$i])
        GUICtrlDelete($aLabel[$i])
    Next

    ; Liat the images to display
    $aImage = _List_Images($sListFilter)
    $iCount = UBound($aImage)
    ; Create arrays to hold button and label ControlIDs
    Global $aButton[$iCount], $aLabel[$iCount]

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

    ; Redraw buttons
    _Draw_Images()

    ; Scrol to top, hide and if required reset the scrolling
    _GUIScrollbars_Scroll_Page($hDialog, 0, 1)
    _GUIScrollBars_ShowScrollBar($hDialog, $SB_BOTH, False)
    If $iRow_Count > $iVisRows Then
        _GUIScrollbars_Generate($hDialog, 0, $iButton_Dim * $iRow_Count)
    EndIf

EndFunc   ;==>_Load_Images

Func _List_Images($sFilter)

    ; Here you would have your FileListToArray lines to get a list of the images to display

    ; But for this example we will look in the AutoIt include folder and show files with/without "Constant" in the name
    Local $sIncludeFolder = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1)) & "Include"
    Local $aList = _FileListToArray($sIncludeFolder, "*.au3", $FLTA_FILES)

    ; Now filter according to the setting
    For $i = $aList[0] To 1 Step -1
        Switch $sFilter
            Case "Functions"
                If StringInStr($aList[$i], "Constant") Then
                    _ArrayDelete($aList, $i)
                    $aList[0] -= 1
                EndIf
            Case "Constants"
                If Not StringInStr($aList[$i], "Constant") Then
                    _ArrayDelete($aList, $i)
                    $aList[0] -= 1
                EndIf
        EndSwitch
    Next

    ; Remove the count element
    _ArrayDelete($aList, 0)
    ; And return the list
    Return $aList

EndFunc   ;==>_List_Images

Func _Move_Focus($hDialog, $iMode)

    Local $iNext_Button, $iRow, $iNewRow
    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)
            $iNewRow = $iRow

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

            Switch $iMode
                Case 1
                    ; Not if in top row
                    If $iRow Then
                        $iNext_Button -= $iCol_Count
                        ; Set new row
                        $iNewRow -= 1
                    EndIf
                Case 2
                    ; 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
                        ; Set new row
                        $iNewRow += 1
                    EndIf
                Case 3
                    ; If not first button
                    If $i <> 0 Then
                        $iNext_Button -= 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
                Case 4
                    ; If not last button
                    If $i <> $iCount Then
                        $iNext_Button += 1
                        $iNewRow = Int($iNext_Button / $iCol_Count)
                    EndIf
            EndSwitch

            ; Set focus to new button
            GUICtrlSetState($aButton[$iNext_Button], $GUI_FOCUS)

            ; Get button into view by scrolling to page which includes button
            _GUIScrollbars_Scroll_Page($hDialog, 0, Int($iNewRow / 2) + 1)

            ; No point in looking further
            ExitLoop
        EndIf
    Next

EndFunc   ;==>_Move_Focus

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

wow that is awesome... 

so you are saying all i need to do is replace this part now?
 

Func _List_Images($sFilter)

    ; Here you would have your FileListToArray lines to get a list of the images to display

    ; But for this example we will look in the AutoIt include folder and show files with/without "Constant" in the name
    Local $sIncludeFolder = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1)) & "Include"
    Local $aList = _FileListToArray($sIncludeFolder, "*.au3", $FLTA_FILES)

im going to dig thru this when i get home whoo hooo... damn this could have saved me weeks of time it looks like but i learned a lot! thanks so much

Edited by dynamitemedia
refresh
Link to comment
Share on other sites

  • Moderators

dynamitemedia,

In my script I use the $sFilter variable to tell the _List_Images function what to list - so you need to do the same thing by setting the initial value of the variable to what you want displayed when the script starts and then adjusting its content when one of the 2 buttons is pressed. Once you have the list you will need obviously need to add the images to the buttons - I used GUICtrlSetData to get the file name into the button, so you would need to replace that with a  GUICtrlSetImage line.

Other than that I think that the script is pretty much what you want - if not, then please do come back.

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

1 hour ago, dynamitemedia said:

Ok one quick thing tho... 

i want the buttons on top to refresh the images or folders...   where do you suggest i make that edit?    

this will be my only question as i play with it i am sure... is this

is the bottom half a child gui ?   so i should be able to hit a button and clear out that bottom section and redraw it right?

Link to comment
Share on other sites

  • Moderators

dynamitemedia,

Quote

 i should be able to hit a button and clear out that bottom section and redraw it right?

Have you actually read the script? What do you think this function does?

Func _Load_Images($sListFilter)

    ; Remove current images, buttons and labels
    For $i = 0 To $iCount - 1
        GUICtrlDelete($aButton[$i])
        GUICtrlDelete($aLabel[$i])
    Next

    ; Liat the images to display
    $aImage = _List_Images($sListFilter)
    $iCount = UBound($aImage)
    ; Create arrays to hold button and label ControlIDs
    Global $aButton[$iCount], $aLabel[$iCount]

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

    ; Redraw buttons
    _Draw_Images()

    ; Scrol to top, hide and if required reset the scrolling
    _GUIScrollbars_Scroll_Page($hDialog, 0, 1)
    _GUIScrollBars_ShowScrollBar($hDialog, $SB_BOTH, False)
    If $iRow_Count > $iVisRows Then
        _GUIScrollbars_Generate($hDialog, 0, $iButton_Dim * $iRow_Count)
    EndIf

EndFunc   ;==>_Load_Images

When I said it was a working script I was quite serious. I suggest you take some time to read and understand it before you ask any more questions. As the script uses the AutoIt include folder to list the files, you should be able to run it without problem on your machine.

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