News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Toolbar problem

Started by minor28, February 18, 2011, 04:11:44 PM

Previous topic - Next topic

minor28

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

jj2007

Check sizeof TBBUTTON.
Try BTNS_SHOWTEXT,0,0>\

minor28

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



jj2007

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>

minor28

No change. Still three A-buttons. No other size then sizeof TBUTTON works e.i 20 not 60.

jj2007

OK, if you want to stop the guessing, post your complete code.

minor28

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

minor28

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??


Tedd

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>

No snowflake in an avalanche feels responsible.

minor28

Thank you. That's the answer of my question. The TBBUTTON structure is not the same in masm32 as in msdn.


dedndave

they probably could have defined it like this...
TBBUTTON STRUCT
  iBitmap           DWORD      ?
  idCommand         DWORD      ?
  fsState           BYTE       ?
  fsStyle           BYTE       ?,?,?
  dwData            DWORD      ?
  iString           DWORD      ?
TBBUTTON ENDS

minor28

or this perhaps


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




MichaelW

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

eschew obfuscation