flat assembler
Message board for the users of flat assembler.

Index > Windows > Toolbar trouble

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio 13 Nov 2008, 15:39
Hi, I want to put a toolbar on my program.
In my data section I've declared an array of strings using this macro:

Code:
macro strArray name,[string]
{
  common
  label name dword
  forward
        local label
        dd label
  forward
        label TCHAR string,0
}

strArray szToolbar,'New','Select','Previous','Next','Delete'
    

I declared in my udata section a tbAddBitmap structure...
Code:
tbAddBitmap   TBADDBITMAP 0,IDC_TOOLBAR
    

...and and array of TBBUTTON structure
Code:
tbButton        TBBUTTON NEW,     IDM_NEW,     TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0
                TBBUTTON SELECT,  IDM_SELECT,  TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0
                TBBUTTON PREVIOUS,IDM_PREVIOUS,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0
                TBBUTTON NEXT,    IDM_NEXT,    TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0
                TBBUTTON DEL,     IDM_DEL,     TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0
    

I'm a C programmer, so I use my old code to do things in asm.
I'm keep in trouble while converting this piece of code:
Code:
//
INT iButtons = __SIZEOF_ARRAY__(tbButtons);
TBADDBITMAP tbAddBitmap = { hInstance, IDP_TOOLBAR };
SendMessage(hToolbar, TB_ADDBITMAP, iButtons, (LPARAM)&tbAddBitmap);
//
for ( INT i = 0; i < iButtons; i++ )
{
   tbButtons[i].iString = SendMessage(hToolbar, TB_ADDSTRING, 0, (LPARAM)szToolbar[i]);
}
    

Ok, for the size of TBBUTTON array I use a constant, I'm not able to calculate it.
Then I put program instance into previous declared TbAddBitmap struct:
Code:
mov eax,[hInstance]
mov [tbAddBitmap.hInst],eax
    

then I've tried to convert that C code but I'm not able to put return values of SendMessage into tbbutton[i].iString
Code:
invoke SendMessage,[hToolbar],TB_ADDBITMAP,TB_BUTTONS,tbAddBitmap
xor ecx,ecx
@@:
mov esi,[szToolbar+ecx*4]
push ecx
invoke SendMessage,[hToolbar],TB_ADDSTRING,0,esi
; here values of eax should be putted into tbButton[i].iString
pop ecx
inc ecx
cmp ecx,TB_BUTTONS; TB_BUTTONS is a constant, how to get number of tbButton array elements ?
jl @r
    


How can be done ?
Post 13 Nov 2008, 15:39
View user's profile Send private message MSN Messenger Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 13 Nov 2008, 17:33
Alessio,

Attach compilable source, that will help us to help you faster.
Post 13 Nov 2008, 17:33
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 13 Nov 2008, 17:46
Code:
tbButton        TBBUTTON NEW,     IDM_NEW,     TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0 
                TBBUTTON SELECT,  IDM_SELECT,  TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0 
                TBBUTTON PREVIOUS,IDM_PREVIOUS,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0 
                TBBUTTON NEXT,    IDM_NEXT,    TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0 
                TBBUTTON DEL,     IDM_DEL,     TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0 

TB_BUTTONS = ($-tbButton)/sizeof.TBBUTTON    
Post 13 Nov 2008, 17:46
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 13 Nov 2008, 17:49
Code:
imul edx,ecx,sizeof.TBBUTTON
mov [tbButton.iString + edx],eax    
Post 13 Nov 2008, 17:49
View user's profile Send private message Visit poster's website Reply with quote
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio 17 Nov 2008, 09:16
thank you
Post 17 Nov 2008, 09:16
View user's profile Send private message MSN Messenger Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 29 Dec 2009, 15:43
I'm trying to create a toolbar, but something is wrong.

Code:
  .wm_create:
                invoke  CreateWindowEx,0,TOOLBARCLASSNAME,NULL,WS_CHILD+WS_VISIBLE,\
                        0,0,0,0,[hwnd],NULL,[wc.hInstance],NULL
                test    eax, eax
                jnz     @f
                invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK
            @@:
                jmp     .finish0     
TOOLBARCLASSNAME is not recognized. So I did
Code:
TOOLBARCLASSNAME db 'ToolbarWindow32',0     

