Jump to content
Sign in to follow this  
gcue

trying to set toolbar font color

Recommended Posts

gcue

i tried this but it didnt work

$font_color="0xE9E9E9"

button_txt = _GUICtrlToolbar_AddString($dToolbar, "Support")

_GUICtrlToolbar_AddButton($dToolbar, $idNew, 0, $button_txt)

GUICtrlSetColor(-1, $font_color)

any ideas?

Share this post


Link to post
Share on other sites
gcue

ive also looked into _GUICtrlToolbar_SetColorScheme - dont see how it can be done really =/

Share this post


Link to post
Share on other sites
gcue

if theres no way meant to do this.. how about a workaround?

Share this post


Link to post
Share on other sites
reb

try moving "GUICtrlSetColor(-1, $font_color)"

up one line -- just under button text.

I've found that these color assignments should be after the item you want affected .

REB


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites
rover

Faraway, So close!

it's doable, but... (with MS there's always a but)

I'm assuming you mean a toolbar in your script, and not a toolbar in another process.

If you mean an external process then I don't know if its doable. (look into API hook/DLL injection into another process)

you can set button text colour by custom drawing the toolbar,

however, to use visual styles/themes this only works with Vista and up.

In XP visual style/theme must be turned off for toolbar control with SetWindowTheme API

I'll leave you to your own gnashing of teeth and rending of garments

over Microsofts intransigence when it comes to updating the common controls with new features

always frustratingly one OS version behind, and many that could have been there from the start.</rant>

this can also be done with ownerdrawing, I don't have an example, but skinning dlls do this

(skincrafter DLL can set text colour for all toolbar buttons, but not individually)

ownerdrawn controls requires additional UxTheme DLL API calls,

themechanged/drawitem/measureitem message handling and you have to do the painting yourself.

with customdrawn controls, most of the work is done for you by windows.

regarding _GUICtrlToolbar_SetColorScheme(), it doesn't paint text colour.

MSDN: "The toolbar control uses the color scheme information when drawing the 3-D elements in the control.

When visual styles are enabled, this message has no effect."

_GUICtrlToolbar_SetColorScheme($hToolbar, 0x00ffff, 0x800000)

with this example all it did was paint yellow between the buttons.

Example: Customdrawn toolbar colored text

if using custom fonts then text measurement and some adjusting of the toolbar metrics is needed to resize button,

its not quite worked out properly in this example.

"$TBSTYLE_CUSTOMERASE - Generates $NM_CUSTOMDRAW messages when the toolbar processes $WM_ERASEBKGND messages"

I haven't read any clear description of its purpose, NM_CUSTOMDRAW messages are sent to the main form WM_NOTIFY handler without it.

I'm assuming its some kind of additional buffering for flicker if toolbar is heavily customdrawn...

that's as much input as I can give, however YMMV with the forums knowledgeable Win32 programmers

screenshot shows unthemed transparent flat style toolbar on visual style with background texture and hot track button background colour.

post-22637-1245598302_thumb.png

example tested in Win2000, XP and Vista

Edit: added text highlighting on third button

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiToolbar.au3>
#Include <GuiRebar.au3>
#Include <GuiImageList.au3>


Opt('MustDeclareVars', 1)

;Global Const $tagNMHDR = "hwnd hWndFrom;int IDFrom;int Code"
Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;hwnd HDC;int Rect[4];long_ptr ItemSpec;uint ItemState;long_ptr ItemParam"
Global Const $tagNMTBCUSTOMDRAW = $tagNMCUSTOMDRAWINFO & ";hwnd hbrMonoDither;hwnd hbrLines;hwnd hpenLines;dword clrText;dword clrMark;" & _
"dword clrTextHighlight;dword clrBtnFace;dword clrBtnHighlight;" & _
"dword clrHighlightHotTrack;int rcText[4];int nStringBkMode;int nHLStringBkMode;int iListGap"

Global Const $TBCDRF_HILITEHOTTRACK = 0x20000
Global Const $TBCDRF_USECDCOLORS  = 0x00800000; Vista and up

Global $hToolbar, $hFont
Global Enum $id1 = 1000, $id2, $id3
Global $iIcon1 = 27, $iIcon2 = 110

_Main()

Func _Main()

    Local $hGUI, $hReBar, $hToolBarImageListNorm, $aStrings[3]
    $hGUI = GUICreate("Customdrawn toolbar colour text - Vista or without toolbar theme in XP/Win2000", 600, 60)
    GUISetBkColor(0xFFFFFF)
    
;$TBSTYLE_TRANSPARENT $TBSTYLE_FLAT $TBSTYLE_CUSTOMERASE
    $hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN, $TBSTYLE_CUSTOMERASE))
    $hReBar = _GUICtrlReBar_Create($hGUI, BitOR($CCS_TOP, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "wstr", "", "wstr", ""); theme off
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "ptr", 0, "ptr", 0) ; theme on
    
    Switch @OSVersion
        Case "WIN_XP"
        ; to change text colour in XP, themes must be turned off for toolbar
            DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "wstr", "", "wstr", "");theme off
        Case "WIN_VISTA"
            $iIcon1 = 35
            $iIcon2 = 286
        Case "WIN_2000"
            $iIcon1 = 101
            $iIcon2 = 4
    EndSwitch
    
    $hToolBarImageListNorm = _GUIImageList_Create(32, 32, 5, 3)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", $iIcon2, True)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", $iIcon1, True)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @AutoItExe, 0, True)
    _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm)
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "Open")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "Exit")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "AutoIt v3")
    
    _GUICtrlToolbar_AddButton($hToolbar, $id1, 0, $aStrings[0], $BTNS_AUTOSIZE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $id2, 1, $aStrings[1], $BTNS_AUTOSIZE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $id3, 2, $aStrings[2], $BTNS_AUTOSIZE)
    
    _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0)

    $hFont = _WinAPI_CreateFont(14, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, _
    $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, BitOR($DEFAULT_PITCH, $FF_DONTCARE), "Arial")

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUISetState()
    
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    Exit
EndFunc  ;==>_Main


Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam

    Local $tNMTBCUSTOMDRAW, $hWndFrom, $iCode;, $iItem
    Local $tNMHDR, $iDrawStage, $iItemSpec, $hDC, $iItemState;$tNMTOOLBAR
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
;$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
    $hWndFrom   = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode      = DllStructGetData($tNMHDR, "Code")
;$iItem         = DllStructGetData($tNMHDR, "iItem")

    Switch $hWndFrom
        Case $hToolbar
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    
                    $tNMTBCUSTOMDRAW = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
                    $iDrawStage = DllStructGetData($tNMTBCUSTOMDRAW, "DrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage <> $CDDS_ITEMPREPAINT Then Return $CDRF_DODEFAULT
                    
                    $iItemSpec = DllStructGetData($tNMTBCUSTOMDRAW, "ItemSpec")
                    $hDC = DllStructGetData($tNMTBCUSTOMDRAW, "HDC")
                    $iItemState = DllStructGetData($tNMTBCUSTOMDRAW, "ItemState")
                    
                    #cs
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!ItemSpec ................", ": ", $iItemSpec) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrText ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrText"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrMark ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrMark"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrTextHighlight ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrTextHighlight"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrBtnFace ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrBtnFace"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrBtnHighlight ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrBtnHighlight"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrHighlightHotTrack ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrHighlightHotTrack"))) & @crlf & @crlf )
                    #ce
                
                    Switch $iItemSpec
                        Case $id1; Open
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x000000FF); RED
                        ;set text colour ($TBCDRF_USECDCOLORS required for Vista (ignored in Win 2000/XP), otherwise return $CDRF_DODEFAULT)
                            If @OSVersion = "WIN_VISTA" Then Return $TBCDRF_USECDCOLORS
                        Case $id2; Exit
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00008B00);GREEN
                            ;set text colour ($TBCDRF_USECDCOLORS required for Vista (ignored in Win 2000/XP), otherwise return $CDRF_DODEFAULT)
                            If @OSVersion = "WIN_VISTA" Then Return $TBCDRF_USECDCOLORS
                        Case $id3; AutoIt v3
                        ; set font/text colour/hot track colour
                        ;resize button for width of custom font text string (a rough example that needs additional code to properly resize button)
                        ;DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FF0000);BLUE
                            _WinAPI_SelectObject($hDC, $hFont) 
                            Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, _GUICtrlToolbar_GetButtonText($hToolbar, $id3))
                            Local $iWidth = DllStructGetData($tSize, "X")
                            DllStructSetData($tNMTBCUSTOMDRAW, "rcText", $iWidth, 3)
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FF0000);BLUE
                            
                            Switch $iItemState;optionally set hot track highlight colour of button background
                                Case $CDIS_HOT;WindowsConstants.au3
                                    DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FFDF55);LIGHT BLUE
                                ;not set unless $TBCDRF_HILITEHOTTRACK returned
                                    DllStructSetData($tNMTBCUSTOMDRAW, "clrHighlightHotTrack", 0x00FFFFFF);change hot track button background colour - works in XP
                                    Return BitOR($TBCDRF_HILITEHOTTRACK, $CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set hot track background colour, font and text colour
                            EndSwitch
                            
                            Return BitOR($CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set font and text colour
                    EndSwitch

                    Return $CDRF_DODEFAULT; The control will draw itself
                ;Return BitOR($TBCDRF_HILITEHOTTRACK, $CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set hot track background colour, font and text colour (Vista) 
                ;Return BitOR($TBCDRF_HILITEHOTTRACK, $TBCDRF_USECDCOLORS);set hot track background colour and text colour (Vista) 
                ;Return BitOR($CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set font and text colour (Vista)
                ;Return $TBCDRF_HILITEHOTTRACK;set hot track background colour
                ;Return $CDRF_NEWFONT;set font
                ;Return $TBCDRF_USECDCOLORS;set text colour (Vista)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>_WM_NOTIFY
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
gcue

very nice example. nice to know there's so many options. =)

however, i am only trying to set one color for all the toolbar text

u mentioned different ways of doing this.. does one take up more memory than another?

i am trying to set it up for this toolbar (anything conflicting?):

#include <GuiToolbar.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <GuiRebar.au3>
#include <GuiImageList.au3>

Opt('MustDeclareVars', 1)

$Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $hGUI, $hToolbar, $Tbar, $TbarMenu, $iMemo, $msg, $aSize
Global $iItem ; Command identifier of the button associated with the notification.
Global Enum $idRemoteScreenShot = 1000, $idPushKillNotes, $idWhoseLoggedOn, $idMustHave, $idGetIP, $idSysInfo, $idLocalMaps, $idWhosAdmin, $idUserHistory ;Common
Global Enum $idLookupLocation = 1100, $idDefaultPrinter, $idNonIPrint, $idEncryptionStatus, $idMACnHD, $idDPIsetting, $idUptime ;Hardware
Global Enum $idActiveProcesses = 1200, $idKillProcess, $idInstalledPrograms, $idNotesDataDir, $idImageBuild, $idRecoverySol ;Software
Global $netsupport_button_txt, $manage_button_txt, $common_button_txt, $hardware_button_txt, $software_button_txt
Global Enum $idNetSupport = 2000, $idManage, $idCommon, $idHardware, $idSoftware


; Create GUI
$hGUI = GUICreate("Toolbar", 500, 300)
$hToolbar = _GUICtrlToolbar_Create($hGUI)
$aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)

;~  _GUICtrlToolbar_SetExtendedStyle($hToolbar, $TBSTYLE_EX_DRAWDDARROWS)
;~ _GUICtrlToolbar_SetColorScheme($hToolbar, 16774367, 16774367)

$iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

$Tbar = GUICtrlCreateDummy() ; dummy control to receive toolbar events
$TbarMenu = GUICtrlCreateDummy() ; dummy control to receive toolbar button dropdown menu events

GUISetState()

toolbar()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
                        Case $Tbar       ; toolbar buttons
                _ToolBar_Click(GUICtrlRead($Tbar))
        Case $TbarMenu ; toolbar button dropdown menu
            _ToolBarMenu(GUICtrlRead($TbarMenu))
    EndSwitch
WEnd

Func Toolbar()

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    Global $hImage = _GUIImageList_Create(16, 16, 5, 3, 3)
    _GUIImageList_AddIcon($hImage, "C:\program Files\NetSupport Manager\PCIAX.DLL", 0) ;netsupport    0
    _GUIImageList_AddIcon($hImage, "tapisnap.dll", 3);-7) ;manage    1
    _GUIImageList_AddIcon($hImage, "cdfview.dll", 2) ;common    2
    _GUIImageList_AddIcon($hImage, "azroleui.dll", 7) ;hardware    3
    _GUIImageList_AddIcon($hImage, "Shell32.dll", 19) ;software    4
    _GUICtrlToolbar_SetImageList($hToolbar, $hImage)

    _GUICtrlToolbar_SetImageList($hToolbar, $hImage)

    $netsupport_button_txt = _GUICtrlToolbar_AddString($hToolbar, "NetSupport")
    $manage_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Manage")
    $common_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Common")
    $hardware_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Hardware")
    $software_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Software")

    _GUICtrlToolbar_AddButton($hToolbar, $idNetSupport, 0, $netsupport_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idManage, 1, $manage_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idCommon, 2, $common_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))
    _GUICtrlToolbar_AddButton($hToolbar, $idHardware, 3, $hardware_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))
    _GUICtrlToolbar_AddButton($hToolbar, $idSoftware, 4, $software_button_txt, BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN))

    ;_GUICtrlToolbar_SetButtonStyle($hToolbar, $idPower, $BTNS_CHECK)
    _GUICtrlToolbar_SetButtonWidth($hToolbar, 100, 37)

EndFunc   ;==>Toolbar

; Toolbar: call functions for toolbar button dropdown menu
Func _ToolBarMenu($TbarMenuCmdID)
    Switch $TbarMenuCmdID
        Case $idRemoteScreenShot
            MsgBox(4096, "Pop-Up Menu", "Remote ScreenShot")
        Case $idPushKillNotes
            MsgBox(4096, "Pop-Up Menu", "Push KillNotes")
        Case $idWhoseLoggedOn
            MsgBox(4096, "Pop-Up Menu", "Whose Logged On")
        Case $idMustHave
            MsgBox(4096, "Pop-Up Menu", "MustHave")
        Case $idGetIP
            MsgBox(4096, "Pop-Up Menu", "GetIP")
        Case $idSysInfo
            MsgBox(4096, "Pop-Up Menu", "SysInfo")
        Case $idLocalMaps
            MsgBox(4096, "Pop-Up Menu", "Local Maps")
        Case $idWhosAdmin
            MsgBox(4096, "Pop-Up Menu", "Whos Admin")
        Case $idUserHistory
            MsgBox(4096, "Pop-Up Menu", "User History")
    EndSwitch
EndFunc   ;==>_ToolBarMenu

Func _ToolBar_Click($TbarCmdID)
    Switch $TbarCmdID
        Case $idNetSupport    ; FileOpen
            MsgBox(4096, "Pop-Up Menu", "Netsupport")
        Case $idManage    ; FileSave
            MsgBox(4096, "Pop-Up Menu", "Manage")
    EndSwitch
    Return
EndFunc   ;==>_ToolBar_Click

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
    Local $tNMTOOLBAR, $tNMTBHOTITEM, $hMenu, $hSubmenu, $aRet, $iMenuID
    Local Const $TBDDRET_TREATPRESSED = 2   

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $idFrom = DllStructGetData($tNMHDR, "IDFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $TBN_DROPDOWN
                    $hMenu = _GUICtrlMenu_CreatePopup()
                    _GUICtrlMenu_AddMenuItem($hMenu, "Remote ScreenShot", $idRemoteScreenShot)                  
                    _GUICtrlMenu_AddMenuItem($hMenu, "Push KillNotes", $idPushKillNotes)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Whose Logged On?", $idWhoseLoggedOn)
                    _GUICtrlMenu_AddMenuItem($hMenu, "MustHave", $idMustHave)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Get IP", $idGetIP)
                    _GUICtrlMenu_AddMenuItem($hMenu, "System Information", $idSysInfo)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Local Mappings", $idLocalMaps)
                    _GUICtrlMenu_AddMenuItem($hMenu, "Who's An Admin", $idWhosAdmin)
                    _GUICtrlMenu_AddMenuItem($hMenu, "User History", $idUserHistory)

                    $aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $idCommon)
                    If Not IsArray($aRet) Then
                        Dim $aRet[2] = [-1, -1]
                    EndIf


                    ; send button dropdown menu item commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                    ; allows quick return from message handler : See warning for GUIRegisterMsg() in helpfile
                    $iMenuID = _GUICtrlMenu_TrackPopupMenu($hMenu, $hToolbar, $aRet[0], $aRet[1], 1, 1, 2)
                    GUICtrlSendToDummy($TbarMenu, $iMenuID)
                    _GUICtrlMenu_DestroyMenu($hMenu)
                    If $iMenuID Then Return $TBDDRET_TREATPRESSED
                Case $NM_LDOWN
                    Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iItem) ; add check for button state if disabled
                        Case True
                            ; send toolbar commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                            ; allows quick return from message handler : See warning for GUIRegisterMsg() in helpfile
                            GUICtrlSendToDummy($Tbar, $iItem)
                    EndSwitch
                    ;----------------------------------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem))
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $iItem = $i_idNew
                    $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY


Func _GetToolbarButtonScreenPos($hwnd, $hTbar, $iCmdID, $iIndex = 0, $hRbar = -1) ; $hRbar and $iIndex is for optional Rebar hwnd and band index
    ; Author: rover 04/08/2008
    ; this UDF integrates _WinAPI_ClientToScreen() from WinAPI.au3 include
    ; _GUICtrlMenu_TrackPopupMenu() uses screen coordinates to place dropdown menu
    ; need to convert button client coordinates to screen coordinates
    Local $aBorders, $aBandRect, $aRect, $tpoint, $pPoint, $aRet[2]
    Local $aRect = _GUICtrlToolbar_GetButtonRect($hTbar, $iCmdID) ; 'Options' button with dropdown menu
    If Not IsArray($aRect) Then Return SetError(@error, 0, "")
    $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", $aRect[0])
    DllStructSetData($tpoint, "Y", $aRect[3])
    $pPoint = DllStructGetPtr($tpoint)
    DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hwnd, "ptr", $pPoint)
    If @error Then Return SetError(@error, 0, "")
    If $hRbar <> -1 And IsHWnd($hRbar) And IsNumber($iIndex) Then
        $aBorders = _GUICtrlRebar_GetBandBorders($hRbar, $iIndex)
        If Not IsArray($aBorders) Then Return SetError(@error, 0, "")
        $aBandRect = _GUICtrlRebar_GetBandRect($hRbar, $iIndex)
        If Not IsArray($aBandRect) Then Return SetError(@error, 0, "")
        ; X screen coordinate of dropdown button left corner
        ; subtract 2 pixel border of bounding rectangle for band in rebar control
        $aRet[0] = (DllStructGetData($tpoint, "X") + $aBorders[0]) - $aBandRect[0]
    Else
        ; X screen coordinate of dropdown button left corner
        $aRet[0] = DllStructGetData($tpoint, "X")
    EndIf
    ; Y screen coordinate of dropdown button left corner
    $aRet[1] = DllStructGetData($tpoint, "Y")
    Return $aRet ; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc   ;==>_GetToolbarButtonScreenPos

Faraway, So close!

it's doable, but... (with MS there's always a but)

I'm assuming you mean a toolbar in your script, and not a toolbar in another process.

If you mean an external process then I don't know if its doable. (look into API hook/DLL injection into another process)

you can set button text colour by custom drawing the toolbar,

however, to use visual styles/themes this only works with Vista and up.

In XP visual style/theme must be turned off for toolbar control with SetWindowTheme API

I'll leave you to your own gnashing of teeth and rending of garments

over Microsofts intransigence when it comes to updating the common controls with new features

always frustratingly one OS version behind, and many that could have been there from the start.</rant>

this can also be done with ownerdrawing, I don't have an example, but skinning dlls do this

(skincrafter DLL can set text colour for all toolbar buttons, but not individually)

ownerdrawn controls requires additional UxTheme DLL API calls,

themechanged/drawitem/measureitem message handling and you have to do the painting yourself.

with customdrawn controls, most of the work is done for you by windows.

regarding _GUICtrlToolbar_SetColorScheme(), it doesn't paint text colour.

MSDN: "The toolbar control uses the color scheme information when drawing the 3-D elements in the control.

When visual styles are enabled, this message has no effect."

_GUICtrlToolbar_SetColorScheme($hToolbar, 0x00ffff, 0x800000)

with this example all it did was paint yellow between the buttons.

Example: Customdrawn toolbar colored text

if using custom fonts then text measurement and some adjusting of the toolbar metrics is needed to resize button,

its not quite worked out properly in this example.

