Solved

OnMouseDown in TPopupMenu

Posted on 1997-06-30
7
376 Views
Last Modified: 2010-04-04
I need to be able to react to mousedowns on menu items that have subitems.

normally, the menu only reacts (closes) when the user clicks on a leaf (a menu item without subitems).

The only available event in TMenuItem is OnClick, but this also gets triggered if an item is highlighted.

Can anyone show me how to implement this handler, 'cause i'm slightly stuck (understatement of the year)
0
Comment
Question by:jmstolting
  • 4
  • 2
7 Comments
 

Author Comment

by:jmstolting
ID: 1337987
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:ygolan
ID: 1337988
You will need to capture the WM_MenuSelect message.
0
 

Author Comment

by:jmstolting
ID: 1337989
ygolan :

thanks for your proposed answer.

WM_MenuSelect won't work for two reasons :

1. The T(Popup)Menu triggers this message on two occasions. [A] the user clicks on a menuitem which doesn't have any subitems (so far so good) and [B] the user positions the mousecursor over an item which has subitems. (automatic opening of the sub-menu). I need to be able to determine if the user generates a mousedown over a menuitem wether it has subitems or not.

2. when the user clicks on a menuitem which has subitems, windows doesn't send _any_ message to the menu.WinProc handler.

-----

I know, this problem is slightly bigger than I first thought it to be. oh well, another 101 points then.

ps: I think using a mousehook should do the trick, but I don't have the time to explore this subject extensively.

jeroen

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:jmstolting
ID: 1337990
Adjusted points to 301
0
 
LVL 1

Expert Comment

by:Gabor
ID: 1337991
Which version of Delphi do you use?I think it's a difficult task to handle mouse events on a menu, because it's made to be a MENU (select one, and send back the result)It would help if you write down exactly what you want to do.
0
 

Author Comment

by:jmstolting
ID: 1337992
Gabor,

I'm using Delphi 3.0 professional.

What I want to do is this : I want users to be able to select items from a tree, represented by a (popup)menu.

When a user selects an item, all parents of this item should be selected. This isn't difficult if the user would only able to select the leaves of the tree, but that's not what I want.

They should be able to select an item, for example, halfway down the tree. If this item has children, my problem occurs...

Thanks for your reaction,

jeroen.
0
 
LVL 1

Accepted Solution

by:
Gabor earned 300 total points
ID: 1337993
I have found what you want.

1. To avoid to show submenus make all subitems' Visible property to FALSE at initialization.

2. You can use the OnClick event to handle selections.

This is not enought for you, because you want to handle mouse-button event too.
You can determine if the OnClick event is occured by the left button with using GetAsyncKeyState API function:

{OnClick event}
...
if GetAsyncKeyState(VK_LBUTTON)<0 then begin
  {you can do everithing you want, for example make subitems' Visible property to true}
end;
...

It works, I have tried it.

Good luck!

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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