|
-
Jul 1st, 2001, 04:54 AM
#1
Thread Starter
New Member
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..
-
Aug 27th, 2001, 04:02 PM
#2
Addicted Member
how are you inserting the buttons using the api?
Always looking for a better and faster way!
-
Sep 13th, 2001, 11:55 AM
#3
Addicted Member
Haha, does anyone know how?
Always looking for a better and faster way!
-
Sep 13th, 2001, 01:19 PM
#4
Fanatic Member
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 
-
Sep 13th, 2001, 01:23 PM
#5
Addicted Member
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!
-
Sep 18th, 2001, 07:03 PM
#6
Member
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:
Dim nPos As Long
Dim tbb As TBBUTTON
' You only have to send the TB_BUTTONSTRUCTSIZE message once, before inserting the first button.
SendMessage hwndTb, TB_BUTTONSTRUCTSIZE, Len(tbb), ByVal 0&
' Since we want to insert the button at the end of the toolbar, set
' nPos to the number of buttons in the toolbar
nPos = SendMessage(hwndTb, TB_BUTTONCOUNT, 0, ByVal 0&)
' Fill in the button structure
tbb.idCommand = 50 ' Change the ID to be whatever you want
tbb.iBitmap = -1 ' Change this value to indicate the index of the button icon, or -1 for no icon
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
tbb.fsState = TBSTATE_ENABLED
tbb.fsStyle = TBSTYLE_BUTTON
' Insert the button
SendMessage hwndTb, TB_INSERTBUTTON, nPos, tbb
' You could also have used:
SendMessage hwndTb, TB_ADDBUTTONS, 1, tbb
-
Sep 19th, 2001, 01:13 AM
#7
Addicted Member
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!
-
Sep 21st, 2001, 12:24 PM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|