Jump to content

Recommended Posts

Posted (edited)

Very nice Chimp. :thumbsup:

What about a dock function of the GUI to the desktop borders?

An auto "hide" function where the GUI moved outside the visible area if it is not in use. When you hover the mouse to the e.g. 1 px visible border it will be move to the visible screen again.

Save of the last position and GUI size.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
On 3/15/2020 at 8:16 PM, UEZ said:

Very nice Chimp. :thumbsup:

Thanks UEZ :)

This version includes the possibility to hide the panel by right clicking on the title bar. The panel disappears and only a placeholder icon (a star) remains in its place.
To make the panel reappear just right click on the star icon.
When the panel is closed, it "remembers" the current size and position in an ini file so that the next run it reappears where it was.

I haven't replaced the old version in the first psost because I'm not sure this is better ...
probably making the panel disappear beyond the edges would be a more gracious effect, but ... this requires more programming effort ...

have fun

; ===============================================================================================================================
; Title .........: LaunchPad
; Description ...: button deck to be used as an applications launcher (and not only)
; Author(s) .....: Chimp (Gianni Addiego)
;                  credits to  @KaFu, @Danyfirex, @mikell (see comments for references)
; ===============================================================================================================================

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3> ; <WinAPISysWin.au3>
#include <SendMessage.au3>
#include <WinAPIFiles.au3>

;Turn off redirection for a 32-bit script on 64-bit system.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

OnAutoItExitRegister('_Exit')

; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing
Global Const $WMSZ_LEFT = 1
Global Const $WMSZ_RIGHT = 2
Global Const $WMSZ_TOP = 3
Global Const $WMSZ_TOPLEFT = 4
Global Const $WMSZ_TOPRIGHT = 5
Global Const $WMSZ_BOTTOM = 6
Global Const $WMSZ_BOTTOMLEFT = 7
Global Const $WMSZ_BOTTOMRIGHT = 8
Global Enum $vButton_Tip = 0, $vButton_IconPath, $vButton_IconNumber, $vButton_Command

#cs
    The following 2D array contains the settings that determine the behavior of each "Button"
    namely 4 parameters for each row (for each button);
    [n][0] the tooltip of the button
    [n][1] path of an icon or a file containing icons
    [n][2] the number of the icon (if the previous parameter is a collection)
    [n][3] AutoIt command(s) to be executed directly on button click (or also the name of a function)
#ce

Global Const $aTools[][] = [ _
        ['Settings', 'SHELL32.dll', 177, 'run("explorer.exe shell:::{D20EA4E1-3957-11d2-A40B-0C5020524153}")'], _ ; 'Test()'], _ ; call a function 'Test()'
        ['Windows version', 'winver.exe', 1, 'run("explorer.exe shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}")'], _  ; or "Run('winver.exe')"
        ['This computer', 'netcenter.dll', 6, 'run("explorer.exe shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")'], _
        ['Devices and Printers', 'SHELL32.dll', 272, 'run("explorer.exe shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")'], _
        ['Folder options', 'SHELL32.dll', 210, 'run("explorer.exe  shell:::{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}")'], _
        ['Command Prompt', @ComSpec, 1, 'Run(@ComSpec)'], _
        ['Internet Explorer', @ProgramFilesDir & '\Internet Explorer\iexplore.exe', 1, "Run(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')"], _
        ['Media Player', @ProgramFilesDir & '\Windows media player\wmplayer.exe', 1, "Run(@ProgramFilesDir & '\Windows media player\wmplayer.exe')"], _
        ['File browser', @WindowsDir & '\explorer.exe', 1, "Run(@WindowsDir & '\explorer.exe')"], _
        ['Notepad', @SystemDir & '\notepad.exe', 1, "Run(@SystemDir & '\notepad.exe')"], _
        ['Wordpad', @SystemDir & '\write.exe', 1, "Run(@SystemDir & '\write.exe')"], _
        ['Registry editor', @SystemDir & '\regedit.exe', 1, "ShellExecute('regedit.exe')"], _
        ['Connect to', 'netcenter.dll', 19, 'run("explorer.exe shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B}")'], _
        ['Calculator', @SystemDir & '\Calc.exe', 1, "Run(@SystemDir & '\calc.exe')"], _
        ['Control panel', 'control.exe', 1, 'run("explorer.exe shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}")'], _
        ['Users manager', @SystemDir & '\Netplwiz.exe', 1, "ShellExecute('Netplwiz.exe')"], _ ; {7A9D77BD-5403-11d2-8785-2E0420524153}
        ['Run', 'SHELL32.dll', 25, 'Run("explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}")'], _
        ['Search files', 'SHELL32.dll', 135, 'run("explorer.exe shell:::{9343812e-1c37-4a49-a12e-4b2d810d956b}")'], _
        ['On screen Magnifier', @SystemDir & '\Magnify.exe', 1, "ShellExecute('Magnify.exe')"], _
        ['Paint', @SystemDir & '\mspaint.exe', 1, "Run(@SystemDir & '\mspaint.exe')"], _
        ['Remote desktop', @SystemDir & '\mstsc.exe', 1, " Run('mstsc.exe')"], _
        ['Resource monitoring', @SystemDir & '\resmon.exe', 1, "Run('resmon.exe')"], _
        ['Device manager', 'SHELL32.dll', 13, 'Run("explorer.exe Shell:::{74246bfc-4c96-11d0-abef-0020af6b0b7a}")'], _
        ['Audio', 'SndVol.exe', 1, 'Run("explorer.exe Shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D}")'], _ ; or 'run(@SystemDir & "\SndVol.exe")']
        ['Task view', 'SHELL32.dll', 133, 'Run("explorer.exe shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}")'], _
        ['Task Manager', @SystemDir & '\taskmgr.exe', 1, 'Send("^+{ESC}")'], _ ; "Run(@SystemDir & '\taskmgr.exe')"], _
        ['On Screen Keyboard', 'osk.exe', 1, 'ProcessExists("osc.exe") ? False : ShellExecute("osk.exe")'], _ ; <-- ternary example
        ['... if Notepad is running' & @CRLF & 'Send F5 to it', 'SHELL32.dll', 167, ' WinExists("[CLASS:Notepad]") ? ControlSend("[CLASS:Notepad]", "", "", "{F5}") : MsgBox(16, ":(", "Notepad not found", 2)'] _ ; Check if Notepad is currently running
        ]
; Show desktop       {3080F90D-D7AD-11D9-BD98-0000947B0257}
; Desktop Background {ED834ED6-4B5A-4bfe-8F11-A626DCB6A921}
; IE internet option {A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE}
;       ['Notes', 'StikyNot.exe', 1, "ShellExecute('StikyNot')"], _

Global $ini = @ScriptDir & '\LaunchPad.ini'
Global $iStep = 38 ; button size
Global $iNrPerLine = Number(IniRead($ini, 'GENERAL', 'xIcons', '15'))
Global $iLeftPos = Number(IniRead($ini, 'GENERAL', 'LeftPos', '10'))
Global $iTopPos = Number(IniRead($ini, 'GENERAL', 'TopPos', '10'))
Global $iNrOfLines = Ceiling(UBound($aTools) / $iNrPerLine)