"$TBSTYLE_CUSTOMERASE - Generates $NM_CUSTOMDRAW messages when the toolbar processes $WM_ERASEBKGND messages"

I haven't read any clear description of its purpose, NM_CUSTOMDRAW messages are sent to the main form WM_NOTIFY handler without it.

I'm assuming its some kind of additional buffering for flicker if toolbar is heavily customdrawn...

that's as much input as I can give, however YMMV with the forums knowledgeable Win32 programmers

screenshot shows unthemed transparent flat style toolbar on visual style with background texture and hot track button background colour.

post-22637-1245598302_thumb.png

example tested in Win2000, XP and Vista

Edit: added text highlighting on third button

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiToolbar.au3>
#Include <GuiRebar.au3>
#Include <GuiImageList.au3>


Opt('MustDeclareVars', 1)

;Global Const $tagNMHDR = "hwnd hWndFrom;int IDFrom;int Code"
Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;hwnd HDC;int Rect[4];long_ptr ItemSpec;uint ItemState;long_ptr ItemParam"
Global Const $tagNMTBCUSTOMDRAW = $tagNMCUSTOMDRAWINFO & ";hwnd hbrMonoDither;hwnd hbrLines;hwnd hpenLines;dword clrText;dword clrMark;" & _
"dword clrTextHighlight;dword clrBtnFace;dword clrBtnHighlight;" & _
"dword clrHighlightHotTrack;int rcText[4];int nStringBkMode;int nHLStringBkMode;int iListGap"

Global Const $TBCDRF_HILITEHOTTRACK = 0x20000
Global Const $TBCDRF_USECDCOLORS  = 0x00800000; Vista and up

Global $hToolbar, $hFont
Global Enum $id1 = 1000, $id2, $id3
Global $iIcon1 = 27, $iIcon2 = 110

_Main()

Func _Main()

    Local $hGUI, $hReBar, $hToolBarImageListNorm, $aStrings[3]
    $hGUI = GUICreate("Customdrawn toolbar colour text - Vista or without toolbar theme in XP/Win2000", 600, 60)
    GUISetBkColor(0xFFFFFF)
    
;$TBSTYLE_TRANSPARENT $TBSTYLE_FLAT $TBSTYLE_CUSTOMERASE
    $hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN, $TBSTYLE_CUSTOMERASE))
    $hReBar = _GUICtrlReBar_Create($hGUI, BitOR($CCS_TOP, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "wstr", "", "wstr", ""); theme off
;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "ptr", 0, "ptr", 0) ; theme on
    
    Switch @OSVersion
        Case "WIN_XP"
        ; to change text colour in XP, themes must be turned off for toolbar
            DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "wstr", "", "wstr", "");theme off
        Case "WIN_VISTA"
            $iIcon1 = 35
            $iIcon2 = 286
        Case "WIN_2000"
            $iIcon1 = 101
            $iIcon2 = 4
    EndSwitch
    
    $hToolBarImageListNorm = _GUIImageList_Create(32, 32, 5, 3)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", $iIcon2, True)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", $iIcon1, True)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @AutoItExe, 0, True)
    _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm)
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "Open")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "Exit")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "AutoIt v3")
    
    _GUICtrlToolbar_AddButton($hToolbar, $id1, 0, $aStrings[0], $BTNS_AUTOSIZE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $id2, 1, $aStrings[1], $BTNS_AUTOSIZE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $id3, 2, $aStrings[2], $BTNS_AUTOSIZE)
    
    _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0)

    $hFont = _WinAPI_CreateFont(14, 0, 0, 0, 800, False, False, False, $DEFAULT_CHARSET, _
    $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, BitOR($DEFAULT_PITCH, $FF_DONTCARE), "Arial")

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    GUISetState()
    
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    Exit
EndFunc  ;==>_Main


Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam

    Local $tNMTBCUSTOMDRAW, $hWndFrom, $iCode;, $iItem
    Local $tNMHDR, $iDrawStage, $iItemSpec, $hDC, $iItemState;$tNMTOOLBAR
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
;$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
    $hWndFrom   = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode      = DllStructGetData($tNMHDR, "Code")
;$iItem         = DllStructGetData($tNMHDR, "iItem")

    Switch $hWndFrom
        Case $hToolbar
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    
                    $tNMTBCUSTOMDRAW = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
                    $iDrawStage = DllStructGetData($tNMTBCUSTOMDRAW, "DrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage <> $CDDS_ITEMPREPAINT Then Return $CDRF_DODEFAULT
                    
                    $iItemSpec = DllStructGetData($tNMTBCUSTOMDRAW, "ItemSpec")
                    $hDC = DllStructGetData($tNMTBCUSTOMDRAW, "HDC")
                    $iItemState = DllStructGetData($tNMTBCUSTOMDRAW, "ItemState")
                    
                    #cs
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!ItemSpec ................", ": ", $iItemSpec) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrText ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrText"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrMark ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrMark"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrTextHighlight ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrTextHighlight"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrBtnFace ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrBtnFace"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrBtnHighlight ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrBtnHighlight"))) & @crlf)
                    ConsoleWrite(StringFormat("%-.25s%s%-40s", "!clrHighlightHotTrack ................", ": ", Hex(DllStructGetData($tNMTBCUSTOMDRAW, "clrHighlightHotTrack"))) & @crlf & @crlf )
                    #ce
                
                    Switch $iItemSpec
                        Case $id1; Open
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x000000FF); RED
                        ;set text colour ($TBCDRF_USECDCOLORS required for Vista (ignored in Win 2000/XP), otherwise return $CDRF_DODEFAULT)
                            If @OSVersion = "WIN_VISTA" Then Return $TBCDRF_USECDCOLORS
                        Case $id2; Exit
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00008B00);GREEN
                            ;set text colour ($TBCDRF_USECDCOLORS required for Vista (ignored in Win 2000/XP), otherwise return $CDRF_DODEFAULT)
                            If @OSVersion = "WIN_VISTA" Then Return $TBCDRF_USECDCOLORS
                        Case $id3; AutoIt v3
                        ; set font/text colour/hot track colour
                        ;resize button for width of custom font text string (a rough example that needs additional code to properly resize button)
                        ;DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FF0000);BLUE
                            _WinAPI_SelectObject($hDC, $hFont) 
                            Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, _GUICtrlToolbar_GetButtonText($hToolbar, $id3))
                            Local $iWidth = DllStructGetData($tSize, "X")
                            DllStructSetData($tNMTBCUSTOMDRAW, "rcText", $iWidth, 3)
                            DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FF0000);BLUE
                            
                            Switch $iItemState;optionally set hot track highlight colour of button background
                                Case $CDIS_HOT;WindowsConstants.au3
                                    DllStructSetData($tNMTBCUSTOMDRAW, "clrText", 0x00FFDF55);LIGHT BLUE
                                ;not set unless $TBCDRF_HILITEHOTTRACK returned
                                    DllStructSetData($tNMTBCUSTOMDRAW, "clrHighlightHotTrack", 0x00FFFFFF);change hot track button background colour - works in XP
                                    Return BitOR($TBCDRF_HILITEHOTTRACK, $CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set hot track background colour, font and text colour
                            EndSwitch
                            
                            Return BitOR($CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set font and text colour
                    EndSwitch

                    Return $CDRF_DODEFAULT; The control will draw itself
                ;Return BitOR($TBCDRF_HILITEHOTTRACK, $CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set hot track background colour, font and text colour (Vista) 
                ;Return BitOR($TBCDRF_HILITEHOTTRACK, $TBCDRF_USECDCOLORS);set hot track background colour and text colour (Vista) 
                ;Return BitOR($CDRF_NEWFONT, $TBCDRF_USECDCOLORS);set font and text colour (Vista)
                ;Return $TBCDRF_HILITEHOTTRACK;set hot track background colour
                ;Return $CDRF_NEWFONT;set font
                ;Return $TBCDRF_USECDCOLORS;set text colour (Vista)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc  ;==>_WM_NOTIFY

Share this post


Link to post
Share on other sites
rover

"u mentioned different ways of doing this.. does one take up more memory than another?"

gcue

it's not an issue of more memory.

ownerdrawing a themed toolbar to get colour text requires far more code

and the external DLL is a costly third party commercial product.

stick with the customdrawing example below.

the customdrawn colour text and dropdown menu examples are combined in this script

it's just easier to post an example than explain

I've worked on a few things for myself I'm posting here.

a rebar band bitmap background, another update to GetToolbarButtonScreenPos

and a modified _GUICtrlRebar_AddToolBarBand

Issues:

customdrawn dropdown button has black text in pressed state, I could not find a way to change that.

Added option to use a rebar:

even though only a toolbar is used in this instance you can remove the gripper, text header and other features of a rebar

so you get the benefit of the visual style/themed background instead of the transparent toolbar background.

and you can set the bitmap background of a rebared toolbar.

#include <Constants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <GuiToolbar.au3>
#include <GuiRebar.au3>
#include <GuiImageList.au3>

#include <GDIPlus.au3> ;just for bitmap rebar band examples

Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)

;$Debug_RB = False
;$Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $fRebarOn = True ;set bitmap background of toolbar
Global $fCustomdrawToolbar = True ;set text colour of toolbar text (with limitations of no theme and black text for pressed buttons)
Global $iToolbarTextColour = SwitchColor(0x191970) ;set toolbar text colour (convert to BGR COLORREF)

Global $hGUI, $hReBar, $hToolbar, $Tbar, $TbarMenu, $iMemo, $msg, $aSize, $hBmp
Global $iItem ; Command identifier of the button associated with the notification.
Global Enum $idRemoteScreenShot = 1000, $idPushKillNotes, $idWhoseLoggedOn, _
        $idMustHave, $idGetIP, $idSysInfo, $idLocalMaps, $idWhosAdmin, $idUserHistory ;Common
Global Enum $idLookupLocation = 1100, $idDefaultPrinter, $idNonIPrint, _
        $idEncryptionStatus, $idMACnHD, $idDPIsetting, $idUptime ;Hardware
Global Enum $idActiveProcesses = 1200, $idKillProcess, $idInstalledPrograms, _
        $idNotesDataDir, $idImageBuild, $idRecoverySol ;Software
Global $netsupport_button_txt, $manage_button_txt, $common_button_txt, _
        $hardware_button_txt, $software_button_txt
Global Enum $idNetSupport = 2000, $idManage, $idCommon, $idHardware, $idSoftware

;Menu
Global $hMenuCommon, $hMenuHardware, $hMenuSoftware
Global Const $TBDDRET_DEFAULT = 0
Global Const $TBDDRET_NODEFAULT = 1
Global Const $TBDDRET_TREATPRESSED = 2
Global Const $TBCDRF_HILITEHOTTRACK = 0x20000

;Toolbar
Global Const $TBCDRF_USECDCOLORS = 0x00800000 ; Vista and up
Global Const $tagNMHDR64 = "long_ptr hWndFrom;int_ptr IDFrom;int Code"
Global Const $tagNMCUSTOMDRAWINFO = $tagNMHDR & ";dword DrawStage;hwnd HDC;" & _
        "int Rect[4];long_ptr ItemSpec;uint ItemState;long_ptr ItemParam"
Global Const $tagNMTBCUSTOMDRAW = $tagNMCUSTOMDRAWINFO & ";hwnd hbrMonoDither;" & _
        "hwnd hbrLines;hwnd hpenLines;dword clrText;dword clrMark;dword clrTextHighlight;" & _
        "dword clrBtnFace;dword clrBtnHighlight;dword clrHighlightHotTrack;int rcText[4];" & _
        "int nStringBkMode;int nHLStringBkMode;int iListGap"

; Create GUI

$hGUI = GUICreate("Toolbar customdraw/menus/bitmaps - ThemeOff: " & $fCustomdrawToolbar & " - RebarOn: " & $fRebarOn, 500, 300)
GUISetBkColor(0xd3d3d3) ;0x3E68AC
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

Toolbar()

$iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 6, 496, 292 - ($aSize[1]), $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")

$Tbar = GUICtrlCreateDummy() ; dummy control for toolbar events
GUICtrlSetOnEvent(-1, "_ToolBar_Click")
$TbarMenu = GUICtrlCreateDummy() ; dummy control for toolbar button dropdown menu events
GUICtrlSetOnEvent(-1, "_ToolBarMenu")

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()


;set background bitmap of rebar band
_GDIPlus_Startup()
Global $himage = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\Web\Wallpaper\bliss.bmp")
Global $aChildSize = _GUICtrlRebar_GetBandChildSize($hReBar, 0)
Global $hClone = _GDIPlus_BitmapCloneArea($himage, 0, 0, 500, $aChildSize[1], $GDIP_PXF24RGB)
Global $hBmp1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hClone)
_GDIPlus_ImageDispose($hClone)
$hClone = _GDIPlus_BitmapCloneArea($himage, 0, 400, 500, $aChildSize[1], $GDIP_PXF24RGB)
Global $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hClone)
_GDIPlus_ImageDispose($hClone)
_GDIPlus_ImageDispose($himage)
_GDIPlus_Shutdown()
;small bitmaps are tiled
Global $hBmp3 = _WinAPI_LoadImage(0, @WindowsDir & "\Prairie Wind.bmp", $IMAGE_BITMAP, 0, 0, BitOR($LR_CREATEDIBSECTION, $LR_LOADFROMFILE))
Global $hBmp4 = -1


While 1
    ;rotate through bitmaps and text colour
    For $i = 1 To 4
        Sleep(1000)
        $iToolbarTextColour = 0x00FFFFFF
        If $i = 1 Then $iToolbarTextColour = 0x00000000
        If $i = 2 Then $iToolbarTextColour = SwitchColor(0xFFFF00)
        If $i = 3 Then $iToolbarTextColour = SwitchColor(0xDDC488)
        _GUICtrlRebar_SetBandBackgroundBitmap($hReBar, $hToolbar, 0, Execute("$hBmp" & String($i)))
        DllCall("User32.dll", "int", "InvalidateRect", "hwnd", $hToolbar, "ptr", 0, "int", 1)
    Next

