The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: minor28 on February 18, 2011, 04:11:44 PM

Title: Toolbar problem
Post by: minor28 on February 18, 2011, 04:11:44 PM
Now, I have tried for a long time but failed to resolve why all the buttons show the "A" and not "A", "R" and "T".
I would appreciate some help with this problem. Here is the code.


.const
TbBtns5 TBBUTTON <-1,IDC_TBB51,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,0>
TBBUTTON <-1,IDC_TBB52,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,1>
TBBUTTON <-1,IDC_TBB53,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,2>
nTbBtns5 equ 3

.data
BtnStrArray5 db "A",0,"R",0,"T",0,0

.code
invoke GetDlgItem,hWin,IDC_TBR5
mov hTBR5,eax
invoke SendMessage,hTBR5,TB_BUTTONSTRUCTSIZE,sizeof TBBUTTON,0
invoke SendMessage,hTBR5,TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_MIXEDBUTTONS
invoke SendMessage,hTBR5,TB_ADDSTRING,0,offset BtnStrArray5
invoke SendMessage,hTBR5,TB_SETBITMAPSIZE,0,0
invoke SendMessage,hTBR5,TB_ADDBUTTONS,nTbBtns5,offset TbBtns5
invoke SendMessage,hTBR5,TB_AUTOSIZE,0,0


Best regards
Title: Re: Toolbar problem
Post by: jj2007 on February 18, 2011, 04:53:23 PM
Check sizeof TBBUTTON.
Try BTNS_SHOWTEXT,0,0>\
Title: Re: Toolbar problem
Post by: minor28 on February 18, 2011, 07:14:43 PM
Thanks for your answer.

My other toolbars work with TBUTTON as I wrote them, if buttons are images and not text. Compile with '\' gives the following error:

error A2006: undefined symbol : TbBtns5
error A2114: INVOKE argument type mismatch : argument : 4


Title: Re: Toolbar problem
Post by: jj2007 on February 18, 2011, 09:56:03 PM
This will work, and return the correct size of 60 bytes instead of 20 as in your version:
TbBtns5 TBBUTTON <-1,IDC_TBB51,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,0>,
<-1,IDC_TBB52,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,1>,
<-1,IDC_TBB53,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,2>
Title: Re: Toolbar problem
Post by: minor28 on February 18, 2011, 10:36:45 PM
No change. Still three A-buttons. No other size then sizeof TBUTTON works e.i 20 not 60.
Title: Re: Toolbar problem
Post by: jj2007 on February 18, 2011, 11:50:43 PM
OK, if you want to stop the guessing, post your complete code.
Title: Re: Toolbar problem
Post by: minor28 on February 19, 2011, 09:09:17 AM
I assume you mean complete code for the toolbar.

The toolbar is in the resource file of the main dialog.


CONTROL "",IDC_TBR5,"ToolbarWindow32",0x5200114C,566,1,104,14,0x00000000


Translated to code it will be


invoke CreateWindowEx,0,offset szToolbarWindow32,0,
TBSTYLE_TOOLTIPS or TBSTYLE_LIST or \
CCS_NORESIZE or CCS_NOPARENTALIGN or CCS_NODIVIDER or \
WS_CHILD or WS_CLIPCHILDREN or WS_VISIBLE,
850,0,104,24,hWin,IDC_TBR5,hInstance,0

;invoke GetDlgItem,hWin,IDC_TBR5
mov hTBR5,eax
invoke SendMessage,hTBR5,TB_BUTTONSTRUCTSIZE,sizeof TBBUTTON,0
invoke SendMessage,hTBR5,TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_MIXEDBUTTONS
invoke SendMessage,hTBR5,TB_ADDSTRING,0,offset BtnStrArray5
invoke SendMessage,hTBR5,TB_SETBITMAPSIZE,0,0
invoke SendMessage,hTBR5,TB_ADDBUTTONS,nTbBtns5,offset TbBtns5
invoke SendMessage,hTBR5,TB_AUTOSIZE,0,0


Same result for both methods.

Edit:
I can read all strings.  This is the "T".

mov ecx,2
shl ecx,16
add ecx,10
invoke SendMessage,hTBR5,TB_GETSTRING,ecx,addr buffer
invoke MessageBox,0,addr buffer,0,MB_OK
Title: Re: Toolbar problem
Post by: minor28 on February 19, 2011, 10:41:31 AM
Finally I got it to work.

I moved TBBUTTON structure to initiated data section. However the indices in the
structure do not work but I did manually set the text indices in the code.


.const
nTbBtns5 equ 3

.data
BtnStrArray5 db "A",0,"R",0,"T",0,0

