Results 1 to 8 of 8

Thread: Toolbar Button

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    UK
    Posts
    7

    Toolbar Button

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Private Const WM_USER = &H400
    Private Const TB_PRESSBUTTON = (WM_USER + 3)
    Private Const TB_GETBUTTON = (WM_USER + 23)

    Type TBBUTTON
    iBitmapas As Integer
    idCommand As Integer
    fsState As Byte
    fsStyle As Byte
    dwData As Long
    iString As Integer
    End Type

    Private Sub Form_load()
    Dim but As TBBUTTON
    SendMessage Toolbar1.hwnd, TB_GETBUTTON, 1, but '1 is the index button.
    SendMessageToolbar1.hwnd, TB_PRESSBUTTON, but.idCommand, True
    End Sub

    I want to press to a button toolbar without using mouse .
    What is wrong with this code. And Thank You..

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    how are you inserting the buttons using the api?
    Always looking for a better and faster way!

  3. #3
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    Haha, does anyone know how?
    Always looking for a better and faster way!

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    You'd add them with TB_INSERTBUTTON or TB_ADDBUTTONS. I've never tried it myself since using the control stuff is much easier, and I've not been able to get info out of a toolbar with API things before, even something as paltry as getting the number of buttons already in it via SendMessage and TB_BUTTONCOUNT.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  5. #5
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    The API is sooo much better then the controls. You have all the
    options and flexibility you want and most of all, its FAST!
    I have created the Toolbar with the API and i can see it, but I
    cant seem to bet a button on it
    Anyone have and example of using TB_INSERTBUTTON ? I cant find
    any on the net.
    Always looking for a better and faster way!

  6. #6
    Member
    Join Date
    Oct 2000
    Posts
    34
    Well, if you are using the toolbar control supplied by Microsoft (MSCOMCTL.OCX) then you cannot use the API to modify the toolbar. If you fire up Spy++ and point it at the toolbar on your form you will see that it is not a "true" toolbar. It appears to be a superclass of the comctl32.dll toolbar ("ToolbarWindow32"). Sending TB_INSERTBUTTON does not have any affect.

    BTW, this may not be the case if you are using VB5, I myself use VB6 and cannot test it on VB5.

    However, if you are using a real API toolbar you can use TB_INSERTBUTTON like so:

    VB Code:
    1. Dim nPos As Long
    2. Dim tbb As TBBUTTON
    3.  
    4. ' You only have to send the TB_BUTTONSTRUCTSIZE message once, before inserting the first button.
    5. SendMessage hwndTb, TB_BUTTONSTRUCTSIZE, Len(tbb), ByVal 0&
    6.  
    7. ' Since we want to insert the button at the end of the toolbar, set
    8. ' nPos to the number of buttons in the toolbar
    9. nPos = SendMessage(hwndTb, TB_BUTTONCOUNT, 0, ByVal 0&)
    10.  
    11. ' Fill in the button structure
    12. tbb.idCommand = 50 ' Change the ID to be whatever you want
    13. tbb.iBitmap = -1 ' Change this value to indicate the index of the button icon, or -1 for no icon
    14. tbb.iString = -1 ' If your toolbar button needs to display text, you need to send the toolbar a TB_ADDSTRING message and set iString to the value returned
    15. tbb.fsState = TBSTATE_ENABLED
    16. tbb.fsStyle = TBSTYLE_BUTTON
    17.  
    18. ' Insert the button
    19. SendMessage hwndTb, TB_INSERTBUTTON, nPos, tbb
    20.  
    21. ' You could also have used:
    22. SendMessage hwndTb, TB_ADDBUTTONS, 1, tbb

  7. #7
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    Oh Ya! Thats what i was looking for. Thanks. And yes, all my crontrols are created with the API CreateWindowEx function. I created a ListView DLL for the windows api and added classes for ListItems and Subitems..I even have options to change scrollbar colors and states. Thanks.
    Always looking for a better and faster way!

  8. #8
    Addicted Member
    Join Date
    Oct 2000
    Location
    Orlando, FL
    Posts
    253
    You wouldnt happen to have values for those constants would
    you?
    Always looking for a better and faster way!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width