;~     $msg = GUIGetMsg()
;~     Switch $msg
;~         Case $GUI_EVENT_CLOSE
;~             Exit
;~         Case $Tbar  ; toolbar buttons
;~             _ToolBar_Click(GUICtrlRead($Tbar))
;~         Case $TbarMenu ; toolbar button dropdown menu
;~             _ToolBarMenu(GUICtrlRead($TbarMenu))
;~     EndSwitch
WEnd

Func SpecialEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            ;"Menu resources that are assigned to a window are freed automatically.
            ;If the menu is not assigned to a window,
            ;an application must free system resources associated with the menu before closing"
            _GUICtrlMenu_DestroyMenu($hMenuCommon)
            _GUICtrlMenu_DestroyMenu($hMenuHardware)
            _GUICtrlMenu_DestroyMenu($hMenuSoftware)
            DllCall("GDI32.dll", "int", "DeleteObject", "hwnd", $hBmp1)
            DllCall("GDI32.dll", "int", "DeleteObject", "hwnd", $hBmp2)
            DllCall("GDI32.dll", "int", "DeleteObject", "hwnd", $hBmp3)
            Exit
    EndSwitch
EndFunc   ;==>SpecialEvents

Func Toolbar()
    
    ;CCS_NORESIZE common controls style required for toolbar embedded in a rebar if using a moveable/resizeable rebar band
    ;in this example the band is fixed and rebar features removed, only transparency feature of rebar is used.
    ;TBSTYLE_TRANSPARENT is automatically added by common controls when $TBSTYLE_FLAT used, but must be added manually for $TBSTYLE_LIST
    
    ;Explorer style ($TBSTYLE_FLAT required for button transparency with no theme customdraw)
    ;Local $iMin = 96, $iMax = 100
    ;Local $iTBStyles = BitOR($TBSTYLE_LIST, $TBSTYLE_FLAT, $TBSTYLE_TRANSPARENT)

    Local $iMin = 100, $iMax = 100
    ;($CCS_NORESIZE used here if moveable/resizeable rebar band with gripper and other features required)
    Local $iTBStyles = BitOR($TBSTYLE_FLAT, $TBSTYLE_TRANSPARENT) ; ,$CCS_NORESIZE)

    Local $iRBStyles = -1
    If $fRebarOn Then
        ;RBBS_CHILDEDGE: no edge at the top and bottom of the toolbar child window
        ;RBBS_VARIABLEHEIGHT: band can be resized by the rebar control
        ;RBBS_NOGRIPPER: never have a sizing grip, even if there is more than one band in the rebar
        ;RBBS_HIDETITLE; hide band title
        $iRBStyles = BitOR($RBBS_CHILDEDGE, $RBBS_VARIABLEHEIGHT, $RBBS_NOGRIPPER, $RBBS_HIDETITLE)
        $hReBar = _GUICtrlRebar_Create($hGUI, BitOR($WS_BORDER, $CCS_TOP, $CCS_NODIVIDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    EndIf

    $hToolbar = _GUICtrlToolbar_Create($hGUI, $iTBStyles)
    _GUICtrlToolbar_SetStyleCustomErase($hToolbar, True)
    _GUICtrlToolbar_SetExtendedStyle($hToolbar, $TBSTYLE_EX_DRAWDDARROWS)
    _GUICtrlRebar_SetUnicodeFormat($hReBar, True) ;needed until Rebar UDFs updated to be unicode by default (to work with modified _GUICtrlReBar_AddToolBarBand)

    If $fCustomdrawToolbar Then
        Switch @OSVersion
            Case "WIN_XP"
                ; to change text colour in XP, themes must be turned off for toolbar
                DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolbar, "wstr", "", "wstr", "") ;theme off
        EndSwitch
    EndIf

    ;temporary stand-in icons for testing and anyone who wants to try this example
    Global $himage = _GUIImageList_Create(16, 16, 5, 3, 3)
    _GUIImageList_AddIcon($himage, "Shell32.dll", 18)
    _GUIImageList_AddIcon($himage, "Shell32.dll", 43)
    _GUIImageList_AddIcon($himage, "Shell32.dll", 171)
    _GUIImageList_AddIcon($himage, "Shell32.dll", 165)
    _GUIImageList_AddIcon($himage, "Shell32.dll", 162)

;~     _GUIImageList_AddIcon($hImage, "C:\program Files\NetSupport Manager\PCIAX.DLL", 0) ;netsupport    0
;~     _GUIImageList_AddIcon($hImage, "tapisnap.dll", 3);-7) ;manage    1
;~     _GUIImageList_AddIcon($hImage, "cdfview.dll", 2) ;common    2
;~     _GUIImageList_AddIcon($hImage, "azroleui.dll", 7) ;hardware    3
;~     _GUIImageList_AddIcon($hImage, "Shell32.dll", 19) ;software    4

    _GUICtrlToolbar_SetImageList($hToolbar, $himage)

    $netsupport_button_txt = _GUICtrlToolbar_AddString($hToolbar, "NetSupport")
    $manage_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Manage")
    $common_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Common")
    $hardware_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Hardware")
    $software_button_txt = _GUICtrlToolbar_AddString($hToolbar, "Software")

    _GUICtrlToolbar_AddButton($hToolbar, $idNetSupport, 0, $netsupport_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idManage, 1, $manage_button_txt)
    _GUICtrlToolbar_AddButton($hToolbar, $idCommon, 2, $common_button_txt, $BTNS_WHOLEDROPDOWN);BitOR($BTNS_DROPDOWN, $BTNS_WHOLEDROPDOWN)
    _GUICtrlToolbar_AddButton($hToolbar, $idHardware, 3, $hardware_button_txt, $BTNS_WHOLEDROPDOWN)
    _GUICtrlToolbar_AddButton($hToolbar, $idSoftware, 4, $software_button_txt, $BTNS_WHOLEDROPDOWN)

    If $fRebarOn Then
        __GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0, $iRBStyles, 4) ;add 4 pixel height offset to rebar band
        ;_GUICtrlRebar_SetBandHeaderSize($hReBar, 0, 0)
        ;set custom ID of toolbarband at index 0 (first band)
        ;Required if using Rebar with multiple moveable bands (index numbers change with position)
        ;_GUICtrlRebar_SetBandID($hReBar, 0, 2357)
    EndIf

    _GUICtrlToolbar_SetButtonWidth($hToolbar, $iMin, $iMax)
    $aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)

    ;create menus once instead of each time button clicked
    $hMenuCommon = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Remote ScreenShot", $idRemoteScreenShot)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Push KillNotes", $idPushKillNotes)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Whose Logged On?", $idWhoseLoggedOn)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "MustHave", $idMustHave)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Get IP", $idGetIP)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "System Information", $idSysInfo)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Local Mappings", $idLocalMaps)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "Who's An Admin", $idWhosAdmin)
    _GUICtrlMenu_AddMenuItem($hMenuCommon, "User History", $idUserHistory)

    $hMenuHardware = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "Lookup Location", $idLookupLocation)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "Default Printer", $idDefaultPrinter)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "No nIPrint", $idNonIPrint)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "Encryption Status", $idEncryptionStatus)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "MAC nHD", $idMACnHD)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "DPI setting", $idDPIsetting)
    _GUICtrlMenu_AddMenuItem($hMenuHardware, "Uptime", $idUptime)

    $hMenuSoftware = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Active Processes", $idActiveProcesses)
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Kill Process", $idKillProcess)
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Installed Programs", $idInstalledPrograms)
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Notes DataDir", $idNotesDataDir)
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Image Build", $idImageBuild)
    _GUICtrlMenu_AddMenuItem($hMenuSoftware, "Recovery Sol", $idRecoverySol)
