Results 1 to 7 of 7

Thread: Why is this not working? (GetSubMenu)

  1. #1

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Question Why is this not working? (GetSubMenu)

    Hi guys, I want to be able to get the menu and its submenu rectangles. I tried the code below but without success. I use “WindowFromPoint” to get the handle of the window that the mouse is on and use the “GetSubMenu” function to get the menu’s activated submenu. I successfully can retrieve the menu handle by using “WidowFromPoint” but the “GetSubMenu” function returns zero. Can some one take a look on this and tell what I am doing wrong. Thanks in advance.
    vb Code:
    1. Imports System.runtime.InteropServices
    2.  
    3. Public Class Form1
    4.  
    5.     Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As IntPtr, ByVal nPos As Integer) As IntPtr
    6.  
    7.     <DllImport("user32", EntryPoint:="WindowFromPoint")> _
    8.         Public Shared Function WindowFromPoint(ByVal xPoint As Integer, _
    9.         ByVal yPoint As Integer) As IntPtr
    10.     End Function
    11.  
    12.    End Class
    I call the functions in the keydown event.
    vb Code:
    1. Dim hwind As IntPtr = WindowFromPoint(Control.MousePosition.X, Control.MousePosition.Y) ' <-- returns the menu handl
    2. Console.WriteLine("Menu " & hwind.ToString)
    3. Dim hsubMenu As IntPtr = GetSubMenu(hwind, 0) ' <-- returns 0
    4. Console.WriteLine("SubMenu " & hsubMenu.ToString)

  2. #2
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Why is this not working? (GetSubMenu)

    Because menu handle are not windows handles
    You use something like this:
    1. Find the window with WindowFromPoint
    2. Use that handle and get its menu handle with GetMenu.
    3. Once all the handles are correct and if you want a specific sub menu item, use GetSubMenu...

    BTW: You sould use msdn to see the correct param values

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  3. #3

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Why is this not working? (GetSubMenu)

    I am sorry but can you be more specific. I am sure that WindowFromPoint function returns the menu or the container of the menu handle because when I call the GetWindowRect function I get the menu’s rectangle.

  4. #4

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Why is this not working? (GetSubMenu)

    Quote Originally Posted by Kal-El
    Because menu handle are not windows handles
    You use something like this:
    1. Find the window with WindowFromPoint
    2. Use that handle and get its menu handle with GetMenu.
    3. Once all the handles are correct and if you want a specific sub menu item, use GetSubMenu...

    BTW: You sould use msdn to see the correct param values
    I also did that but GetMenu function returns zero.

  5. #5
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Why is this not working? (GetSubMenu)

    Quote Originally Posted by VBDT
    I am sorry but can you be more specific. I am sure that WindowFromPoint function returns the menu or the container of the menu handle because when I call the GetWindowRect function I get the menu’s rectangle.
    No sir, see msdn, only retrieves a handle to the window, no menus. And you getting error zero, because you are using invalid handle values for each API function. To get rectangles or boundies, you can also see GetMenuItemRect.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  6. #6

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Why is this not working? (GetSubMenu)

    I am already using the WindowFromPoint function to retrive the rectangle of the menu and it works. The msdn doesn't say that it doesn't return menu handle. I am not saing that the handle it returns is menu hadle but it might be menu's container handle.
    I don't want menuItemRectangle i want the menu and its submenu rectangles.

  7. #7

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Why is this not working? (GetSubMenu)

    Sorry for the confusion, I mean shortcut menu. The menu that when you right click on a window or the desktop and it pops up.

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