; --- PlaceHolder ------------------------------------------------------------------------------------------
Global $iPH = 30 ; Placeholder dimension
Global $AlphaKey = 0xF0F7FF ; for transparent background
Global $hPlaceHolder = GUICreate('', $iPH, $iPH, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED))
Global $hPic = GUICtrlCreatePic("", 0, 0, $iPH, $iPH, -1, $GUI_WS_EX_PARENTDRAG) ; this allow dragging.
Global $Hstar = GUICtrlCreateIcon("shell32.dll", 44, 0, 0, $iPH, $iPH) ; a placeholder icon
GUISetBkColor($AlphaKey, $hPlaceHolder) ; $AlphaKey $hBackground
_WinAPI_SetLayeredWindowAttributes($hPlaceHolder, $AlphaKey, 0, $LWA_COLORKEY) ; make it transparent
GUISetState(@SW_HIDE, $hPlaceHolder) ; keep it hide
; ----------------------------------------------------------------------------------------------------------
Global $dllUser32 = DllOpen("user32.dll")

Global $GUI = GUICreate('LaunchPad', 10, 10, $iLeftPos, $iTopPos, BitOR($WS_THICKFRAME, 0), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

Global $aMyMatrix = _GuiControlPanel("Button", $iNrPerLine, $iNrOfLines, $iStep, $iStep, BitOR(0x40, 0x1000), -1, 0, 0, 0, 0, 0, 0, False, "")
Global $iPreviousX = ($aMyMatrix[0])[1], $iPreviousY = ($aMyMatrix[0])[2]

For $i = 1 To UBound($aMyMatrix) - 1
    GUICtrlSetResizing($aMyMatrix[$i], $GUI_DOCKALL) ; (2+32+256+512) so the control will not move during resizing
    If $i <= UBound($aTools) Then
        GUICtrlSetImage($aMyMatrix[$i], $aTools[$i - 1][$vButton_IconPath], $aTools[$i - 1][$vButton_IconNumber])
        GUICtrlSetTip($aMyMatrix[$i], $aTools[$i - 1][$vButton_Tip])
    EndIf
Next

_WinSetClientSize($GUI, ($aMyMatrix[0])[11], ($aMyMatrix[0])[12]) ; thanks to KaFu

GUISetState()

; https://devblogs.microsoft.com/oldnewthing/20110218-00/?p=11453
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
; GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_LBUTTONDBLCLK")

_MainLoop()
_Exit()

Func _MainLoop()
    Local $iDeltaX, $iDeltaY, $row, $col, $left, $top, $awPos

    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case -3 ; end
                Exit
            Case Else
                For $i = 1 To UBound($aMyMatrix) - 1
                    If $Msg = $aMyMatrix[$i] Then
                        If $i <= UBound($aTools) Then
                            $dummy = Execute($aTools[$i - 1][3])
                        EndIf
                    EndIf
                Next
        EndSwitch

        ; check if any size has changed
        If $iPreviousX <> ($aMyMatrix[0])[1] Or $iPreviousY <> ($aMyMatrix[0])[2] Then
            ; calculate the variations
            $iDeltaX = Abs($iPreviousX - ($aMyMatrix[0])[1])
            $iDeltaY = Abs($iPreviousY - ($aMyMatrix[0])[2])

            ; if both dimensions changed at the same time, the largest variation prevails over the other
            If $iDeltaX >= $iDeltaY Then ; keep the new number of columns
                ; calculate and set the correct number of lines accordingly
                _SubArraySet($aMyMatrix[0], 2, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[1]))
            Else ; otherwise keep the new number of rows
                ; calculate and set the correct number of columns accordingly
                _SubArraySet($aMyMatrix[0], 1, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[2]))
            EndIf

            ; set client area new sizes
            _WinSetClientSize($GUI, ($aMyMatrix[0])[1] * $iStep, ($aMyMatrix[0])[2] * $iStep)

            ; remember the new panel settings
            $iPreviousX = ($aMyMatrix[0])[1]
            $iPreviousY = ($aMyMatrix[0])[2]

            ; rearrange the controls inside the panel
            For $i = 0 To UBound($aMyMatrix) - 2
                ; coordinates 1 based
                $col = Mod($i, $iPreviousX) + 1 ; Horizontal position within the grid (column)
                $row = Int($i / $iPreviousX) + 1 ; Vertical position within the grid (row number)
                $left = ($aMyMatrix[0])[5] + (((($aMyMatrix[0])[3] + ($aMyMatrix[0])[9]) * $col) - ($aMyMatrix[0])[9]) - ($aMyMatrix[0])[3] + ($aMyMatrix[0])[7]
                $top = ($aMyMatrix[0])[6] + (((($aMyMatrix[0])[4] + ($aMyMatrix[0])[10]) * $row) - ($aMyMatrix[0])[10]) - ($aMyMatrix[0])[4] + ($aMyMatrix[0])[8]
                GUICtrlSetPos($aMyMatrix[$i + 1], $left, $top)
            Next
        EndIf

        $hHover = GUIGetCursorInfo(HWnd($hPlaceHolder))

        If Not @error And $hHover[4] = $Hstar And $hHover[3] Then
            GUISetState(@SW_HIDE, $hPlaceHolder) ; hide placeholder
            $awPos = WinGetPos($hPlaceHolder)
            WinMove($GUI, '', $awPos[0], $awPos[1])
            DllCall($dllUser32, "int", "AnimateWindow", "hwnd", $GUI, "int", 200, "long", "0x00040010") ; show panel
            WinActivate($GUI)
        EndIf
    WEnd
EndFunc   ;==>_MainLoop

; Allow/Disallow specific borders resizing
; thanks to Danyfirex
;           ---------
; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445748
Func WM_NCHITTEST($hwnd, $iMsg, $iwParam, $ilParam)
    If $hwnd = $GUI Then
        Local $iRet = _WinAPI_DefWindowProc($hwnd, $iMsg, $iwParam, $ilParam)
        ; https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest
        If $iRet = $HTBOTTOM Or $iRet = $HTRIGHT Or $iRet = $HTBOTTOMRIGHT Then ; allowed resizing
            Return $iRet ; default process of border resizing
        Else ; resizing not allowed
            Return $HTCLIENT ; do like if cursor is in the client area
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

; controls and process resizing operations in real time
; thanks to mikell
;           ------
; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445754
Func WM_SIZING($hwnd, $iMsg, $wparam, $lparam)
    ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing
    Local $iCols = ($aMyMatrix[0])[1]
    Local $iRows = ($aMyMatrix[0])[2]
    Local $xClientSizeNew, $yClientSizeNew

    #cs $wparam
        The edge of the window that is being sized.
        
        $lparam
        A pointer to a RECT structure with the screen coordinates of the drag rectangle.
        To change the size or position of the drag rectangle, an application must change the members of this structure.
        
        Return value
        Type: LRESULT
        
    #ce $wparam

    $aPos = WinGetPos($GUI)
    #cs Success : a 4 - element array containing the following information :
        $aArray[0] = X position
        $aArray[1] = Y position
        $aArray[2] = Width
    #ce Success : a 4 - element array containing the following information :

    $aPos2 = WinGetClientSize($GUI)
    #cs Success: a 2-element array containing the following information:
        $aArray[0] = Width of window's client area
    #ce Success: a 2-element array containing the following information:

    ; https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85)
    Local $sRect = DllStructCreate("Int[4]", $lparam) ; outer dimensions (includes borders)
    Local $left = DllStructGetData($sRect, 1, 1)
    Local $top = DllStructGetData($sRect, 1, 2)
    Local $Right = DllStructGetData($sRect, 1, 3)
    Local $bottom = DllStructGetData($sRect, 1, 4)

    ; border width
    Local $iEdgeWidth = ($aPos[2] - $aPos2[0]) / 2
    Local $iHeadHeigth = $aPos[3] - $aPos2[1] - $iEdgeWidth * 2

    Local $aEdges[2]
    $aEdges[0] = $aPos[2] - $aPos2[0] ; x
    $aEdges[1] = $aPos[3] - $aPos2[1] ; y

    $xClientSizeNew = $Right - $left - $aEdges[0]
    $xClientSizeNew = Round($xClientSizeNew / $iStep) * $iStep

    $yClientSizeNew = $bottom - $top - $aEdges[1]
    $yClientSizeNew = Round($yClientSizeNew / $iStep) * $iStep


    Switch $wparam
        Case $WMSZ_RIGHT
            ; calculate the new position of the right border
            DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3)
        Case $WMSZ_BOTTOM
            ; calculate the new position of the bottom border
            DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4)
        Case $WMSZ_BOTTOMRIGHT
            ; calculate the new position of both borders
            DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3)
            DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4)
    EndSwitch

    #cs If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right
        DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 3) - $iStep, 3)
        $xClientSizeNew -= $iStep
        EndIf
        
        If DllStructGetData($sRect, 1, 4) > @DesktopHeight Then ; $bottom
        DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 4), 4)
        $yClientSizeNew -= $iStep
    #ce If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right

    ; check if number of rows has changed
    If $iRows <> $yClientSizeNew / $iStep Then
        _SubArraySet($aMyMatrix[0], 2, $yClientSizeNew / $iStep)
    EndIf

    ; check if number of columns has changed
    If $iCols <> $xClientSizeNew / $iStep Then
        _SubArraySet($aMyMatrix[0], 1, $xClientSizeNew / $iStep)
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZING

; set client area new sizes
; thanks to KaFu
;           ----
; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141
Func _WinSetClientSize($hwnd, $iW, $iH)
    Local $aWinPos = WinGetPos($hwnd)
    Local $sRect = DllStructCreate("int;int;int;int;")
    DllStructSetData($sRect, 3, $iW)
    DllStructSetData($sRect, 4, $iH)
    _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hwnd, $GWL_STYLE), _WinAPI_GetWindowLong($hwnd, $GWL_EXSTYLE))
    WinMove($hwnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize

;
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiControlPanel
; Description ...: Creates a rectangular panel with adequate size to contain the required amount of controls
;                  and then fills it with the same controls by placing them according to the parameters
; Syntax.........: _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $style, $exStyle, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1, $Group = false, , $sGrpTitle = "")
; Parameters ....: $ControlType  - Type of controls to be generated ("Button"; "Text"; .....
;                  $nrPerLine  - Nr. of controls per line in the matrix
;                  $nrOfLines - Nr. of lines in the matrix
;                  $ctrlWidth - Width of each control
;                  $ctrlHeight - Height of each control
;                  $Style - Defines the style of the control
;                  $exStyle - Defines the extended style of the control
;                  $xPanelPos - x Position of panel in GUI
;                  $yPanelPos - y Position of panel in GUI
;                  $xBorder - distance from lateral panel's borders to the matrix (width of left and right margin) default = 0
;                  $yBorder - distance from upper and lower panel's borders to the matrix (width of upper and lower margin) default = 0
;                  $xSpace - horizontal distance between the controls
;                  $ySpace - vertical distance between the controls
;                  $Group - if you want to group the controls (true or false)
;                  $sGrpTitle - title of the group (ignored if above is false)
; Return values .: an 1 based 1d array containing references to each control
;                  element [0] contains an 1d array containing various parameters about the panel
; Author ........: Gianni Addiego (Chimp)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================

Func _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $style = -1, $exStyle = -1, $xPanelPos = 0, $yPanelPos = 0, $xBorder = 0, $yBorder = 0, $xSpace = 1, $ySpace = 1, $Group = False, $sGrpTitle = "")

    Local Static $sAllowedControls = "|Label|Input|Edit|Button|CheckBox|Radio|List|Combo|Pic|Icon|Graphic|"
    If Not StringInStr($sAllowedControls, '|' & $ControlType & '|') Then Return SetError(1, 0, "Unkown control")

    Local $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2)
    Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2)

    Local $hGroup

    If $Group Then
        If $sGrpTitle = "" Then
            $xPanelPos += 1
            $yPanelPos += 1
            $hGroup = GUICtrlCreateGroup("", $xPanelPos - 1, $yPanelPos - 7, $PanelWidth + 2, $PanelHeight + 8)
        Else
            $xPanelPos += 1
            $yPanelPos += 15
            $hGroup = GUICtrlCreateGroup($sGrpTitle, $xPanelPos - 1, $yPanelPos - 15, $PanelWidth + 2, $PanelHeight + 16)
        EndIf
    EndIf

    ; create the controls
    Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1]
    Local $aPanelParams[14] = [ _
            $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _
            $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $hGroup]

    For $i = 0 To $nrPerLine * $nrOfLines - 1
        ; coordinates 1 based
        $col = Mod($i, $nrPerLine) + 1 ; Horizontal position within the grid (column)
        $row = Int($i / $nrPerLine) + 1 ;  Vertical position within the grid (row)
        $left = $xPanelPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder
        $top = $yPanelPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder
        $text = $i + 1 ; "*" ; "." ; "(*)"
        ; create the control(s)
        $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight, $style, $exStyle)")
    Next

    If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1) ; close group
    $aGuiGridCtrls[0] = $aPanelParams
    Return $aGuiGridCtrls
EndFunc   ;==>_GuiControlPanel

; writes a value to an element of an array embedded in another array
Func _SubArraySet(ByRef $aSubArray, $iElement, $vValue)
    $aSubArray[$iElement] = $vValue
EndFunc   ;==>_SubArraySet

Func WM_ACTIVATE($hwnd, $Msg, $wParam, $lParam)
    Local $awPos
    Switch $hwnd
        Case $GUI
            If Not $wParam Then ; GUI Lost focus

                $awPos = WinGetPos($GUI)
                If $awPos[0] < 0 Then $awPos[0] = 0
                If $awPos[1] < 0 Then $awPos[1] = 0
                DllCall($dllUser32, "int", "AnimateWindow", "hwnd", $GUI, "int", 200, "long", "0x00050010") ; hide panel

                WinMove($hPlaceHolder, '', $awPos[0], $awPos[1])
                GUISetState(@SW_SHOW, $hPlaceHolder) ; show placeholder

            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_ACTIVATE