EndFunc   ;==>Toolbar

Func _ToolBarMenu()
    Switch GUICtrlRead($TbarMenu)
        Case $idRemoteScreenShot
            MsgBox(4096, "Pop-Up Menu", "Remote ScreenShot")
        Case $idPushKillNotes
            MsgBox(4096, "Pop-Up Menu", "Push KillNotes")
        Case $idWhoseLoggedOn
            MsgBox(4096, "Pop-Up Menu", "Whose Logged On")
        Case $idMustHave
            MsgBox(4096, "Pop-Up Menu", "MustHave")
        Case $idGetIP
            MsgBox(4096, "Pop-Up Menu", "GetIP")
        Case $idSysInfo
            MsgBox(4096, "Pop-Up Menu", "SysInfo")
        Case $idLocalMaps
            MsgBox(4096, "Pop-Up Menu", "Local Maps")
        Case $idWhosAdmin
            MsgBox(4096, "Pop-Up Menu", "Whos Admin")
        Case $idUserHistory
            MsgBox(4096, "Pop-Up Menu", "User History")
        Case $idLookupLocation

        Case $idDefaultPrinter

        Case $idNonIPrint

        Case $idEncryptionStatus

        Case $idMACnHD

        Case $idDPIsetting

        Case $idUptime

    EndSwitch
EndFunc   ;==>_ToolBarMenu

Func _ToolBar_Click()
    Switch GUICtrlRead($Tbar)
        Case $idNetSupport ; FileOpen
            MsgBox(4096, "Pop-Up Menu", "Netsupport")
        Case $idManage ; FileSave
            MsgBox(4096, "Pop-Up Menu", "Manage")
    EndSwitch
    Return
EndFunc   ;==>_ToolBar_Click

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $i_idNew, $idFrom, $i_idOld, $dwFlags
    Local $tNMTOOLBAR, $tNMTBHOTITEM, $hMenu, $aRet, $iMenuID = -1

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $idFrom = DllStructGetData($tNMHDR, "IDFrom")
    $code = DllStructGetData($tNMHDR, "Code")

    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $TBN_DROPDOWN
                    If Not $fRebarOn Then $hReBar = -1
                    ; if using multiple moveable rebar bands then ID should be set for toolbarband with _GUICtrlRebar_SetBandID()
                    ; and current index retrieved with _GUICtrlRebar_IDToIndex()
                    Local $iRBID = 0 ;_GUICtrlRebar_IDToIndex($hReBar, 2357)
                    $aRet = _GetToolbarButtonScreenPos($hGUI, $hToolbar, $iItem, 2, $iRBID, $hReBar)
                    ;$tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
                    ;$iItem = DllStructGetData($tNMTOOLBAR, "iItem")
                    Switch $iItem
                        Case $idCommon
                            $hMenu = $hMenuCommon
                        Case $idHardware
                            $hMenu = $hMenuHardware
                        Case $idSoftware
                            $hMenu = $hMenuSoftware
                    EndSwitch
                    ; send button dropdown menu item commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                    $iMenuID = _GUICtrlMenu_TrackPopupMenu($hMenu, $hToolbar, $aRet[0], $aRet[1], 1, 1, 2)
                    If $iMenuID <> 0 Then GUICtrlSendToDummy($TbarMenu, $iMenuID)
                    Return $TBDDRET_DEFAULT
                Case $NM_CLICK ; $NM_LDOWN
                    Switch $iItem
                        Case $idNetSupport, $idManage
                            Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iItem) ; add check for button state if disabled
                                Case True
                                    ; send toolbar commandID to dummy control for use in GuiGetMsg() or GUICtrlSetOnEvent()
                                    GUICtrlSendToDummy($Tbar, $iItem)
                            EndSwitch
                    EndSwitch
                    ;----------------------------------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem))
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    ;$dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
                    $iItem = $i_idNew
                Case $NM_CUSTOMDRAW ;set toolbar text colour
                    If Not $fCustomdrawToolbar Then Return $CDRF_DODEFAULT
                    Local $tNMTBCUSTOMDRAW = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
                    Local $iDrawStage = DllStructGetData($tNMTBCUSTOMDRAW, "DrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage <> $CDDS_ITEMPREPAINT Then Return $CDRF_DODEFAULT
                    DllStructSetData($tNMTBCUSTOMDRAW, "clrText", $iToolbarTextColour)
                    If @OSVersion = "WIN_VISTA" Then Return $TBCDRF_USECDCOLORS ;set text colour (Vista)
                    Return $CDRF_DODEFAULT ; The control will draw itself
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Func _GetToolbarButtonScreenPos($hwnd, $hTb, $iCmdID, $iOffset = 0, $iIndex = 0, $hRbar = -1)
    ; Author: rover 04/08/2008
    ; this UDF integrates _WinAPI_ClientToScreen() from WinAPI.au3 include.
    ; _GUICtrlMenu_TrackPopupMenu() uses screen coordinates to place dropdown menu.
    ; button client coordinates must be converted to screen coordinates.
    ; $hRbar and $iIndex is for optional Rebar hwnd and band index
    ; $iOffset sets menu Y position below button
    ; Update: 06/27/2009 added offset for menu position below button, corrected left off-screen menu positioning.
    ; Update: 07/13/2009 added compensation for CCS_NORESIZE and RBS_BANDBORDERS style alignment problems. cleaned up error handling.

    Local $aBorders, $aBandRect, $aRect, $tpoint, $pPoint, $aRet[2] = [-1, -1]

    Local $aRect = _GUICtrlToolbar_GetButtonRect($hTb, $iCmdID)
    If @error Then Return SetError(@error, 0, $aRet)

    $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", $aRect[0])
    DllStructSetData($tpoint, "Y", $aRect[3])
    $pPoint = DllStructGetPtr($tpoint)

    DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hwnd, "ptr", $pPoint)
    If @error Then Return SetError(@error, 0, $aRet)

    ; X screen coordinate of dropdown button left corner
    $aRet[0] = DllStructGetData($tpoint, "X")
    ;limit X coordinate to 0 if button partially off-screen
    If $aRet[0] < 0 Then $aRet[0] = 0
    ; Y screen coordinate of dropdown button left corner
    $aRet[1] = DllStructGetData($tpoint, "Y") + Number($iOffset)

    ;#cs  comment out if not using rebars
    If $hRbar <> -1 And IsHWnd($hRbar) And IsNumber($iIndex) Then
        If BitAND(_SendMessage($hTb, $TB_GETSTYLE), $CCS_NORESIZE) = $CCS_NORESIZE Then
            $aBorders = _GUICtrlRebar_GetBandBorders($hRbar, $iIndex)
            If @error Then Return SetError(@error, 0, $aRet)
            $aBandRect = _GUICtrlRebar_GetBandRect($hRbar, $iIndex)
            If @error Then Return SetError(@error, 0, $aRet)
            ; X screen coordinate of dropdown button left corner
            ; add or subtract 2 pixel border of bounding rectangle for band in rebar control
            If BitAND(_WinAPI_GetWindowLong($hReBar, $GWL_STYLE), $RBS_BANDBORDERS) = 0 Then $aBandRect[0] = -$aBandRect[0]
            If $aRet[0] <> 0 Then $aRet[0] += ($aBorders[0] - $aBandRect[0])
        EndIf
    EndIf
    ;#ce

    Return $aRet ; return X,Y screen coordinates of toolbar dropdown button lower left corner
EndFunc   ;==>_GetToolbarButtonScreenPos

Func __GUICtrlRebar_AddToolBarBand($hwndRebar, $hwndToolbar, $sText = "", $iIndex = -1, $fStyle = -1, $iHOffset = 0)
    ;Internal process toolbars only
    ;Author: Gary Frost
    ;modified by rover 07/12/2009
    ;modified for Unicode and additional parameter for height offset to add space between bottom of button and band.
    ;removed external process code
    ;Note: Rebar unicode support must be set with _GUICtrlRebar_SetUnicodeFormat($hReBar, True)
    ;(_GUICtrlRebar_Create() does not set unicode internally as of 07/12/2009)
    If $Debug_RB Then _GUICtrlRebar_ValidateClassName($hwndRebar)
    If $Debug_RB Then _GUICtrlRebar_ValidateClassName($hwndToolbar, "ToolbarWindow32")
    Local $tBuffer, $pBuffer, $dwBtnSize, $NumButtons, $iDefaultWidth, $iResult
    Local $tINFO = DllStructCreate($tagREBARBANDINFO)
    Local $pINFO = DllStructGetPtr($tINFO)
    Local $iBuffer = StringLen($sText) + 1
    Local $iSize = DllStructGetSize($tINFO)

    If $fStyle <> -1 Then
        $fStyle = BitOR($fStyle, $RBBS_CHILDEDGE, $RBBS_GRIPPERALWAYS)
    Else
        $fStyle = BitOR($RBBS_CHILDEDGE, $RBBS_GRIPPERALWAYS)
    EndIf

    ;// Initialize band info used by the toolbar
    DllStructSetData($tINFO, "cbSize", $iSize)
    DllStructSetData($tINFO, "fMask", BitOR($RBBIM_STYLE, $RBBIM_TEXT, $RBBIM_CHILD, $RBBIM_CHILDSIZE, $RBBIM_SIZE, $RBBIM_ID))
    DllStructSetData($tINFO, "fStyle", $fStyle)

    ;// Get the height of the toolbar.
    $dwBtnSize = _SendMessage($hwndToolbar, $__REBARCONSTANT_TB_GETBUTTONSIZE)
    ; Get the number of buttons contained in toolbar for calculation
    $NumButtons = _SendMessage($hwndToolbar, $__REBARCONSTANT_TB_BUTTONCOUNT)
    $iDefaultWidth = $NumButtons * _WinAPI_LoWord($dwBtnSize)

    ;// Set values unique to the band with the toolbar.
    $tBuffer = DllStructCreate("wchar Text[" & $iBuffer & "]")
    DllStructSetData($tBuffer, "Text", $sText)
    $pBuffer = DllStructGetPtr($tBuffer)
    DllStructSetData($tINFO, "hwndChild", $hwndToolbar)
    DllStructSetData($tINFO, "cyChild", _WinAPI_HiWord($dwBtnSize))
    DllStructSetData($tINFO, "cxMinChild", $iDefaultWidth)
    DllStructSetData($tINFO, "cyMinChild", _WinAPI_HiWord($dwBtnSize) + $iHOffset)
    DllStructSetData($tINFO, "cx", $iDefaultWidth) ;// The default width is the width of the buttons.
    DllStructSetData($tINFO, "wID", _GUICtrlRebar_GetBandCount($hwndRebar))
    DllStructSetData($tINFO, "lpText", $pBuffer)

    ;// Add the band that has the toolbar.
    $iResult = _SendMessage($hwndRebar, $RB_INSERTBANDW, $iIndex, $pINFO, 0, "wparam", "ptr") <> 0
    Return $iResult
EndFunc   ;==>__GUICtrlRebar_AddToolBarBand

Func _GUICtrlRebar_SetBandBackgroundBitmap($hwndRebar, $hWndCtrl, $iIndex, $hBitmap = -1)
    ;Author: rover
    ;Set or remove bitmap background of Rebar band
    ;Parameters:
    ;$hWndRebar - Rebar handle
    ;$hWndCtrl - embedded control handle (toolbar, input, combo etc.)
    ;$iIndex - rebar band index
    ;$hBitmap - bitmap handle (bitmap is removed and band is repainted if $hBitmap = -1)
    If Not IsHWnd($hwndRebar) Then Return SetError(1, 1, False)
    If Not IsHWnd($hWndCtrl) Then $hWndCtrl = GUICtrlGetHandle($hWndCtrl)
    If Not IsHWnd($hWndCtrl) Then Return SetError(1, 2, False)
    Local $aResult
    ;if $hBitmap = -1 remove handle to bitmap and repaint rebar
    If $hBitmap = -1 Or $hBitmap = 0 Or $hBitmap = Default Then
        _GUICtrlRebar_SetBandInfo($hwndRebar, $iIndex, $RBBIM_BACKGROUND, "hbmBack", 0)
        DllCall("User32.dll", "int", "InvalidateRect", "hwnd", $hWndCtrl, "ptr", 0, "int", 1)
        Return SetError(2, 2, False)
    EndIf
    ;verify $hBitmap is handle to a bitmap
    $aResult = DllCall("GDI32.dll", "int", "GetObjectW", "hwnd", $hBitmap, "int", 0, "ptr", 0)
    If @error Or $aResult[0] <> 24 Then Return SetError(3, 3, False)
    _GUICtrlRebar_SetBandInfo($hwndRebar, $iIndex, $RBBIM_BACKGROUND, "hbmBack", $hBitmap)
    DllCall("User32.dll", "int", "InvalidateRect", "hwnd", $hWndCtrl, "ptr", 0, "int", 1)
    Return SetError(0, 0, True)
EndFunc   ;==>_GUICtrlRebar_SetBandBackgroundBitmap

Func SwitchColor($iColor)
    ;Switch BGR to RGB and vice versa
    ; Author - RazerM
    Local $iMask
    $iMask = BitXOR(BitAND($iColor, 0xFF), ($iColor / 0x10000))
    Return BitXOR($iColor, ($iMask * 0x10001))
EndFunc   ;==>SwitchColor

I see fascists...

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.