TbBtns5 TBBUTTON <0,IDC_TBB51,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,0>
TBBUTTON <1,IDC_TBB52,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,1>
TBBUTTON <2,IDC_TBB53,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT,0,2>

.code
invoke GetDlgItem,hWin,IDC_TBR5
mov hTBR5,eax
invoke SendMessage,hTBR5,TB_BUTTONSTRUCTSIZE,sizeof TBBUTTON,0
invoke SendMessage,hTBR5,TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_MIXEDBUTTONS
invoke SendMessage,hTBR5,TB_ADDSTRING,0,offset BtnStrArray5

mov edi,offset TbBtns5
assume edi:ptr TBBUTTON
mov [edi].iString,0
add edi,sizeof TBBUTTON
mov [edi].iString,1
add edi,sizeof TBBUTTON
mov [edi].iString,2
assume edi:ptr nothing

invoke SendMessage,hTBR5,TB_SETBITMAPSIZE,0,0
invoke SendMessage,hTBR5,TB_ADDBUTTONS,nTbBtns5,offset TbBtns5
invoke SendMessage,hTBR5,TB_AUTOSIZE,0,0


However the question remains. Why does not the string indices in the TBBUTTON work
when the images indices works??

Title: Re: Toolbar problem
Post by: Tedd on February 19, 2011, 01:13:43 PM
Your original code was fine, but for one tiny detail..

TBBUTTON STRUCT
  iBitmap           DWORD      ?
  idCommand         DWORD      ?
  fsState           BYTE       ?
  fsStyle           BYTE       ?
  _wPad1            WORD       ?
  dwData            DWORD      ?
  iString           DWORD      ?
TBBUTTON ENDS


Just insert an extra padding 0, so the following elements are at the correct offsets.

TBBUTTON <0,IDC_TBB51,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT, 0, 0,0>
TBBUTTON <1,IDC_TBB52,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT, 0, 0,1>
TBBUTTON <2,IDC_TBB53,TBSTATE_ENABLED,BTNS_BUTTON or BTNS_CHECK or BTNS_SHOWTEXT, 0, 0,2>

Title: Re: Toolbar problem
Post by: minor28 on February 19, 2011, 02:21:43 PM
Thank you. That's the answer of my question. The TBBUTTON structure is not the same in masm32 as in msdn.

Title: Re: Toolbar problem
Post by: dedndave on February 19, 2011, 03:40:41 PM
they probably could have defined it like this...
TBBUTTON STRUCT
  iBitmap           DWORD      ?
  idCommand         DWORD      ?
  fsState           BYTE       ?
  fsStyle           BYTE       ?,?,?
  dwData            DWORD      ?
  iString           DWORD      ?
TBBUTTON ENDS
Title: Re: Toolbar problem
Post by: minor28 on February 19, 2011, 03:52:51 PM
or this perhaps


TBBUTTON struct dword
  iBitmap           DWORD      ?
  idCommand         DWORD      ?
  fsState           BYTE       ?
  fsStyle           BYTE       ?
  dwData            DWORD      ?
  iString           DWORD      ?
TBBUTTON ends



Title: Re: Toolbar problem
Post by: MichaelW on February 19, 2011, 03:59:51 PM
Quote from: minor28 on February 19, 2011, 02:21:43 PM
The TBBUTTON structure is not the same in masm32 as in msdn.

Here are the two structures:

This is the definition from CommCtrl.h in the PSDK:

typedef struct _TBBUTTON {
   int iBitmap;
   int idCommand;
   BYTE fsState;
   BYTE fsStyle;
#ifdef _WIN64
   BYTE bReserved[6];          // padding for alignment
#elif defined(_WIN32)
   BYTE bReserved[2];          // padding for alignment
#endif
   DWORD_PTR dwData;
   INT_PTR iString;
} TBBUTTON, NEAR* PTBBUTTON, *LPTBBUTTON;

This is the definition from the MASM32 Windows.inc:

TBBUTTON STRUCT
 iBitmap           DWORD      ?
 idCommand         DWORD      ?
 fsState           BYTE       ?
 fsStyle           BYTE       ?
 _wPad1            WORD       ?
 dwData            DWORD      ?
 iString           DWORD      ?
TBBUTTON ENDS


And yes, this definition will also put the members at the correct alignment:

TBBUTTON STRUCT DWORD
 iBitmap           DWORD      ?
 idCommand         DWORD      ?
 fsState           BYTE       ?
 fsStyle           BYTE       ?
 dwData            DWORD      ?
 iString           DWORD      ?
TBBUTTON ENDS