But CreateWindowEx is always returning 0.
Post 29 Dec 2009, 15:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 29 Dec 2009, 16:26
What does GetLastError tell you?
Post 29 Dec 2009, 16:26
View user's profile Send private message Visit poster's website Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 29 Dec 2009, 16:53
Teehee, are you sure that you call the 'InitCommonControls' function at the beginning of your code?
Code:
format PE GUI 4.0

include 'win32ax.inc'

(...)

section '.code' code readable executable

        start:
          invoke  InitCommonControls

      (...)

.end start    
BTW, in the 'COMCTL32.INC' file exists such definition of the toolbar class name:
Code:
TOOLBAR_CLASS     equ 'ToolbarWindow32'    
Post 29 Dec 2009, 16:53
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 29 Dec 2009, 17:17
MHajduk wrote:
Teehee, are you sure that you call the 'InitCommonControls' function at the beginning of your code?


oh.. undocumented data. Sad
however, it seems obsolete. MSDN told to use InitCommonControlsEx.

Now its working Smile Thanks.

PS: There is a way to create Toolbar from resource? (like Menus)

Edit: Link fixed.

_________________
Sorry if bad english.


Last edited by Teehee on 31 Dec 2009, 08:45; edited 2 times in total
Post 29 Dec 2009, 17:17
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 29 Dec 2009, 17:29
Teehee wrote:
oh.. undocumented data. Sad
Slightly off-topic here, but for your information I have to say that this forum doesn't accept parentheses in the urls. If you want to use them anyway, use these codes instead:
Code:
%28 for '('
%29 for ')'    
Now you have a proper link:
Quote:
oh.. undocumented data. Sad
Wink
Post 29 Dec 2009, 17:29
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 29 Dec 2009, 17:58
thanks again Smile
Post 29 Dec 2009, 17:58
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 08:38
I'm can't to shown the text in the ToolBar's buttons.

Button config:
Code:
toolButton1 TBBUTTON I_IMAGECALLBACK,0,TBSTATE_ENABLED,TBSTYLE_DROPDOWN+BTNS_SHOWTEXT,0,'New'     


Toolbar config:
Code:
invoke  CreateWindowEx,0,TOOLBAR_CLASS,NULL,\
        WS_VISIBLE+WS_BORDER+WS_CHILD+TBSTYLE_WRAPABLE+TBSTYLE_LIST+BTNS_SHOWTEXT+\
        TBSTYLE_FLAT+TBSTYLE_TOOLTIPS,\
        0,0,0,0,eax,NULL,[wc.hInstance],NULL
mov     [hToolBar], eax

invoke  SendMessage,[hToolBar],TB_BUTTONSTRUCTSIZE,sizeof.TBBUTTON,0
invoke  SendMessage,[hToolBar],TB_ADDBUTTONS,1,toolButton1 

invoke  SendMessage,[hToolBar],TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_DRAWDDARROWS
invoke  SendMessage,[hToolBar],TB_AUTOSIZE,0,0    


What's happening?


