This might be a simple question, but I haven't succeeded with it:
What I would like to do is to check which mouse button that's
been pressed when the OnClick event occurs within the TMenuItem
a TPopupMenu.
What I would like to do is to do the default handling if the left button was
pressed, and to do some other handling if the right button was pressed on
the
item. (Show another popup menu).
How can this be possible, I have tried to catch the WM_LBUTTONDOWN and
WM_RBUTTONDOWN events, but they doesn't get's invokend once the
popup menu is visible.
Regards and thanks in advance,
Mikael Stalvik
It is not at all simple.
> What I would like to do is to check which mouse button that's
> been pressed when the OnClick event occurs within the TMenuItem
> a TPopupMenu.
There is a new message WM_MENURBUTTONUP in Win2k/Win98 and up that is send to
the menus owner window. The problem is that for a popup menu the owner window
is not the form, it is a tool window created by the Menus unit internally.
Since D5 it is possible to get access to this internal window by replacing the
TPopuplist instance the Menus unit creates with a custom derivative.
Search the newsgroup archives (URLs in signature) for ExPopupList, that will
turn up a unit that does this replacement. You will need to add handling of
the WM_MENURBUTTONUP message to it. You can also use the WM_MENUSELECT message
in connection with GetKEyState to figure out which mouse button was used to
select a menu item:
If (Message.MenuFlag <> $FFFF) and (Message.Menu <> 0) Then
If (Message.MenuFlag AND MF_MOUSESELECT) <> 0 Then Begin
If GetKeyState( VK_RBUTTON ) < 0 Then
FMouseButton := mbRight
Else If GetKeyState( VK_LBUTTON ) < 0 Then
FMouseButton := mbLeft;
End
Else
FMouseButton := mbNone;
In this example FMouseButton is of this type:
TMouseButton = (mbNone, mbLeft, mbRight );
Note that for a main menu (for which all these messages go to the form) a
right click will not close the menu or fire the OnClick event of an item.
--
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Regards,
Mikael Stalvik
"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.000080d...@antispam.compuserve.com...
> Search the newsgroup archives (URLs in signature) for ExPopupList, that
will
> turn up a unit that does this replacement.
How can I do that?
Any help is appreciated.
Regards,
Mikael Stalvik
The URLs in the posts signature get you to websites that have search
engines. Just use those and you will be rewarded with newsgroup posts that
these sites archive.
Regards,
Mikael
"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.000080e...@antispam.compuserve.com...
I hope that I don't disturb you too much, but...
I added the ExPopupList unit succesfully to my project, and
it responds to the WM_MENUSELECT. It doesn't happen anything at all
when I implemented support for the WM_MENURBUTTONUP message.
Anyway, there's still a problem. Whenever I click a menu item in the popup
menu,
the popuplist always execute the else condition, FMouseButton := mbNone;
So the problem remains. :-|
Oh, Btw. using D6, Win2000.
Regards and thanks,
Mikael Stalvik
On other hand, you can use a third-party software that has
events like OnMouseDown and OnMouseUp.
If you have more questions, feel free to contact us.
Sincerely, Andrew Cher.
**********************************************
We took the best from Mac OS X, Windows XP, and .NET
We named it Animated Menus 3.0. We love it.
Now you can love it, too.
**********************************************
For more information visit us today on the Web:
http://www.animatedmenus.com/
**********************************************
"Mikael Stalvik" <mikael....@telia.com> wrote in message
news:3c40daea_2@dnews...
Mh, yes, the MSDN docs indicate that one needs to pass a specific flag in the
TrackPopupMenuEx call that shows the menu to get these messages.
> Anyway, there's still a problem. Whenever I click a menu item in the popup
> menu,the popuplist always execute the else condition,
> FMouseButton := mbNone;
Pity. You may have to fall back on the solution proposed by Andrew Cher:
install a thread-specific WH_GETMESSAGE hook when you get WM_ENTERMENULOOP,
remove it on WM_EXITMENULOOP. The hook will see all mouse and keyboard
messages even if they are not passed on to you app otherwise. The question is:
is this all really worth the trouble?
No, probably not... Hmm... But, I need a working solution to
invoke a popupmenu on a menu item..
Any other ideas?
Thanks for all help and effort (so far :)),
Regards,
Mikael Stalvik
Another idea: you can make a submenu (instead of a plain
item) and include into that submenu all options you needed
in context menu. Even more beautiful.
A.
/Mikael
"Andrew Cher" <Andre...@AnimatedMenus.comNOSPAM> wrote in message
news:3c440edd_2@dnews...