Solved

URGENT : Toolbar Dropping-Down

Posted on 2001-09-06
9
271 Views
Last Modified: 2008-03-10
Hello friends,
I have a Toolbar control with several buttons on it. These buttons have the tbrDropdown style.
So in the right part ot each button I have a DOWN arrow, and when I click on this arrow , a ButtonMenu drops down with a choice of several menu items. I want this drop-down operation to happen when I click even on the button itself (button's left part).

     Anybody know some API function or some way of doing this??
Thank you for reading my question.

                              Pavel Tsekov

0
Comment
Question by:paul_tsekov
9 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 6462556
Use your own menu instead of built-in ButtonMenus, e.g.:

' Form1, add toolbar, menu mnuPop (visible=false), add one submenu
Option Explicit

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
    MyButtonMenu Button
End Sub

Private Sub Toolbar1_ButtonDropDown(ByVal Button As MSComctlLib.Button)
    MyButtonMenu Button
End Sub

Private Sub MyButtonMenu(ByVal Button As MSComctlLib.Button)
    PopupMenu mnuPop, , Button.Left, Button.Top + Button.Height
End Sub
0
 
LVL 17

Accepted Solution

by:
Suat Ozgur earned 300 total points
ID: 6462579
Interesting but this works :)

First it finds the position of the mouse which clicked on a button then it goes to click on the dropdown arrow.

'-----Code Start----
'Put declarations into form declarations because i used them as Private to not use a module

Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
Private Type POINT_TYPE
  x As Long
  y As Long
End Type

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim retval As Long
Dim coord As POINT_TYPE
    If not Button.Style = tbrDropdown Then exit sub
    retval = GetCursorPos(coord)
    retval = SetCursorPos(coord.x - Me.Point(Toolbar1.Left, Toolbar1.Top), coord.y)
    mouse_event &H2, 0, 0, 0, 0
    mouse_event &H4, 0, 0, 0, 0
End Sub
'--------- Code End

Just put a toolbar called as ToolBar1 and set your buttons then you will see what is going on.

I hope you find the best way.
Suat
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6462584
...position of the mouse pointer.... (correction)

suat
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6465161
Interesting...
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6466354
More interesting thing is the question's title: URGENT

:)
suat
0
 
LVL 1

Author Comment

by:paul_tsekov
ID: 6466623
Thank you man, you are a real genius. Superb performance by you. Incredible. Thank you again
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6466659
Thank you Pavel.
0
 
LVL 2

Expert Comment

by:nahumd
ID: 6702574
I had the same question now, so I searched it first and used this answer.
First, nice solution.
Second, does this line :
retval = SetCursorPos(coord.x - Me.Point(Toolbar1.Left, Toolbar1.Top), coord.y)
has an explanation, or is it a harmless bug like it looks like ?

Me.Point(Toolbar1.Left, Toolbar1.Top) returns the RGB of the point, and always returns -1 for the toolbar, so what it really does is moving the cursor one step to the right, calling to toolbar_click event again and again, until it reaches the zone of the dropdown menu, there is stops.

So the above line should actually be replaced with :

SetCursorPos coord.x + 1, coord.y

and it will still achieve the same effect.

0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6702627
It is the way that i shown the (-1) in code :)

By the way, nahumd is right and i am not sure why i did that bug. Interesting thing coord+1 moves the pointer onto drop down arrow. And that little bug gives the code some mystery. :)

Yes, i agree with you nahumd with one exception word:

So the above line "CAN" be replaced with :
SetCursorPos coord.x + 1, coord.y

and this one much better :)

Thanks for warning us nahumd.
And Happy New Year everybody...

regards
suat
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question