Func WM_LBUTTONDBLCLK($hwnd, $Msg, $wParam, $lParam)
    Local $awPos
    $awPos = WinGetPos($GUI)
    If $awPos[0] < 0 Then $awPos[0] = 0
    If $awPos[1] < 0 Then $awPos[1] = 0
    DllCall($dllUser32, "int", "AnimateWindow", "hwnd", $GUI, "int", 200, "long", "0x00050010") ; hide panel

    WinMove($hPlaceHolder, '', $awPos[0], $awPos[1])
    GUISetState(@SW_SHOW, $hPlaceHolder) ; show placeholder

    Return 0
EndFunc   ;==>WM_LBUTTONDBLCLK

Func _Exit()
    Local $awPos
    $awPos = WinGetPos($GUI)
    If $awPos[0] < 0 Then $awPos[0] = 0
    If $awPos[1] < 0 Then $awPos[1] = 0
    IniWrite($ini, 'GENERAL', 'xIcons', ($aMyMatrix[0])[1]) ; $iNrPerLine
    IniWrite($ini, 'GENERAL', 'LeftPos', $awPos[0]) ; $iLeftPos
    IniWrite($ini, 'GENERAL', 'TopPos', $awPos[1]) ; $iTopPos
EndFunc   ;==>_Exit

Func Test()
    MsgBox(0, 0, ":)", 1)
EndFunc   ;==>Test

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
Posted (edited)

Hi Chimp, very nice work.  I made a few small changes on the UI so It fits more with my needs.

1- Allow move and close from the title bar

2- Auto-hide after 5 secs

3- Tray management of the deck

4- Show with tray and mouse touching borders

5- A few changes to allow in-use timer to reset

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Tool.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; ===============================================================================================================================
; Title .........: LaunchPad
; Description ...: button deck to be used as an applications launcher (and not only)
; Author(s) .....: Chimp (Gianni Addiego)
;                  credits to  @KaFu, @Danyfirex, @mikell (see comments for references)
; ===============================================================================================================================

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>;<WinAPISysWin.au3>
#include <SendMessage.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.

;Turn off redirection for a 32-bit script on 64-bit system.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing
Global Const $WMSZ_LEFT = 1
Global Const $WMSZ_RIGHT = 2
Global Const $WMSZ_TOP = 3
Global Const $WMSZ_TOPLEFT = 4
Global Const $WMSZ_TOPRIGHT = 5
Global Const $WMSZ_BOTTOM = 6
Global Const $WMSZ_BOTTOMLEFT = 7
Global Const $WMSZ_BOTTOMRIGHT = 8
Global Enum $vButton_Tip = 0, $vButton_IconPath, $vButton_IconNumber, $vButton_Command

#cs
    The following 2D array contains the settings that determine the behavior of each "Button"
    namely 4 parameters for each row (for each button);
    [n][0] the tooltip of the button
    [n][1] path of an icon or a file containing icons
    [n][2] the number of the icon (if the previous parameter is a collection)
    [n][3] AutoIt command(s) to be executed directly on button click (or also the name of a function)
#ce

Global Const $aTools[][] = [ _
    ['Settings', 'SHELL32.dll', 177, 'run("explorer.exe shell:::{D20EA4E1-3957-11d2-A40B-0C5020524153}")'], _     ; 'Test()'], _ ; call a function 'Test()'
    ['Windows version', 'winver.exe', 1, 'run("explorer.exe shell:::{BB06C0E4-D293-4f75-8A90-CB05B6477EEE}")'], _      ; or "Run('winver.exe')"
    ['This computer', 'netcenter.dll', 6, 'run("explorer.exe shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")'], _
    ['Devices and Printers', 'SHELL32.dll', 272, 'run("explorer.exe shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")'], _
    ['Folder options', 'SHELL32.dll', 210, 'run("explorer.exe  shell:::{6DFD7C5C-2451-11d3-A299-00C04F8EF6AF}")'], _
    ['Command Prompt', @ComSpec, 1, 'Run(@ComSpec)'], _
    ['Internet Explorer', @ProgramFilesDir & '\Internet Explorer\iexplore.exe', 1, "Run(@ProgramFilesDir & '\Internet Explorer\iexplore.exe')"], _
    ['Media Player', @ProgramFilesDir & '\Windows media player\wmplayer.exe', 1, "Run(@ProgramFilesDir & '\Windows media player\wmplayer.exe')"], _
    ['File browser', @WindowsDir & '\explorer.exe', 1, "Run(@WindowsDir & '\explorer.exe')"], _
    ['Notepad', @SystemDir & '\notepad.exe', 1, "Run(@SystemDir & '\notepad.exe')"], _
    ['Wordpad', @SystemDir & '\write.exe', 1, "Run(@SystemDir & '\write.exe')"], _
    ['Registry editor', @SystemDir & '\regedit.exe', 1, "ShellExecute('regedit.exe')"], _
    ['Connect to', 'netcenter.dll', 19, 'run("explorer.exe shell:::{38A98528-6CBF-4CA9-8DC0-B1E1D10F7B1B}")'], _
    ['Calculator', @SystemDir & '\Calc.exe', 1, "Run(@SystemDir & '\calc.exe')"], _
    ['Control panel', 'control.exe', 1, 'run("explorer.exe shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}")'], _
    ['Users manager', @SystemDir & '\Netplwiz.exe', 1, "ShellExecute('Netplwiz.exe')"], _     ; {7A9D77BD-5403-11d2-8785-2E0420524153}
    ['Run', 'SHELL32.dll', 25, 'Run("explorer.exe Shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}")'], _
    ['Search files', 'SHELL32.dll', 135, 'run("explorer.exe shell:::{9343812e-1c37-4a49-a12e-4b2d810d956b}")'], _
    ['On screen Magnifier', @SystemDir & '\Magnify.exe', 1, "ShellExecute('Magnify.exe')"], _
    ['Paint', @SystemDir & '\mspaint.exe', 1, "Run(@SystemDir & '\mspaint.exe')"], _
    ['Remote desktop', @SystemDir & '\mstsc.exe', 1, " Run('mstsc.exe')"], _
    ['Resource monitoring', @SystemDir & '\resmon.exe', 1, "Run('resmon.exe')"], _
    ['Device manager', 'SHELL32.dll', 13, 'Run("explorer.exe Shell:::{74246bfc-4c96-11d0-abef-0020af6b0b7a}")'], _
    ['Audio', 'SndVol.exe', 1, 'Run("explorer.exe Shell:::{F2DDFC82-8F12-4CDD-B7DC-D4FE1425AA4D}")'], _     ; or 'run(@SystemDir & "\SndVol.exe")']
    ['Task view', 'SHELL32.dll', 133, 'Run("explorer.exe shell:::{3080F90E-D7AD-11D9-BD98-0000947B0257}")'], _
    ['Task Manager', @SystemDir & '\taskmgr.exe', 1, 'Send("^+{ESC}")'], _     ; "Run(@SystemDir & '\taskmgr.exe')"], _
    ['On Screen Keyboard', 'osk.exe', 1, 'ProcessExists("osc.exe") ? False : ShellExecute("osk.exe")'] _     ; <-- ternary example
    ]
