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.
I call the functions in the keydown event.vb Code:
Imports System.runtime.InteropServices Public Class Form1 Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As IntPtr, ByVal nPos As Integer) As IntPtr <DllImport("user32", EntryPoint:="WindowFromPoint")> _ Public Shared Function WindowFromPoint(ByVal xPoint As Integer, _ ByVal yPoint As Integer) As IntPtr End Function End Class
vb Code:
Dim hwind As IntPtr = WindowFromPoint(Control.MousePosition.X, Control.MousePosition.Y) ' <-- returns the menu handl Console.WriteLine("Menu " & hwind.ToString) Dim hsubMenu As IntPtr = GetSubMenu(hwind, 0) ' <-- returns 0 Console.WriteLine("SubMenu " & hsubMenu.ToString)




Reply With Quote