?
Solved

URGENT : Toolbar Dropping-Down

Posted on 2001-09-06
9
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

801 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