; Show desktop       {3080F90D-D7AD-11D9-BD98-0000947B0257}
; Desktop Background {ED834ED6-4B5A-4bfe-8F11-A626DCB6A921}
; IE internet option {A3DD4F92-658A-410F-84FD-6FBBBEF2FFFE}
;       ['Notes', 'StikyNot.exe', 1, "ShellExecute('StikyNot')"], _
;    ['... if Notepad is running' & @CRLF & 'Send F5 to it', 'SHELL32.dll', 167, ' WinExists("[CLASS:Notepad]") ? ControlSend("[CLASS:Notepad]", "", "", "{F5}") : MsgBox(16, ":(", "Notepad not found", 2)'] _     ; Check if Notepad is currently running

Opt("TrayMenuMode", 3)

Global $iStep = 38 ; button size
Global $iNrPerLine = 7

Global $iNrOfLines = Ceiling(UBound($aTools) / $iNrPerLine)

Global $GUI = GUICreate('LaunchPad', 10, 10, -1, -1, $WS_THICKFRAME, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

Global $aMyMatrix = _GuiControlPanel("Button", $iNrPerLine, $iNrOfLines, $iStep, $iStep, BitOR(0x40, 0x1000), -1, 0, 0, 0, 0, 0, 0, False, "")
Global $iPreviousX = ($aMyMatrix[0])[1], $iPreviousY = ($aMyMatrix[0])[2]

For $i = 1 To UBound($aMyMatrix) - 1
  GUICtrlSetResizing($aMyMatrix[$i], $GUI_DOCKALL)   ; (2+32+256+512) so the control will not move during resizing
  If $i <= UBound($aTools) Then
    GUICtrlSetImage($aMyMatrix[$i], $aTools[$i - 1][$vButton_IconPath], $aTools[$i - 1][$vButton_IconNumber])
    GUICtrlSetTip($aMyMatrix[$i], $aTools[$i - 1][$vButton_Tip])
  EndIf
Next

_WinSetClientSize($GUI, ($aMyMatrix[0])[11], ($aMyMatrix[0])[12]) ; thanks to KaFu

GUISetState()

; https://devblogs.microsoft.com/oldnewthing/20110218-00/?p=11453
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_SIZING, "WM_SIZING")
GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

Global $idHide = TrayCreateItem("Hide")
Global $idShow = TrayCreateItem("Show")
TrayCreateItem("") ; Create a separator line.
Global $idExit = TrayCreateItem("Exit")

TraySetState($TRAY_ICONSTATE_SHOW)

_MainLoop()

Func _MainLoop()
  Local $iDeltaX, $iDeltaY, $row, $col, $left, $top
  Global $hTimer = TimerInit()
  Local $aPos

  While 1
    Sleep (80)
    If TimerDiff($hTimer) > 5000 Then
      GUISetState(@SW_HIDE)
      $hTimer = 0
    EndIf
    $aPos = MouseGetPos ()
    If $aPos[0] = 0 Or $aPos[1] = 0 Or $aPos[0] = @DesktopWidth-1 Or $aPos[1] = @DesktopHeight-1 Then
      $hTimer = TimerInit ()
      GUISetState(@SW_SHOW)
    EndIf
    $Msg = GUIGetMsg()
    Switch $Msg
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $aMyMatrix[1] To $aMyMatrix[UBound($aMyMatrix)-1]
        $hTimer = TimerInit ()
        For $i = 1 To UBound($aMyMatrix) - 1
          If $Msg = $aMyMatrix[$i] Then
            If $i <= UBound($aTools) Then
              $dummy = Execute($aTools[$i - 1][3])
            EndIf
          EndIf
        Next
    EndSwitch
        Switch TrayGetMsg()
      Case $idShow
        $hTimer = TimerInit ()
        GUISetState(@SW_SHOW)
            Case $idHide
        GUISetState(@SW_HIDE)
        $hTimer = 0
            Case $idExit
                ExitLoop
        EndSwitch

    ; check if any size has changed
    If $iPreviousX <> ($aMyMatrix[0])[1] Or $iPreviousY <> ($aMyMatrix[0])[2] Then
      ; calculate the variations
      $iDeltaX = Abs($iPreviousX - ($aMyMatrix[0])[1])
      $iDeltaY = Abs($iPreviousY - ($aMyMatrix[0])[2])

      ; if both dimensions changed at the same time, the largest variation prevails over the other
      If $iDeltaX >= $iDeltaY Then       ; keep the new number of columns
        ; calculate and set the correct number of lines accordingly
        _SubArraySet($aMyMatrix[0], 2, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[1]))
      Else       ; otherwise keep the new number of rows
        ; calculate and set the correct number of columns accordingly
        _SubArraySet($aMyMatrix[0], 1, Ceiling((UBound($aMyMatrix) - 1) / ($aMyMatrix[0])[2]))
      EndIf

      ; set client area new sizes
      _WinSetClientSize($GUI, ($aMyMatrix[0])[1] * $iStep, ($aMyMatrix[0])[2] * $iStep)

      ; remember the new panel settings
      $iPreviousX = ($aMyMatrix[0])[1]
      $iPreviousY = ($aMyMatrix[0])[2]

      ; rearrange the controls inside the panel
      For $i = 0 To UBound($aMyMatrix) - 2
        ; coordinates 1 based
        $col = Mod($i, $iPreviousX) + 1         ; Horizontal position within the grid (column)
        $row = Int($i / $iPreviousX) + 1         ; Vertical position within the grid (row number)
        $left = ($aMyMatrix[0])[5] + (((($aMyMatrix[0])[3] + ($aMyMatrix[0])[9]) * $col) - ($aMyMatrix[0])[9]) - ($aMyMatrix[0])[3] + ($aMyMatrix[0])[7]
        $top = ($aMyMatrix[0])[6] + (((($aMyMatrix[0])[4] + ($aMyMatrix[0])[10]) * $row) - ($aMyMatrix[0])[10]) - ($aMyMatrix[0])[4] + ($aMyMatrix[0])[8]
        GUICtrlSetPos($aMyMatrix[$i + 1], $left, $top)
      Next
    EndIf
  WEnd
EndFunc   ;==>_MainLoop

Func WM_NOTIFY ($hwnd, $iMsg, $iwParam, $ilParam)
  If $hwnd = $GUI Then $hTimer = TimerInit ()
  Return $GUI_RUNDEFMSG
EndFunc

