How do I get the mouse position i.e. the X & Y co-ordinates when the mouse is moved over different menu items under a menu?
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
Good idea, but your code will only show the mouseposition, if the mouse is over the control picDraw (probably a PictureBox). If you move over the menu or even click on it, the displayed X and Y won't change!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
Mars base one Username: Jim Davis Password: yCrm33
Posts
1,284
Re: Mouse Co-ordinates Over Menu!
Why do you need those x and y coordinates. Probably you cant get them. But you might have luck to hook the menu items, and use the WM_MENUSELECT message, to determine what menu item is the mouse hovers on.
You may want to better use the MOUSEHOVER/MOVE messages if you want to get the x and y coordinates. Translate the lParam to get the actual x and y values. The WM_NCMOUSEHOVER/MOVE message is for when the mouse is over the menu bar or title bar. You can tell which by reading the wParam for HTMENU. Then when the mouse is over the actual menu items you would use WM_MOUSEHOVER/MOVE and also translate the lParam for x and y.
Why do you need those x and y coordinates. Probably you cant get them. But you might have luck to hook the menu items, and use the WM_MENUSELECT message, to determine what menu item is the mouse hovers on.
This is a 3+ year old thread so doubt the OP will reply. Still in case anyone wanted to know. KNow we know.
Ps, this assumes that the goal is to get the x and y coords from a menu on a form within our own application. If an external/3rd party window then you need to use Moers C++ dll to subclass external programs which can be found in VB6 CodeBank
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Mars base one Username: Jim Davis Password: yCrm33
Posts
1,284
Re: Mouse Co-ordinates Over Menu!
Originally Posted by RobDog888
WM_MENUSELECT will tell you which menu item was clicked.
I've been tested before i posted the tip, WM_MENUSELECT is generated each time you hover the mouse over a new menuitem. It even generates on disabled and menu hr lines. Well, at least it does under windows xp.
here is the most simple hook i've ever seen. brilliant code i've been added the menuselect message to be displayed in the immediate window.
Last edited by Jim Davis; Oct 22nd, 2009 at 11:14 AM.
Mars base one Username: Jim Davis Password: yCrm33
Posts
1,284
Re: Mouse Co-ordinates Over Menu!
the only problem regarding this code is that it is generates the old-fashioned menu for the root items, while the sub items will be rendered by new menu items under vista. is there any way to make the root items to be rendered by the new engine as well?
You may want to experiment a bit more. For example, what happens if you remove the MF_OWNERDRAW from this line, in the MenuPopUp routine?
AppendMenu hMenu, MF_OWNERDRAW Or MF_DISABLED, 1000, 0& 'SideBar
Does the root level still draw old-fashioned? Granted that the sidebar won't draw as expected, but curious whether not-owner drawing the menu, whether Vista will apply style to root level menu.
Insomnia is just a byproduct of, "It can't be done"
So, Vista does not directly support menubarbreaks? At least not with theming? I assume that not theming Vista would result in correct drawing.
Don't know the answer, didn't even know problem existed until today. One answer appears to be to ownerdraw the entire root level, using theming APIs similar to XP. However, I have not seen a listing, complete or otherwise, that identifies the "parts" and "values" used for Vista themes & objects (ie. menus, buttons, etc). XP theme parts & values are pretty well docuemented.
Edited: If interested in drawing with Vista themes and menus, this might prove useful. Look specifically at the "attachments" linked in the comments posted after the table.
Last edited by LaVolpe; Oct 22nd, 2009 at 12:50 PM.
Insomnia is just a byproduct of, "It can't be done"
Mars base one Username: Jim Davis Password: yCrm33
Posts
1,284
Re: Mouse Co-ordinates Over Menu!
Oh ok sorry, i've been missed the edited part of your post. I'll look further what the mozilla kb can help in this case. But it gives me hard time to understand these code sniplets. I'll post here any results, if i get any.