Jump to content

please help with toolbar, icons and text


jennico
 Share

Recommended Posts

to make clear what i would like to achieve, look at IE or Explorer toolbar. the text is beside the icon, not below. i couldn't find an appropriate style, so maybe someone can edit the examples or post a link, if this problem has been solved before.

thx.

j.

#include <GuiConstantsEx.au3>
#include <GuiToolbar.au3>
#include <GuiToolTip.au3>
#Include <GuiRebar.au3>
#Include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
;#include <GuiToolbar.au3>
;#include <GuiImageList.au3>
;#include <GuiToolTip.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $iItem ; Command identifier of the button associated with the notification.
Global $hGUI, $hToolbar, $hToolTip, $hReBar, $iMemo, $aStrings[5], $i = 0
Global Enum $id1 = 1000, $id2, $id3, $id4, $id5 ; ID's for each ToolBar button

_Main()

Func _Main()

    Local $hToolBarImageListNorm, $hToolBarImageListDisabled, $hToolBarImageListHot, $aSize
    $hGUI = GUICreate("Toolbar", 400, 300)

    $hReBar = _GUICtrlReBar_Create($hGUI, BitOR($RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    $hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($BTNS_AUTOSIZE, $BTNS_BUTTON, $BTNS_SHOWTEXT))
    $aSize = _GUICtrlToolbar_GetMaxSize($hToolbar)

    ; Create ToolTip
    $hToolTip = _GUIToolTip_Create($hToolbar, $TTS_ALWAYSTIP)
    _GUICtrlToolbar_SetToolTips($hToolbar, $hToolTip)

    ; Add Icons from system DLL shell32.dll to ImageList
    $hToolBarImageListNorm = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 146)

    ; add AutoIt icon from exe internal resources or icon added at compile time by compiler directives
    _GUIImageList_AddIcon($hToolBarImageListNorm, @AutoItExe, 0) ; AutoIt icon if run in Scite or compiled
    _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm)

    ; Add strings
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&Open")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "E&xit")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Gear")
    $aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Tunes")
    $aStrings[4] = _GUICtrlToolbar_AddString($hToolbar, "&AutoIt")

    ; Add buttons
    _GUICtrlToolbar_AddButton($hToolbar, $id1, 0, $aStrings[0]) ; Index 0
    _GUICtrlToolbar_AddButton($hToolbar, $id2, 1, $aStrings[1]) ; Index 1
    _GUICtrlToolbar_AddButton($hToolbar, $id3, 2, $aStrings[2]) ; Index 2
    _GUICtrlToolbar_AddButtonSep($hToolbar) ; Index 3 - separators have index values
    _GUICtrlToolbar_AddButton($hToolbar, $id4, 3, $aStrings[3]) ; Index 4
    _GUICtrlToolbar_AddButtonSep($hToolbar) ; Index 5 - separators have index values
    _GUICtrlToolbar_AddButton($hToolbar, $id5, 6, $aStrings[4]) ; Index 6

    _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0)

    ; Remove
    $iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    ; /Remove
    
    ; Loop until user exits
    Do
        Sleep(10)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

; Remove
; Write message to memo
Func MemoWrite($sMessage = "")
    $i += 1
    If $i = 16 Then
        GUICtrlSetData($iMemo, $sMessage & @CRLF)
        $i = 0
    Else
        GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
    EndIf
EndFunc   ;==>MemoWrite
; /Remove