; Allow/Disallow specific borders resizing
; thanks to Danyfirex
;           ---------
; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445748
Func WM_NCHITTEST($hwnd, $iMsg, $iwParam, $ilParam)
  If $hwnd = $GUI Then
    $hTimer = TimerInit()
    Local $iRet = _WinAPI_DefWindowProc($hwnd, $iMsg, $iwParam, $ilParam)
    ; https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest
    If $iRet = $HTBOTTOM Or $iRet = $HTRIGHT Or $iRet = $HTBOTTOMRIGHT Or $iRet = $HTCAPTION Or $iRet = $HTCLOSE Then
      Return $iRet       ; default process of border resizing
    Else     ; resizing not allowed
      Return $HTCLIENT       ; do like if cursor is in the client area
    EndIf
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

; controls and process resizing operations in real time
; thanks to mikell
;           ------
; https://www.autoitscript.com/forum/topic/201464-partially-resizable-window-how-solved-by-danyfirex-%F0%9F%91%8D/?do=findComment&comment=1445754
Func WM_SIZING($hwnd, $iMsg, $wparam, $lparam)
  ; https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-sizing
  Local $iCols = ($aMyMatrix[0])[1]
  Local $iRows = ($aMyMatrix[0])[2]
  Local $xClientSizeNew, $yClientSizeNew

  #cs $wparam
      The edge of the window that is being sized.

      $lparam
      A pointer to a RECT structure with the screen coordinates of the drag rectangle.
      To change the size or position of the drag rectangle, an application must change the members of this structure.

      Return value
      Type: LRESULT

  #ce $wparam

  $aPos = WinGetPos($GUI)
  #cs Success : a 4 - element array containing the following information :
      $aArray[0] = X position
      $aArray[1] = Y position
      $aArray[2] = Width
  #ce Success : a 4 - element array containing the following information :

  $aPos2 = WinGetClientSize($GUI)
  #cs Success: a 2-element array containing the following information:
      $aArray[0] = Width of window's client area
  #ce Success: a 2-element array containing the following information:

  ; https://docs.microsoft.com/en-us/previous-versions//dd162897(v=vs.85)
  Local $sRect = DllStructCreate("Int[4]", $lparam)   ; outer dimensions (includes borders)
  Local $left = DllStructGetData($sRect, 1, 1)
  Local $top = DllStructGetData($sRect, 1, 2)
  Local $Right = DllStructGetData($sRect, 1, 3)
  Local $bottom = DllStructGetData($sRect, 1, 4)

  ; border width
  Local $iEdgeWidth = ($aPos[2] - $aPos2[0]) / 2
  Local $iHeadHeigth = $aPos[3] - $aPos2[1] - $iEdgeWidth * 2

  Local $aEdges[2]
  $aEdges[0] = $aPos[2] - $aPos2[0]   ; x
  $aEdges[1] = $aPos[3] - $aPos2[1]   ; y

  $xClientSizeNew = $Right - $left - $aEdges[0]
  $xClientSizeNew = Round($xClientSizeNew / $iStep) * $iStep

  $yClientSizeNew = $bottom - $top - $aEdges[1]
  $yClientSizeNew = Round($yClientSizeNew / $iStep) * $iStep


  Switch $wparam
    Case $WMSZ_RIGHT
      ; calculate the new position of the right border
      DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3)
    Case $WMSZ_BOTTOM
      ; calculate the new position of the bottom border
      DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4)
    Case $WMSZ_BOTTOMRIGHT
      ; calculate the new position of both borders
      DllStructSetData($sRect, 1, $left + $xClientSizeNew + $aEdges[0], 3)
      DllStructSetData($sRect, 1, $top + $yClientSizeNew + $aEdges[1], 4)
  EndSwitch

  #cs If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right
      DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 3) - $iStep, 3)
      $xClientSizeNew -= $iStep
      EndIf

      If DllStructGetData($sRect, 1, 4) > @DesktopHeight Then ; $bottom
      DllStructSetData($sRect, 1, DllStructGetData($sRect, 1, 4), 4)
      $yClientSizeNew -= $iStep
  #ce If DllStructGetData($sRect, 1, 3) > @DesktopWidth Then ; $Right

  ; check if number of rows has changed
  If $iRows <> $yClientSizeNew / $iStep Then
    _SubArraySet($aMyMatrix[0], 2, $yClientSizeNew / $iStep)
  EndIf

  ; check if number of columns has changed
  If $iCols <> $xClientSizeNew / $iStep Then
    _SubArraySet($aMyMatrix[0], 1, $xClientSizeNew / $iStep)
  EndIf

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZING

; set client area new sizes
; thanks to KaFu
;           ----
; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141
Func _WinSetClientSize($hwnd, $iW, $iH)
  Local $aWinPos = WinGetPos($hwnd)
  Local $sRect = DllStructCreate("int;int;int;int;")
  DllStructSetData($sRect, 3, $iW)
  DllStructSetData($sRect, 4, $iH)
  _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hwnd, $GWL_STYLE), _WinAPI_GetWindowLong($hwnd, $GWL_EXSTYLE))
  WinMove($hwnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize

;
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiControlPanel
; Description ...: Creates a rectangular panel with adequate size to contain the required amount of controls
;                  and then fills it with the same controls by placing them according to the parameters
; Syntax.........: _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $style, $exStyle, $xPos = 0, $yPos = 0, $xBorder, $yBorder, $xSpace = 1, $ySpace = 1, $Group = false, , $sGrpTitle = "")
; Parameters ....: $ControlType  - Type of controls to be generated ("Button"; "Text"; .....
;                  $nrPerLine  - Nr. of controls per line in the matrix
;                  $nrOfLines - Nr. of lines in the matrix
;                  $ctrlWidth - Width of each control
;                  $ctrlHeight - Height of each control
;                  $Style - Defines the style of the control
;                  $exStyle - Defines the extended style of the control
;                  $xPanelPos - x Position of panel in GUI
;                  $yPanelPos - y Position of panel in GUI
;                  $xBorder - distance from lateral panel's borders to the matrix (width of left and right margin) default = 0
;                  $yBorder - distance from upper and lower panel's borders to the matrix (width of upper and lower margin) default = 0
;                  $xSpace - horizontal distance between the controls
;                  $ySpace - vertical distance between the controls
;                  $Group - if you want to group the controls (true or false)
;                  $sGrpTitle - title of the group (ignored if above is false)
; Return values .: an 1 based 1d array containing references to each control
;                  element [0] contains an 1d array containing various parameters about the panel
; Author ........: Gianni Addiego (Chimp)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================

Func _GuiControlPanel($ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, $style = -1, $exStyle = -1, $xPanelPos = 0, $yPanelPos = 0, $xBorder = 0, $yBorder = 0, $xSpace = 1, $ySpace = 1, $Group = False, $sGrpTitle = "")

  Local Static $sAllowedControls = "|Label|Input|Edit|Button|CheckBox|Radio|List|Combo|Pic|Icon|Graphic|"
  If Not StringInStr($sAllowedControls, '|' & $ControlType & '|') Then Return SetError(1, 0, "Unkown control")

  Local $PanelWidth = (($ctrlWidth + $xSpace) * $nrPerLine) - $xSpace + ($xBorder * 2)
  Local $PanelHeight = (($ctrlHeight + $ySpace) * $nrOfLines) - $ySpace + ($yBorder * 2)

  Local $hGroup

  If $Group Then
    If $sGrpTitle = "" Then
      $xPanelPos += 1
      $yPanelPos += 1
      $hGroup = GUICtrlCreateGroup("", $xPanelPos - 1, $yPanelPos - 7, $PanelWidth + 2, $PanelHeight + 8)
    Else
      $xPanelPos += 1
      $yPanelPos += 15
      $hGroup = GUICtrlCreateGroup($sGrpTitle, $xPanelPos - 1, $yPanelPos - 15, $PanelWidth + 2, $PanelHeight + 16)
    EndIf
  EndIf

  ; create the controls
  Local $aGuiGridCtrls[$nrPerLine * $nrOfLines + 1]
  Local $aPanelParams[14] = [ _
      $ControlType, $nrPerLine, $nrOfLines, $ctrlWidth, $ctrlHeight, _
      $xPanelPos, $yPanelPos, $xBorder, $yBorder, $xSpace, $ySpace, $PanelWidth, $PanelHeight, $hGroup]

  For $i = 0 To $nrPerLine * $nrOfLines - 1
    ; coordinates 1 based
    $col = Mod($i, $nrPerLine) + 1     ; Horizontal position within the grid (column)
    $row = Int($i / $nrPerLine) + 1     ;  Vertical position within the grid (row)
    $left = $xPanelPos + ((($ctrlWidth + $xSpace) * $col) - $xSpace) - $ctrlWidth + $xBorder
    $top = $yPanelPos + ((($ctrlHeight + $ySpace) * $row) - $ySpace) - $ctrlHeight + $yBorder
    $text = $i + 1     ; "*" ; "." ; "(*)"
    ; create the control(s)
    $aGuiGridCtrls[$i + 1] = Execute("GUICtrlCreate" & $ControlType & "($text, $left, $top, $ctrlWidth, $ctrlHeight, $style, $exStyle)")
  Next

  If $Group Then GUICtrlCreateGroup("", -99, -99, 1, 1)   ; close group
  $aGuiGridCtrls[0] = $aPanelParams
  Return $aGuiGridCtrls
EndFunc   ;==>_GuiControlPanel

; writes a value to an element of an array embedded in another array
Func _SubArraySet(ByRef $aSubArray, $iElement, $vValue)
  $aSubArray[$iElement] = $vValue
EndFunc   ;==>_SubArraySet

Func Test()
  MsgBox(0, 0, ":)", 1)
EndFunc   ;==>Test

 

Edited by Nine

Share this post


Link to post
Share on other sites

In order to avoid the multiple execution I have inserted the following two lines at the beginning of the script.

#include <_SingleScript.au3>  ; http://www.autoitscript.com/forum/index.php?showtopic=178681
_SingleScript()

 


App: Au3toCmd              UDF: _SingleScript()                             

Share this post


Link to post
Share on other sites

And this line in the array shows all the tasks

['All tasks', 'SHELL32.dll', 178, 'run("explorer.exe shell:::{ED7BA470-8E54-465E-825C-99712043E01C}")'], _

 


App: Au3toCmd              UDF: _SingleScript()                             

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By t0nZ
      Often I need to create a panel to monitor a lot of things (users, files, items etc) so I use this piece of code to create a dynamic grid of buttons.
      The number of buttons is variable, and it's related to the size of the gui, the size of the buttons and the distance between buttons.
      Every "button" is a set of three with a real button stacked on the top of two labels, imagine reading a .CSV file or an array or a database and displaying all the things using the labels (Text and COLOR too) and clickin' on the relative button you can call further info on the item or call a particular function.
      So you can decide the number of the buttons, the width of the buttons, and also the distance  between buttons.
      It's quick and dirty, simple  and very improvable (I know..) so fell free to play with the code.
      ;TEST ;GOL-Grill ;Grill test/template ; (c) 2019 NSC ; V.0.6 #Region ;************ Includes ************ #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <ProgressConstants.au3> #include <_GOLLOG.au3>; NSC first UDF #EndRegion ;************ Includes ************ Dim $agButton[1] Global $ButtonU, $rProgress, $form1, $labeltot, $ntotButtonS ; the number of buttons is variable based on the guisize, the button size and button distance, three examples.... ;Global $guiwidth = 850, $guiheight = 500, $buttonW = 150, $buttonHDistance = 10, $buttonVDistance = 20 ; SMALL GUI / BIG BUTTONS <- try it ! Global $guiwidth = 1500, $guiheight = 700, $buttonW = 90 , $buttonHDistance = 29, $buttonVDistance = 3; BIG GUI / SMALL BUTTONS ;Global $guiwidth = 1200, $guiheight = 800, $buttonW = 300, $buttonHDistance = 30, $buttonVDistance = 7; last two variables are horizontal and vertical distance between buttons Global $ver = "V.0.6" Gollog(">>>>> START") Dim $aResult[11] = [10, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] ; this is an example, it can be an array, a DB, a .text file read in real time. Gui() Gollog("start analyzing...") Monitor() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE CLOSEClicked() Exit Case $ButtonU Monitor() Case Else For $i = 1 To $ntotButtonS If $nMsg = $agButton[$i] Then $Bhit = GUICtrlRead($agButton[$i]) infoB($Bhit) EndIf Next EndSwitch WEnd Func Gui() $form1 = GUICreate("Buttons on a grill " & $ver & " (c) NSC 2019", $guiwidth, $guiheight, 90, 10) $ButtonU = GUICtrlCreateButton("Update", 2, 2, 170, 50) $labeltot = GUICtrlCreateLabel("Total found", 5, 55) $Gollogedit = GUICtrlCreateEdit("", 2, $guiheight - 255, 180, 250, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_BORDER)) $rProgress = GUICtrlCreateProgress($guiwidth - 18, 5, 16, $guiheight - 7, BitOR($PBS_SMOOTH, $PBS_VERTICAL, $WS_BORDER)) GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, 0x000000) GUISetState(@SW_SHOW) EndFunc ;==>Gui Func Monitor() GUIDelete($form1) Gui() $leftSTART = 186 ;left align $topSTART = 5 ;start from top $lineDOWN = 45 + $buttonVDistance ; vertical line distance 45 is buttons very near $extraHSTEP = 3 ; extra line distance $buttonSEMIH = 15 ; height of one of the 3 vertical impiled semibuttons $separatorSEMIH = 2 ;vertical distance between 3 semibuttons $separatorW = 2 ;aux horizontal distance ;---------- derived measures $rightLIMIT = $guiwidth - 123 ; right limit befor Carriage Return $leftINCREMENT = $buttonHDistance + $buttonW ; horizontal increment button after button $leftSTEP = $leftSTART ;incremental horizontal $topSTEP = $topSTART ;incremental vertical $foundB = $aResult[0] GUICtrlSetData($labeltot, "Found n°" & $foundB) $ntotButtonS = 0 $nomorebuttons = 0 For $i = 1 To $foundB Local $itemFound = $aResult[$i] ;\TA1000 Gollog($itemFound) GUICtrlCreateGroup('', $leftSTEP, $topSTEP - 3, $buttonW + 3, 50) ;______first-----------------------------_______line___________________UNO________11111_____\\\\\\\\\\------------ Local $textbutton = "button n°" & $i _ArrayAdd($agButton, GUICtrlCreateButton($textbutton, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat)) GUICtrlSetBkColor(-1, 0xccffcc) ;green, sort of GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) ;___second__________line___________________DUE ________222222-------------------------------------------------------------------- Local $textLINE2 = $itemFound GUICtrlCreateLabel($textLINE2, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, 0xD2D7A8) GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) ; __third______line________tre___________________________________________________________333333-3333333-333333333-333333-33333-33333-3333-------------------------------- Local $textLINE3 = "line3" GUICtrlCreateLabel($textLINE3, $leftSTEP + $separatorW, $topSTEP + $buttonSEMIH + $buttonSEMIH + $separatorSEMIH, $buttonW, $buttonSEMIH, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; NSC modify GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 7, -1, -1, 'verdana') GUICtrlSetColor(-1, 0x000000) $ntotButtonS += 1 GUICtrlSetData($rProgress, (100 * $ntotButtonS / $foundB)) If $leftSTEP + $buttonW < $rightLIMIT Then ; $leftSTEP += $leftINCREMENT ;53 Else $leftSTEP = $leftSTART $topSTEP += $lineDOWN If $topSTEP >= $guiheight - 50 Then $nomorebuttons = 1 Gollog("displayed " & $ntotButtonS & " buttons") Gollog("NO more buttons !") EndIf EndIf Sleep(100) ; REMOVE is only for demo Next While $nomorebuttons = 0 ; draw empty buttons (nice to do) $ntotButtonS += 1 _ArrayAdd($agButton, GUICtrlCreateButton("B-" & $ntotButtonS, $leftSTEP + $separatorSEMIH, $topSTEP + $extraHSTEP, $buttonW, $buttonSEMIH, $BS_flat)) If $leftSTEP + $buttonW < $rightLIMIT Then ; $leftSTEP += $leftINCREMENT Else $leftSTEP = $leftSTART $topSTEP += $lineDOWN If $topSTEP >= $guiheight - 50 Then $nomorebuttons = 1 Gollog("displayed " & $ntotButtonS & " buttons") Gollog("NO more buttons !") EndIf EndIf WEnd GUISetState(@SW_SHOW) EndFunc ;==>Monitor Func infoB($Bhit) ; this function act on the pressed button, it's an example so assign the task you need. gollog("infoB -> " & $Bhit) EndFunc ;==>infoB Func CLOSEClicked() MsgBox(64, "exit", "program exiting", 1) Gollog("<---STOP") Exit EndFunc ;==>CLOSEClicked You will need also the Include from this post for the LOG (Gollog) instructions, but you can also just remove the gollog and the EDIT box.
      Look at the screenshot, It's from an APP made using this code.

      21/11/2019 V.0.6
      Script lightly updated with better management of buttons size and distance.
       
    • By nacerbaaziz
      Hi dear
      I have a request
      I want a simplified example of how to create the toolbar
      With an example of pressing the buttons inside this bar
      for example
      Toolbar contains Three buttons
      open, save, And delete
      and i want  If i press a button from among these buttons a MSGBox appears
      I know this is easy
      But I did not know how to do it
      I hope you help me
      I apologize for the inconvenience
      Thank you in advance
    • By t0nZ
      Hello to all, my problem is to have in the same gui buttons (static and dinamically generated ones) and an edit control.
      The gui also adjust its height in function of button number.
      Below you see an ugly interface and the long buttons at the bottom are dinamically generated reading from a txt file.

      Because I have "static" buttons and dynamically generated ones it's not workin' well your method, also the EDIT area is updated (is a live log) and this is detected as GUI events, and this makes the guigetmsg() "dirty".
      Have you any ideas to make it work in better way ?  I only think about creating two different GUIs to not interfere one with the other one.
      My code is this
      While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GOLLOG("<<<< STOP <<<<") Exit #cs ; test 1 Case $iStart To $iEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< gollog(GUICtrlRead($nMsg) & ' ' & 'was pressed' & @CRLF) $iValueToWorkWith = $nMsg - $iStart ; Adjust as required gollog($iValueToWorkWith) ;ExitLoop #ce Case $buttonarray[1] To $buttonarray[UBound($buttonarray) - 1] $UMDguimsg = GUICtrlRead($nMsg) If $UMDguimsg <> 0 Then GOLLOG("ButtonText=[" & $UMDguimsg & "] was clicked") EndIf Case $Bcerca If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") ;Multisearch("username-machinedescription") Case $Block lock() Case $Busergroups usergroups() Case $Bvnc VNC() Case $Icercato If BitAND(GUICtrlRead($idradio1), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("username-machinedescription") If BitAND(GUICtrlRead($idradio2), $GUI_CHECKED) = $GUI_CHECKED Then Multisearch("machinename-username") #CS Multisearch("username-machinedescription") Case Else msgbox(64,"test",GUIGetMsg()) $UMDguimsg = GUICtrlRead(GUIGetMsg()) If $UMDguimsg <> $salvaUMDguimsg Then MsgBox(64, "test2", $UMDguimsg) $salvaUMDguimsg = $UMDguimsg #CE EndIf EndSwitch WEnd Thank you , cheers,
    • By fopetesl
      OK, still learning SOLVED! $WS_EX_COMPOSITED hides buttons?
      I've read, run examples but cannot show action buttons in tabs in a GUI.
      I've run the GUICtrlCreateTabItem function example and, of course, it works.
      Mine doesn't:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <MenuConstants.au3> #include <TabConstants.au3> #include <ColorConstants.au3> $hGUI = GUICreate("My GUI Tab", @DesktopWidth * 1, @DesktopHeight * 1, 0, 0,-1, $WS_EX_COMPOSITED) $hTab = GUICtrlCreateTab(10, 10, 640, 480,$TCS_HOTTRACK) ; Create tabitems ;For $i = 0 To 2 GUICtrlCreateTabItem(" Scan Sample ") ; $idButton1 = GUICtrlCreateButton("Button " & 0, 20 + (0 * 100), 40 + (0 * 50), 80, 30) ; $idButton1 = GUICtrlCreateButton("00", 20, 50, 80, 30) GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlCreateButton("OK0", 20, 50, 50, 20) GUICtrlCreateInput("default", 80, 50, 70, 20) GUICtrlCreateTabItem(" Database ") GUICtrlCreateButton("Button " & 1, 20 + (1 * 100), 40 + (1 * 50), 80, 30) GUICtrlCreateTabItem(" Software ") GUICtrlCreateButton("Button " & 2, 20 + (2 * 100), 40 + (2 * 50), 80, 30) ;Next ; Close Tab definiton GUICtrlCreateTabItem("") ; Set the color of the label control. ; GUICtrlSetColor($idButton1, 0x002E7A) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd It just shows:
      whatever I try.  So I've missed, again?, that I do not have the focus?
       
×
×
  • Create New...