Thread: Some problem with a toolbar???

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    44

    Some problem with a toolbar???

    Hi there,

    I'm trying to add my own button to an existing toolbar (not created by me). However, I just either get a seperator, or some other button from the toolbar...here's the code I'm using:


    Code:
    	LRESULT success;
    	_TBBUTTON *pbuttonarray;
    	_TBBUTTON buttonarray[1];
    	pbuttonarray=buttonarray;
    	int iIndex = -1;
    
    	char *buff="My button!\0\0";
    	iIndex = SendMessage(TBHandle,TB_ADDSTRING,NULL,(long)buff);
    
    	buttonarray[0].fsState=TBSTATE_ENABLED;
    	buttonarray[0].fsStyle=BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT;
    	buttonarray[0].dwData=0;
    	buttonarray[0].iString=iIndex;
    	buttonarray[0].iBitmap=0;
    
    	success=SendMessage(TBHandle,TB_ADDBUTTONS,1,(LPARAM)pbuttonarray);
    
    	if(success)
    		cout<<"ok\n";
    	else
    		cout<<"bad\n";

    now it always adds the string to the stringpool okay, and it also always ends in success. But for the life of me I just cannot get just a simple button with just some text on saying "My Button"...

    Anyone want to just appear out of cyberspace and solve it with a wave of a magic wand?

    Uni


    btw...sorry for the bad formatting, it is fine in VC, but it hasn't shown up as well...

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You fill in the

    _TBBUTTON buttonarray[1];

    button struct

    but use the

    _TBBUTTON *pbuttonarray;

    pointer in the add button msg.

    also

    from MSDN
    "If the toolbar was created using the CreateWindowEx function, you must send the TB_BUTTONSTRUCTSIZE message to the toolbar before sending TB_ADDBUTTONS."
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    44
    Sorry, I can't figure out what you're trying to say...I thought I needed a pointer to a TBBUTTON array when calling TB_ADDBUTTONS?


    "If the toolbar was created using the CreateWindowEx function"...I don't know how it was created, because its in an existing application.


    Thanks

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    sorry missed a line..........


    try sending a TB_BUTTONSTRUCTSIZE msg(to tell the app the size/version of the toolbar struct you are using), see if it helps.

    >>success=SendMessage(TBHandle,TB_ADDBUTTONS,1,(LP A
    RAM)pbuttonarray);

    try

    success = SendMessage( TBHandle, TB_ADDBUTTONS, 1, (LPARAM)&buttonarray[0]);

    might like that better..........


    >>I don't know how it was created, because its in an existing application.

    if its old try using TBSTYLE_AUTOSIZE instead of BTNS_AUTOSIZE (depends on the version of common control DLL it used).

    How are you intercepting the toolbar msg's for your buttons (as opposed to other msg's for the toolbar) ?

    Can you get its HWND?
    it may be there with 0 size as it has no image......
    Can you set one?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    44
    I'm afraid nothing there has made a difference , including the size.


    "How are you intercepting the toolbar msg's for your buttons (as opposed to other msg's for the toolbar) ?

    I'm not because I don't even have a button to capture from.


    "Can you get its HWND?"

    I'm not fully sure, as I'm not quite sure how I do this.


    "it may be there with 0 size as it has no image......"

    I thought of this, however, when I try to customize the toolbar (through the right click menu), the newly added thing is actually shown as a seperator.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try specifing a Command ID in the TBUTTON struct. This must be individual to the dialog / toolbar so use a 40000+ number to avoid conflicts

    ie
    #define IDB_MYBUTTON 40001

    buttonarray[0].idCommand = IDB_MYBUTTON;


    then after you have added it
    Code:
    hWndButton=NULL;
    hWndButton = GetDlgItem(hWndToolBar, IDB_MYBUTTON);
    if(hWndButton==NULL)
    {
          iError = GetLastError();
    }
    are you going to set a new WNDPROC for the button? (if you need to ask what I mean then this is probably beyond your ability at present, read up on subclassing controls)

    Check to see if it gets an msg's.

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    44
    I'm getting a stupid error about the format of GetDlgItem...

    handle=GetDlgItem (TBHandle,BTNCMD);

    that's what I've got but I'm getting:

    syntax error : missing ')' before ';'
    syntax error : ')'

    both pointing to that line

    "are you going to set a new WNDPROC for the button?"
    Yes, because I've already done something similar to this, (minus getting the button to show) so I can just adapt that code.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    44
    <yoink>

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Did you #define the ID for the button and set it? (that should be 'undeclared identifier' error)

    Running out of ideas........hard as I do not know the full details.

    Have you tried using InsertButton to put the button between some existing buttons?

    Why are you using _TBBUTTON not TBBUTTON? I can't find a define for the _TBBUTTON struct.

    >>buttonarray[0].iBitmap=0;
    should be

    buttonarray[0].iBitmap=-1;

    as this is the index of the image the button displays from the tollbar image list.


    Are you writting this in C or C++? Are you using .c or .cpp files?
    As in MFC GetDlgItem() only has one param, the ID of the control.

    Was the original app written in C or C++ (if C++ did it use MFC?)

    The original toolbar may be redrawing itself to a set size (or in some other way hiding your button).
    Try subclassing the toolbar (SetWindowLongPtr() ) and looking at what msg's it is receiving as you add the button.

    If using MSVC the Spy++ tool will enable you to intercept these msg's without writting the code.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User
    Join Date
    May 2003
    Posts
    44
    "Did you #define the ID for the button and set it? (that should be 'undeclared identifier' error)"

    Sorry but I'm not following you there...


    "Have you tried using InsertButton to put the button between some existing buttons?"

    Yeah and the same thing happens...


    ">>buttonarray[0].iBitmap=0;
    should be

    buttonarray[0].iBitmap=-1;"

    Unfortunately hasn't made a difference I've also tried using I_IMAGENONE...again no differerence.


    "Are you writting this in C or C++? Are you using .c or .cpp files? "

    C++


    "Was the original app written in C or C++ (if C++ did it use MFC?)"

    I'm afraid I couldn't begin to tell you!


    "Try subclassing the toolbar (SetWindowLongPtr() ) and looking at what msg's it is receiving as you add the button."

    I'll give it a go!

  11. #11
    Registered User
    Join Date
    May 2003
    Posts
    44
    Right...these are the messages:


    <00001> 002F0420 S ....TB_ADDSTRING hinst:00000000 idString:24704
    <00002> 002F0420 R ....TB_ADDSTRING nIndex:47
    <00003> 002F0420 S ....TB_SETBUTTONSIZE dxButton:100 dyButton:0
    <00004> 002F0420 R ....TB_SETBUTTONSIZE fSucceeded:True
    <00005> 002F0420 S ....TB_ADDBUTTONS uNumButtons:1 lpButtons:0012FEFC
    <00006> 002F0420 R ....TB_ADDBUTTONS fSucceeded:True

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>TB_SETBUTTONSIZE dxButton:100 dyButton:0

    The height has been set to zero so the button will not show up. It probably gets the width from the string it is to display.

    Try sending a msg to set the button size manually.

    Or try setting a new font in the toolbar before adding the button.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Toolbar problem
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2005, 11:38 AM
  3. Toolbar problem
    By Ward in forum Windows Programming
    Replies: 0
    Last Post: 12-21-2005, 03:08 PM
  4. Dockable Toolbar (Like taskbar or office toolbar)
    By om3ga in forum Windows Programming
    Replies: 2
    Last Post: 11-20-2005, 03:09 AM
  5. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM