Jump to content
Sign in to follow this  
RogFleming

Adding Icon and Text to a button control

Recommended Posts

RogFleming

So I trying to create a dynamic right docked launchbar with the process when started will look

into a specific directoryu and make launchable shortcuts in the toolbar. I having major issues creating these

shortcuts and making them work as they should. I trying to make my out window launchbar, without having to hack the registry.

It would just me nice to have a dynamic folder on teh desktop which could be docked and autohidden just like a windows toolbar does.

He is my attempt, but I have issues with getting the teh image and text to be

combined and if either is click to have the process found and executed.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <Misc.au3>
#include <WinAPI.au3>

Opt("GuiOnEventMode", 1)

Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 1)
AutoItSetOption("GUICloseOnESC",0);disable ESC; use the icon to exit
Opt('MustDeclareVars', 1)
Global $hGUI, $hWnd, $Edit, $wW, $wH, $sX, $sY, $sW, $sH, $sR, $lbl
Global $mTray, $mTrayX, $mpos, $App1, $search, $file, $appname, $Selected, $TGUI, $btn[99], $hImage[99]
Toolbar()


; example 1
Func Toolbar()
    Local $msg,$i
    Local $Apps[1]
    Local $prog_dir = "C:\Program Files\XyLoc\XSO Client\Shortcuts\"
    $hGUI =GUICreate("XSO Toolbar",74,@DesktopHeight - 30,@DesktopWidth - 74,0,$WS_EX_MDICHILD,$WS_EX_TOOLWINDOW)
    GUISetBkColor(21989)
    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ;$App1 = IniRead("C:\Program Files\XyLoc\XSO Client\DATA\toolbar.ini","Shortcuts","Program0","0")
    $search = FileFindFirstFile($prog_dir&"*.exe")
    If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
    Local $i=0
    Local $l=21
    Local $t=2

    While 1
        $file = FileFindNextFile($search)
        $appname =StringTrimRight($file,4)
        If @error Then ExitLoop

        If $file <> "" Then
            $btn[$i]=GUICtrlCreateLabel($appname,0,$t+32,74,20,BitOR($SS_CENTER,$SS_CENTERIMAGE))
            GUICtrlCreateIcon($prog_dir&$appname&".ico",1,$l,$t,32,32)
            GUICtrlSetOnEvent($btn[$i], "Pressed")
            $t=$t+66
            $i=$i+1
        Else
            ExitLoop
        EndIf
    WEnd
    FileClose($search)

While 1
        sleep(50)
        $mpos = MouseGetPos()
        ;ConsoleWrite($BN_CLICKED)
        IF $mpos[0] < @DesktopWidth-68 Then
            GUISetState(@SW_HIDE,$hGUI)
        ElseIf $mpos[0] > @DesktopWidth-10 Then
            GUISetState(@SW_SHOW,$hGUI)
        EndIf

    WEnd
GUIDelete()
EndFunc   ;==>Example1

Func Pressed()
    $Selected = _GUICtrlButton_GetText(@GUI_CtrlHandle)
    ConsoleWrite("OK Pressed"&" "&"ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle&@CRLF)
    ConsoleWrite($Selected&@CRLF)
    Run("C:\Program Files\XyLoc\XSO Client\Shortcuts\"&$Selected)
EndFunc   ;==>OKPressed

Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
    Local $iSize = 16
    If $fLarge Then $iSize = 32

    Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
    If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
        _GUIImageList_AddBitmap($hImage, $sFile)
    Else
        _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
    EndIf
    Return $hImage
EndFunc  ;==>_GetImageListHandle

Share this post


Link to post
Share on other sites
picea892

maybe this example will give you some ideas.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.