Solved

OnMouseDown in TPopupMenu

Posted on 1997-06-30
7
382 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
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!

 

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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 121
LAN or WAN ? 11 106
Delphi inherited method 6 80
Delphi Firemonkey : user drawing in window 3 28
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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