I need to figure out how to center text in my buttons. also i need to figure out how to make my buttons the size i want them to be such as 24x24 etc. Here's my source.

.586

.model flat, stdcall
option casemap :none

include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc
include /masm32/include/comctl32.inc

includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib
includelib /masm32/lib/comctl32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD

.const
TB_1 equ 5000
TB_2 equ 5001

.data
ClassName db "Starting Template",0
ToolbarClass db "ToolbarWindow32",0
CaptionText db "Toolbar",0
tb_text1 db "Test1",0
tb_text2 db "Test2",0

.data?
hWnd HANDLE ?
hInstance HANDLE ?
hToolbar HANDLE ?
tbb TBBUTTON <?>

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax
invoke InitCommonControls
; ######################################
WinMain proc hInst:DWORD, hPrevIns:DWORD, CmdLine:DWORD, CmdShow:DWORD

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Pos :DWORD

mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW + CS_VREDRAW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
mov eax, hInstance
mov wc.hInstance, eax
invoke LoadIcon, NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName,offset ClassName
invoke RegisterClassEx, addr wc

invoke GetSystemMetrics,SM_CXSCREEN
sub eax,400
shr eax,1
mov Pos, eax
invoke GetSystemMetrics,SM_CYSCREEN
sub eax,300
shr eax,1
mov Pos+4,eax
mov Pos+8,400
mov Pos+12,300

invoke CreateWindowEx, NULL,
addr ClassName,
addr CaptionText,
WS_OVERLAPPEDWINDOW,
Pos,Pos+4,Pos+8,Pos+12,
NULL,
NULL,
hInst,
NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd

StartLoop:
invoke GetMessage,addr msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
jmp StartLoop
ExitLoop:

mov eax,msg.wParam
ret

WinMain endp
; #######################################
WndProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg == WM_CREATE
invoke CreateWindowEx, NULL,
addr ToolbarClass,
NULL,
WS_CHILD + WS_VISIBLE + WS_CLIPSIBLINGS + CCS_NODIVIDER + CCS_NORESIZE + TBSTYLE_AUTOSIZE + TBSTYLE_LIST,
0,-1,400,41,
hWin,
NULL,
hInstance,
NULL
mov hToolbar,eax

invoke SendMessage,hToolbar,TB_BUTTONSTRUCTSIZE,sizeof tbb,0
invoke SendMessage,hToolbar,TB_SETBUTTONSIZE,24,24

mov tbb.iBitmap,0
mov tbb.idCommand,TB_1
mov tbb.fsState,TBSTATE_ENABLED
mov tbb.fsStyle,BTNS_SHOWTEXT
mov tbb.dwData,0
mov tbb.iString,offset tb_text1
invoke SendMessage,hToolbar,TB_ADDBUTTONS,1,ADDR tbb

mov tbb.iBitmap,0
mov tbb.idCommand,TB_1
mov tbb.fsState,TBSTATE_ENABLED
mov tbb.fsStyle,BTNS_SHOWTEXT
mov tbb.dwData,0
mov tbb.iString,offset tb_text1
invoke SendMessage,hToolbar,TB_ADDBUTTONS,1,ADDR tbb


.elseif uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret

WndProc endp
; #########################################
end start
Posted on 2004-05-24 07:05:31 by smurf
I think that the toolbar itself will resize the buttons auto if they are first added to the internal string table first.

Heres a snip of C code along the same lines that should work...



// Add the button strings to the toolbar.
LoadString(g_hinst, IDS_CUT, (LPSTR) &szBuf, MAX_LEN);
iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);

LoadString(g_hinst, IDS_COPY, (LPSTR) &szBuf, MAX_LEN);
iCopy = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);


LoadString(g_hinst, IDS_PASTE, (LPSTR) &szBuf, MAX_LEN);
iPaste = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);

// Fill the TBBUTTON array with button information, and add the
// buttons to the toolbar.
tbb[0].iBitmap = BMP_CUT;
tbb[0].idCommand = IDM_CUT;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0;
tbb[0].iString = iCut;

tbb[1].iBitmap = BMP_COPY;

tbb[1].idCommand = IDM_COPY;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0;
tbb[1].iString = iCopy;

tbb[2].iBitmap = BMP_PASTE;
tbb[2].idCommand = IDM_PASTE;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].dwData = 0;
tbb[2].iString = iPaste;

SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS,
(LPARAM) (LPTBBUTTON) &tbb);
Posted on 2004-05-24 17:04:43 by Graebel
is there anyway to make a toolbar button smaller than 16x16? whats the smallest size possible?
Posted on 2004-05-28 21:03:48 by smurf
Hi Smurf,

I believe that the problem with your original code may be the TBSTYLE_LIST in the CreateWindowEx function. This style places text to the right of the image in a button (normally, text is placed below the image in a button). As you have specified a button size of 24x24, the text is trying to appear on the right side of a 24x24 button bitmap image. If you remove TBSTYLE_LIST then the text will centre itself in your buttons.

All buttons in a toolbar have the same size; they will resize themselves to accomodate the largest string that appears on the buttons.


Regards,

AsmCoder
Posted on 2004-06-04 12:53:26 by AsmCoder