Solved

URGENT : Toolbar Dropping-Down

Posted on 2001-09-06
9
268 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:
smozgur 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:smozgur
ID: 6462584
...position of the mouse pointer.... (correction)

suat
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6465161
Interesting...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:smozgur
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:smozgur
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:smozgur
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now