Does anyone have an example showing how to add text to the
buttons within a toolbar? I have tried sending the TB_ADDSTRING
message and setting the iString field of TBBUTTON structure
with the correct text index number, but the text never appears
on the buttons?
Any help would be appreciated, Will
make sure you used the TBSTYLE_LIST style.
Hmm, already tried TBSTYLE_LIST and it had no effect. Also tried
BTNS_SHOWTEXT and TBSTYLE_EX_MIXEDBUTTONS (the style TBSTYLE_EX_MIXEDBUTTONS
is required for BTNS_SHOWTEXT to function, according to the
Commctrl.h file) and still the text fails to appear. Does anyone
have sample code where they have managed to get text to show up?
I have tried just about everything I can think of to get this to
work, all without success.
Thanks for any help provided, Will
If its a 'tool-tip' your looking for i posted the walk thru code for it on the board a few months ago... Tool tips are the little messages you get when you hover you mouse over the button for a second.
You can find the discussion here: Tool Tips
Hope this Helps
NaN
after you set your BTNS_SHOWTEXT, TBSTYLE_EX_MIXEDBUTTONS, TBSTYLE_EX_MIXEDBUTTONS and TBSTYLE_LIST how you want it you need to send a message to your toolbar.
invoke SendMessage,hToolBar,TB_ADDSTRING,ADDR TextOfString
i believe the your TextOfString can be and array so that you can set each button separately. if you use the list style the text will appear to the right of the bitmap and if you use just mixbuttons the text appears to the bottom. if you figure a way to center the text on the button when u have no bitmap let me know.
smurf
Here is a clearer explanation of what I'm trying to accomplish,
along with the relevant code I have so far. First off, I am
trying to create a menu bar (like the one in internet explorer)
which is in fact just a toolbar with text only buttons placed
into a rebar band.
Heres what I have so far...
.data
szMenuFile DB "&File",0 ; File Menu String
szMenuView DB "&View",0 ; View Menu String
szMenuHelp DB "&Help",0,0 ; Help Menu String (Last String Must Be
; Double Null Terminated For TB_ADDSTRING)
szTest db 64 dup (0)
.data?
hInstance DD ? ; Handle For Program Instance
hMainWnd DD ? ; Handle For Programs Main Window
hRebarWnd DD ? ; Handle For Rebar
hMenuToolWnd DD ? ; Handle For Menu Toolbar
icce INITCOMMONCONTROLSEX <> ; Common Controls EX Structure
;--- Rebar
rbi REBARINFO <> ; Rebar Information Structure
rbbi REBARBANDINFO <> ; Rebar Band Information Structure
;--- Menu Tool Bar
tbm1 TBBUTTON <> ; File Menu Button Structure
tbm2 TBBUTTON <> ; View Menu Button Structure
tbm3 TBBUTTON <> ; Help Menu Button Structure
tbab TBADDBITMAP <> ; Add Toolbar Bitmap Images Structure
.code
; Following is processed in WM_CREATE message
; Note: InitCommonControls and InitCommonControlsEx
; are called during startup code.
;------------------------------
; Create Programs Rebar |
;------------------------------
Invoke CreateWindowEx,NULL,\ ; Create The Programs Rebar Window
addr szReBarClass,NULL,\
WS_CHILD Or WS_VISIBLE or WS_BORDER,\
0,0,0,0,hWnd,NULL,hInstance,NULL
mov hRebarWnd,eax ; Save The Rebar's Handle
;------------------------------
; Fill Rebar's Structure |
;------------------------------
mov rbi.cbSize,sizeof REBARINFO ; Fill Rebar's Information Structure
mov rbi.fMask,0 ; Rebar Controls Support Only One Value: RBIM_IMAGELIST
mov rbi.himl,NULL ; Handle For Image List Associated With The Rebar
Invoke SendMessage,hRebarWnd,\ ; Send Rebar's Information
RB_SETBARINFO,0,addr rbi
;------------------------------
; Init Menu Tool Bar Buttons |
;------------------------------
;--- File Menu Button ; Data For File Menu Button
mov tbm1.iBitmap,0
mov tbm1.idCommand,IDM_FILE
mov tbm1.fsState,TBSTATE_ENABLED
mov tbm1.fsStyle,TBSTYLE_BUTTON
mov tbm1.dwData,0
mov tbm1.iString,0 ; Index To Toolbars Internal String Table (&File)
;--- View Menu Button
mov tbm2.iBitmap,1 ; Data For View Menu Button
mov tbm2.idCommand,IDM_VIEW
mov tbm2.fsState,TBSTATE_ENABLED
mov tbm2.fsStyle,TBSTYLE_BUTTON
mov tbm2.dwData,0
mov tbm2.iString,1 ; Index To Toolbars Internal String Table (&View)
;--- Help Menu Button
mov tbm3.iBitmap,2 ; Data For Help Menu Button
mov tbm3.idCommand,IDM_HELP
mov tbm3.fsState,TBSTATE_ENABLED
mov tbm3.fsStyle,TBSTYLE_BUTTON
mov tbm3.dwData,0
mov tbm3.iString,2 ; Index To Toolbars Internal String Table (&Help)
;------------------------------
; Create Menu Tool Bar |
;------------------------------
Invoke CreateWindowEx,0,\ ; Create The Menu Toolbar
addr szToolBarClass,NULL,\ ; Parent Is The Rebar Control
WS_CHILD or WS_VISIBLE,\
0,0,0,0,hRebarWnd,NULL,
hInstance,NULL
mov hMenuToolWnd,eax ; Save The Toolbar Handle
Invoke SendMessage,hMenuToolWnd,
Almost got it... Almost....
Changed the TBBUTTON structure members fsState & fsStyle
from BYTE to DWORD in windows.inc so style can accept the styles
greater than one byte. This is probably not the correct way to
do this but it does seem to work. The buttons appear with text
only and the accelerator key is underlined (it acctually looks
like a menu). I also un-commented the SendMessage TB_SETIMAGELIST
to remove the space in front of the text where the bitmap would
normally appear (see my code above).
The only problem now is all three menu items are set to &File.
I don't know if changing the TBBUTTON structure or something
else has changed the iString member for all three menu items to
index value of zero causing all three to point to the same
string. Also, the call SendMessage TB_SETSTYLE is required. Just
setting the same values in the fsStyle member of the TBBUTTON
structure does not work for some reason??
Anyhow here are the styles I used to get text to display in the
SendMessage TB_SETSTYLE call.
TBSTYLE_BUTTON - Standard button
TBSTYLE_FLAT - This one highlights the button when mouse is
over the button as a normal menu does
TBSTYLE_AUTOSIZE - This is supposed to size the button based on
the width of the text, but until I get the other strings to
display, I don't really know if this is working or not.
TBSTYLE_CHECKGROUP - This one is not working, when you click on
a normal menu item, it stays depressed which this style should
produce???
TBSTYLE_LIST - Will not work at all unless this style is set.
Anyhow, if someone has better luck with this let me know, Will
On my Web Page http://www20.brinkster.com/ewayne/AsmLoad.html
If you would download the AsmEdit package and then in the Code Generator
routine you can generate many different types of Toolbars.
Or you could look at the Buttons example.
Below is a little sample of a Toolbar with text:
.586
.model flat, stdcall
option casemap :none ; case sensitive
include \masm32V1\include\windows.inc
include \masm32V1\include\user32.inc
include \masm32V1\include\kernel32.inc
include \masm32V1\include\gdi32.inc
include \masm32V1\include\COMCTL32.inc
includelib \masm32V1\lib\user32.lib
includelib \masm32V1\lib\kernel32.lib
includelib \masm32V1\lib\gdi32.lib
includelib \masm32V1\lib\COMCTL32.lib
MOVmd MACRO Var1, Var2
push Var2
pop Var1
ENDM
TBSep MACRO hTool
mov tbb.iBitmap, 0
mov tbb.idCommand, 0
mov tbb.fsState, TBSTATE_ENABLED
mov tbb.fsStyle, TBSTYLE_SEP
INVOKE SendMessage, hTool, TB_ADDBUTTONS, 1, addr tbb
ENDM
TBButt MACRO hTool, bID, cID, Text
mov tbb.iBitmap, bID ; Button image number
mov tbb.idCommand, cID ; Command ID number
mov tbb.fsState, TBSTATE_ENABLED
mov tbb.fsStyle, TBSTYLE_BUTTON
mov tbb.dwData, 0
mov tbb.iString, Text
INVOKE SendMessage, hTool, TB_ADDBUTTONS, 1, addr tbb
ENDM
WndProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
.data
ToolClass db 'ToolbarWindow32',0
FontNameS db 'Challenge Extra Bold',0 ;'MS Sans Serif',0
szStyleB10 db 'B10',0
dlgname db 'TESTDLG',0
hDlg dd 0
hInst dd 0
hIcon dd 0
hFontT dd 0
hWndTooL10 dd 0
Done dd 0
hDC dd 0
hBR dd 0
hMemDC dd 0
hStyleB10U dd 0
hImageList dd 0
rect RECT >
lf LOGFONT >
tbb TBBUTTON >
.code
start:
INVOKE GetModuleHandle, NULL
mov hInst, eax
call InitCommonControls ; Initialize the common ctrl lib
; ===========================================
; Call the dialog box stored in resource file
; ===========================================
INVOKE DialogBoxParam, hInst, addr dlgname, 0, addr WndProc, 0
INVOKE ExitProcess, eax
;============================================
; Main window procedure
;============================================
WndProc proc hWnd:DWORD, uMsg, wParam, lParam
LOCAL wF:DWORD, wT, Cnt
.if uMsg == WM_INITDIALOG
MOVmd hDlg, hWnd
INVOKE LoadIcon, hInst, 200
mov hIcon, eax
INVOKE SendMessage, hWnd, WM_SETICON, 1, hIcon
INVOKE lstrcpy, addr lf.lfFaceName, addr FontNameS
mov lf.lfHeight, -22
mov lf.lfWidth, 0
mov lf.lfWeight, 400
INVOKE CreateFontIndirect, addr lf
mov hFontT, eax
;---------- ----------
INVOKE LoadImage, hInst, 136, IMAGE_BITMAP, 25, 26, LR_DEFAULTCOLOR
mov hStyleB10U, eax
;---------- ----------
INVOKE CreateWindowEx, 0, addr ToolClass, 0, WS_CHILD or WS_VISIBLE or\
TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or CCS_NORESIZE or\
TBSTYLE_LIST or TBSTYLE_FLAT or CCS_NODIVIDER,\
10, 10, 75, 32, hWnd, 83, hInst, NULL
mov hWndTooL10, eax
INVOKE ImageList_Create, 25, 26, ILC_COLOR32, 1, 0
mov hImageList, eax
INVOKE ImageList_Add, hImageList, hStyleB10U, NULL
INVOKE SendMessage, hWndTooL10, TB_SETIMAGELIST, 0, hImageList
INVOKE SendMessage, hWndTooL10, WM_SETFONT, hFontT, 1
INVOKE SendMessage, hWndTooL10, TB_BUTT
You might want to make sure that File, View, and Help are not being treated as macro variables by replacing & with &&.