Solved

OnMouseDown in TPopupMenu

Posted on 1997-06-30
7
384 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
[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
  • 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
Industry Leaders: 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!

 

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

Technology Partners: 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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 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