; WM_NOTIFY event handler for Toolbar button press events and tooltips
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $hwndFrom, $code, $index
    Local $tNMTOOLBAR, $tInfo, $iID
    
    $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
    $tInfo = DllStructCreate($tagNMTTDISPINFO, $lParam)
    $hwndFrom = DllStructGetData($tNMTOOLBAR, "hWndFrom")
    $code = DllStructGetData($tNMTOOLBAR, "Code")
    $iItem = DllStructGetData($tNMTOOLBAR, "iItem")

    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $TBN_BEGINDRAG
                    $index = _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem)
                    ; Remove
                    ;------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & $index)
                    ;------------------------------------------------------------------
                    ; /Remove
                    Switch _GUICtrlToolbar_IsButtonEnabled($hToolbar, $iItem)
                        Case True
                            Switch $index
                                Case 0
                                    Beep(1000, 5)
                                Case 1
                                    Beep(1500, 5)
                                    Exit
                                Case 2
                                    Beep(2000, 5)
                                    ; Disable / Enable Button 4 - Button 3 Is Checked when button 4 is disabled
                                    If _GUICtrlToolbar_IsButtonEnabled($hToolbar, $id4) Then
                                        _GUICtrlToolbar_EnableButton($hToolbar, $id4, False)
                                        _GUICtrlToolbar_CheckButton($hToolbar, $id3, True)
                                    Else
                                        _GUICtrlToolbar_EnableButton($hToolbar, $id4, True)
                                        _GUICtrlToolbar_CheckButton($hToolbar, $id3, False)
                                    EndIf
                                Case 4
                                    Beep(2500, 5)
                                Case 6
                                    Beep(3000, 5)
                                    SoundPlay(@WindowsDir & "\media\tada.wav", 0)
                            EndSwitch
                    EndSwitch
            EndSwitch
        Case $hToolTip
            Switch $code ; Toolbar Button Tooltips
                Case $TTN_GETDISPINFO
                    $iID = DllStructGetData($tInfo, "IDFrom")
                    Switch $iID
                        Case $id1
                            DllStructSetData($tInfo, "aText", "Open")
                        Case $id2
                            DllStructSetData($tInfo, "aText", "Exit")
                        Case $id3
                            DllStructSetData($tInfo, "aText", "Options")
                        Case $id4
                            DllStructSetData($tInfo, "aText", "Tunes")
                        Case $id5
                            DllStructSetData($tInfo, "aText", "AutoIt")
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFYoÝ÷ Ù«­¢+Ø¥¹±Õ±ÐíÕ¥
½¹ÍѹÑÍà¹ÔÌÐì(¥¹±Õ±ÐíÕ¥Q½½±È¹ÔÌÐì(¥¹±Õ±ÐíÕ¥%µ1¥ÍйÔÌÐì(¥¹±Õ±ÐíÕ¥Q½½±Q¥À¹ÔÌÐì(¥¹±Õ±Ðí]¥¹½ÝÍ
½¹ÍѹÑ̹ÔÌÐì()¥´¹Õ´ÀÌØí¥ÄôÄÀÀÀ°ÀÌØí¥È((ÀÌØí¡U$ôU%
ÉÑ ÅÕ½ÐíQ½½±ÈÅÕ½Ðì°ÐÀÀ°ÌÀÀ¤(ÀÌØí¡Q½½±Èô}U%
ÑɱQ½½±É}
ÉÑ ÀÌØí¡U$° ¥Ñ=H ÀÌØí Q9M}    UQQ=8°ÀÌØí Q9M}M!=]QaP¤°ÀÌØíQ    MQe1}a}I]II=]((ÀÌØí¡%µô}U%%µ1¥ÍÑ}
ÉÑ ÄØ°Äذ԰̤((ÀÌØí¡Q½½±Q¥Àô}U%Q½½±Q¥Á}
ÉÑ ÀÌØí¡Q½½±È°ÀÌØíQQM}1]eMQ%@¤)}U%
ÑɱQ½½±É}MÑQ½½±Q¥ÁÌ ÀÌØí¡Q½½±È°ÀÌØí¡Q½½±Q¥À¤()}U%%µ1¥ÍÑ}%½¸ ÀÌØí¡%µ°Õѽ%Ñá°À¤)}U%%µ1¥ÍÑ}%½¸ ÀÌØí¡%µ°ÅÕ½ÐíÍ¡±°Ìȹ±°ÅÕ½Ðì°Ô¤íÕѽ%Ñá°Ä¤()}U%
ÑɱQ½½±É}MÑ%µ1¥ÍÐ ÀÌØí¡Q½½±È°ÀÌØí¡%µ¤((ÀÌØíMÑÉ¥¹Äô}U%
ÑɱQ½½±É}MÑÉ¥¹ ÀÌØí¡Q½½±È°ÅÕ½ÐíÕѽ%ÐÅÕ½Ðì¤(ÀÌØíMÑÉ¥¹Èô}U%
ÑɱQ½½±É}MÑÉ¥¹ ÀÌØí¡Q½½±È°ÅÕ½Ðí
±½ÍÅÕ½Ðì¤()}U%
ÑɱQ½½±É}    ÕÑѽ¸ ÀÌØí¡Q½½±È°ÀÌØí¥Ä°À°ÀÌØíMÑÉ¥¹Ä¤((í}U%
ÑɱQ½½±É}    ÕÑѽ¹MÀ ÀÌØí¡Q½½±È°Ø¤)}U%
ÑɱQ½½±É}    ÕÑѽ¸ ÀÌØí¡Q½½±È°ÀÌØí¥È°Ä°ÀÌØíMÑÉ¥¹È¤((}U%
ÑɱQ½½±É}MÑMÑ山РÀÌØí¡Q½½±    È°QÉÕ¤((íI¥ÍÑÈ]5}9=Q%dÙ¹ÑÌ)U%I¥ÍÑÉ5Í ÀÌØí]5}9=Q%d°ÅÕ½Ðí]5}9½Ñ¥äÅÕ½Ðì¤()U%MÑMÑÑ ¤()]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤(MÝ¥Ñ ÀÌØíµÍ(
ÍÀÌØíU%}Y9Q}
1=M(á¥Ñ1½½À(¹MÝ¥Ñ )]¹((ì]5}9=Q%dٹС¹±È)Õ¹]5}9½Ñ¥ä ÀÌØí¡]¹U$°ÀÌØí5Í%°ÀÌØíÝAÉ´°ÀÌØí±AÉ´¤(½ÉÉÀÌØí¡]¹U$°ÀÌØí5Í%°ÀÌØíÝAÉ´(1½°ÀÌØí½°ÀÌØíÑ%¹¼(ÀÌØíÑ%¹¼ô±±MÑÉÕÑ
ÉÑ ÀÌØíÑ95QQ%MA%9
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

no, thanks, no tricks ! :)

there must be a clean constant or win api call to work with toolbar buttons. a toolbar button can hold an icon (or a bitmap) and additionally a string.

_GUICtrlToolbar_AddButton($hWnd, $iID, $iImage[, $iString = 0[, $iStyle = 0[, $iState = 4[, $iParam = 0]]]])

by default, the string is below the button. but there sure is a way to make it look like in explorer.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

In you second example, add $TBSTYLE_LIST to your toolbar styles:

$hToolbar = _GUICtrlToolbar_Create($hGUI, BitOR($BTNS_BUTTON,$BTNS_SHOWTEXT,$TBSTYLE_LIST), $TBSTYLE_EX_DRAWDDARROWS)

:)

Edit: damn you linewrap!

Edited by ResNullius
Link to comment
Share on other sites

wow, this still gives me headaches !!!

how can i display a $TBSTYLE_LIST button and a normal square button (like in the examples above) with an icon side by side please ?`

i can only set $TBSTYLE_LIST to the entire toolbar, and not to a single button. and the $TBSTYLE_EX_MIXEDBUTTONS does not do it either. and i did not succeed in creating more than one toolbar in the same gui (without rebar).

i want to make a toolbar that looks more or less like in IE or Explorer.

any help ?

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...