Results 1 to 17 of 17

Thread: Mouse Co-ordinates Over Menu!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Mouse Co-ordinates Over Menu!

    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?

  2. #2
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Mouse Co-ordinates Over Menu!

    Just an idea:

    VB Code:
    1. Private Sub picDraw_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     StatusBar1.Panels(2).Text = "X,Y Coordinate (Meters) =  " & X & " , " & Y
    3. 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

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Mouse Co-ordinates Over Menu!

    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!

  4. #4
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Mouse Co-ordinates Over Menu!

    Sorry I misunderstood arpan_de's question. Well in that case, I wonder how that can be done too

  5. #5
    New Member < Sal >'s Avatar
    Join Date
    Oct 2009
    Location
    Sydney, Australia
    Posts
    6

    Question Re: Mouse Co-ordinates Over Menu!

    Can somebody help us to stop wondering?!?!?!
    Coming Soon!
    Coming to a VBForum near you!!
    27/11/2009
    DD/MM/YYYY

  6. #6
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    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.

    http://msdn.microsoft.com/en-us/libr...52(VS.85).aspx
    Last edited by Jim Davis; Oct 21st, 2009 at 09:30 PM.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Mouse Co-ordinates Over Menu!

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Mouse Co-ordinates Over Menu!

    Quote Originally Posted by Jim Davis View Post
    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
    WM_MENUSELECT will tell you which menu item was clicked.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Mouse Co-ordinates Over Menu!

    Quote Originally Posted by < Sal > View Post
    Can somebody help us to stop wondering?!?!?!
    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.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Mouse Co-ordinates Over Menu!

    Quote Originally Posted by RobDog888 View Post
    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.
    Attached Files Attached Files
    Last edited by Jim Davis; Oct 22nd, 2009 at 11:14 AM.

  11. #11
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    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?
    Attached Images Attached Images  

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Mouse Co-ordinates Over Menu!

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Mouse Co-ordinates Over 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?

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Mouse Co-ordinates Over Menu!

    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"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Mouse Co-ordinates Over Menu!


  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Mouse Co-ordinates Over Menu!

    Quote Originally Posted by Jim Davis View Post
    I do believe that is a good starting point for anyone that wants to customize menus and keep them themed.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width