Solved

URGENT : Toolbar Dropping-Down

Posted on 2001-09-06
9
272 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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