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?
Printable View
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?
Just an idea:
VB Code:
Private Sub picDraw_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "X,Y Coordinate (Meters) = " & X & " , " & Y End Sub
The starting x,y = 0,0 is always at the top left of the form or controls. So its up to you modifiy it :)
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!
Sorry I misunderstood arpan_de's question. Well in that case, I wonder how that can be done too:)
Can somebody help us to stop wondering?!?!?!
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.
http://msdn.microsoft.com/en-us/libr...52(VS.85).aspx
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.
WM_MOUSEHOVER:
http://msdn.microsoft.com/en-us/libr...13(VS.85).aspx
WM_MOUSEMOVE:
http://msdn.microsoft.com/en-us/libr...16(VS.85).aspx
WM_NCMOUSEHOVER:
http://msdn.microsoft.com/en-us/libr...25(VS.85).aspx
WM_NCMOUSEMOVE:
http://msdn.microsoft.com/en-us/libr...27(VS.85).aspx
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
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.
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.
Thanks for the OWNERDRAW tip. However it doesnt help by alone. i had to remove the Or MF_MENUBARBREAK too from the second line
AppendMenu hMenu, MF_POPUP Or MF_MENUBARBREAK, hSubmenu, "Menu Item1"
that is immediately let the menu to render as the new way. Too bad that the sidebar is absolutely gone :(
Is there any way to get the sidebar with the new fashioned menus?
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.
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.