Link to home
Start Free TrialLog in
Avatar of jmstolting
jmstolting

asked on

OnMouseDown in TPopupMenu

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)
Avatar of jmstolting
jmstolting

ASKER

Adjusted points to 200
You will need to capture the WM_MenuSelect message.
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

Adjusted points to 301
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Gabor
Gabor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial