說明:
GetMenu 函式可用來取得指定視窗的選單代碼
引用函式庫:
User32
適用系統:
Windows NT 3.1 或 Windows 95以上
函式原型:
Declare Function GetMenu Lib "user32" Alias "GetMenu" ( _ ByVal hwnd As Long _ ) As Long
參數型態及說明:
hwnd:Long 要取得選單代碼的視窗代碼(Handle)
回傳值:
Long 呼叫成功的話,將會回傳指定視窗的選單代碼;若呼叫失敗的話,則回傳 0
.NET Framework API:
System.Windows.Forms.Form.Menu.Handle
VB範例:
檢視原始碼 Visual Basic
1 2 3 4 5 6 7 8 9 | 'VB的宣告 Private Declare Function GetMenu Lib "user32" ( _ ByVal hwnd As Long _ ) As Long Dim hMenu As Long '取得目前執行視窗的選單代碼 hMenu = GetMenu(Form1.hwnd) |
RB範例:
檢視原始碼 REALBasic
1 2 3 4 5 6 7 8 9 | 'RB的宣告 Declare Function GetMenu Lib "user32" ( _ hwnd As Integer _ ) As Integer Dim hMenu As Integer '取得目前執行視窗的選單代碼 hMenu = GetMenu(Window1.WinHWND) |
VB.NET範例:
檢視原始碼 VB.NET
1 2 3 4 5 6 7 8 9 10 11 | 'VB.NET的宣告 <DllImport("user32.dll")> _ Shared Function GetMenu( _ ByVal hwnd As IntPtr _ ) As IntPtr End Function Dim hMenu As IntPtr '取得目前執行視窗的選單代碼 hMenu = GetMenu(Me.Handle) |
C#範例:
檢視原始碼 C#
1 2 3 4 5 6 7 8 9 10 | //C#的宣告 [DllImport("user32")] public static extern IntPtr GetMenu( IntPtr hwnd ); IntPtr hMenu; //取得目前執行視窗的選單代碼 hMenu = GetMenu(this.Handle); |
註釋:
在 .NET 中的選單若是使用 MenuStrip 的話,並無法透過 GetMenu 函式來取得選單代碼;但若是選單是用 MainMenu 的話,則可順利取得。