Solved

URGENT : Toolbar Dropping-Down

Posted on 2001-09-06
9
269 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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6465161
Interesting...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

862 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now