Description: :(
Filesize: 1.23 KB
Viewed: 13655 Time(s)

imagem.PNG



_________________
Sorry if bad english.
Post 31 Dec 2009, 08:38
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 31 Dec 2009, 10:12
Teehee wrote:
I'm can't to shown the text in the ToolBar's buttons.

Button config:
Code:
toolButton1 TBBUTTON I_IMAGECALLBACK,0,TBSTATE_ENABLED,TBSTYLE_DROPDOWN+BTNS_SHOWTEXT,0,'New'     
Accordingly to the definition and description of the 'TBBUTTON' structure in MSDN
Code:
typedef struct _TBBUTTON { 
  int iBitmap; 
  int idCommand; 
  BYTE fsState; 
  BYTE fsStyle; 
  DWORD dwData; 
  int iString; 
} TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;
typedef const TBBUTTON FAR* LPCTBBUTTON;    
MSDN wrote:

Members

(...)

iString
Zero-based index of the button string.
the last field of the structure can't be a pointer to the string but 'Zero-based index of the button string', i.e. rather index of element in the array of the pointers to the strings (if I understood it correctly).

BTW, see the first post in this thread. Wink
Post 31 Dec 2009, 10:12
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 10:31
edit:
Well, MSDN says:
MSDN wrote:
iString
Zero-based index of the button string, or a pointer to a string buffer that contains text for the button.


Also, here says:
Quote:
Using TB_ADDSTRING is not the only way to add strings to a toolbar. You can display a string in a button by passing a string pointer in the iString field of the TBBUTTON structure that is passed to TB_ADDBUTTONS. Additionally, you can use TB_SETBUTTONINFO to assign text to a toolbar button.
But that seems does not work. Sad At least i'm can't.

end edit.

----

And now i'm having troubles with TBN_DROPDOWN notification.
I don't know how to get it.

I did:
Code:
  .wm_notify:
                mov     eax, [lparam]
                mov     [TB_nmt], eax   ; TB_nmt NMTOOLBAR
                mov     eax, [hToolBar]
                cmp     [TB_nmt.hdr.hwndFrom], eax
                jne    @f
                invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK
            @@: jmp    .finish0
    

but i don't know what's wrong, it's always jumping the messagebox.
Post 31 Dec 2009, 10:31
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 13:44
Ok, I found iString trouble.

Code:
_txt1 db 'example',0
...
toolButton TBBUTTON I_IMAGECALLBACK,0,TBSTATE_ENABLED,\
                    BTNS_BUTTON+TBSTYLE_DROPDOWN+BTNS_SHOWTEXT+BTNS_WHOLEDROPDOWN,0,\
                    _txt1 ; <--- here is the trouble.    


if I move _txt1 to iString in the code, it works:
Code:
mov     [toolButton.iString],_txt1
invoke  SendMessage,[hToolBar],TB_ADDBUTTONS,1,toolButton  ; Works!    
Otherwise, not work! The question is: why?

_________________
Sorry if bad english.
Post 31 Dec 2009, 13:44
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 31 Dec 2009, 17:58
Most probably, whole this mess with 'TBBUTTON' structure is caused by different definitions of it for 32-bit and 64-bit versions of Windows. I suppose that you use 64-bit system, so you can't use 32-bit version of the 'TBBUTTON' structure (which I mentioned above).

Let's see how these definitions look like in the 'COMCTL32.INC' and 'COMCTL64.INC' files.

32-bit version:
Code:
; COMCTL32.INC

struct TBBUTTON
  iBitmap   dd ?
  idCommand dd ?
  fsState   db ?
  fsStyle   db ?
         dw ? ; 2 bytes
  dwData    dd ?
  iString   dd ?
ends
    
and 64-bit version:
Code:
; COMCTL64.INC

struct TBBUTTON
  iBitmap   dd ?
  idCommand dd ?
  fsState   db ?
  fsStyle   db ?
           dp ? ; 6 bytes
  dwData    dd ?
  iString   dd ?
ends
    
The second one is 4 bytes bigger.

Anyway, try to do this:
Code:
_txt1 db 'example',0 
... 
toolButton TBBUTTON I_IMAGECALLBACK,\                    ; iBitmap
                    0,\                                  ; idCommand
                    TBSTATE_ENABLED,\                    ; fsState
                    \
                    BTNS_BUTTON + TBSTYLE_DROPDOWN + \   ; fsStyle
                    BTNS_SHOWTEXT + BTNS_WHOLEDROPDOWN,\ ; 
                    \
                    0,\                                  ; padding data
                    0,\                                  ; dwData
                _txt1                                ; iString
    
Maybe this will help. Wink


Last edited by MHajduk on 31 Dec 2009, 18:24; edited 1 time in total
Post 31 Dec 2009, 17:58
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 18:06
it works. But i'm not working with 64-bit Shocked

_________________
Sorry if bad english.
Post 31 Dec 2009, 18:06
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 31 Dec 2009, 18:22
OK, seems that I'm slightly distracted today - you just always have to initialize this unnamed member of the structure 'TBUTTON'. OS version doesn't matter here. Wink
Post 31 Dec 2009, 18:22
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 18:25
Hmm, ok. Thanks you. Smile
Post 31 Dec 2009, 18:25
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 31 Dec 2009, 18:38
oh, please, do not forget this:

Quote:

And now i'm having troubles with TBN_DROPDOWN notification.
I don't know how to get it.

I did:
Code:
  .wm_notify:
                mov     eax, [lparam]
                mov     [TB_nmt], eax   ; TB_nmt NMTOOLBAR
                mov     eax, [hToolBar]
                cmp     [TB_nmt.hdr.hwndFrom], eax
                jne    @f
                invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK
            @@: jmp    .finish0
    

but i don't know what's wrong, it's always jumping the messagebox.
Post 31 Dec 2009, 18:38
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.