-
January 19th, 2008, 03:51 AM
#1
GetMenuItemInfo SetMenuItemInfo
GetMenuItemInfo Retrieves information about a menu item.
Code:
Const MFS_ENABLED As Int32 = &H0
Const MFS_GRAYED As Int32 = &H3
Const MIIM_STATE As Int32 = &H1
Public Structure MENUITEMINFO
Public cbSize, fMask, fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData, cch As Int32, dwTypeData As String
End Structure
Private Declare Function apiGetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Int32, ByVal un As Int32, ByVal b As Boolean, ByRef lpMenuItemInfo As MENUITEMINFO) As Int32
Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
Private Declare Function apiGetMenu Lib "user32" Alias "GetMenu" (ByVal hWnd As Int32) As Int32
Private Declare Function apiGetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hWnd As Int32 = apiFindWindow(Nothing, "Form1")
Dim hMenu As Int32 = apiGetMenu(hWnd) 'You must add a mainmenu to your toolbox first(2005->).
Dim hSubMenu As Int32 = apiGetSubMenu(hMenu, 0)
Dim mItem As New MENUITEMINFO
mItem.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(mItem)
mItem.fMask = MIIM_STATE
If apiGetMenuItemInfo(hSubMenu, 0, True, mItem) <> 0 Then 'if ret is non-zero, then function succeeded
If mItem.fState = MFS_GRAYED Then
MessageBox.Show("Menu item is disabled")
ElseIf mItem.fState = MFS_ENABLED Then
MessageBox.Show("Menu item is enabled")
End If
Else
MessageBox.Show("Menu item not found")
End If
End Sub
SetMenuItemInfo changes information about a menu item.
Code:
Const MIIM_STATE As Int32 = 1
Const MFS_ENABLED As Int32 = 0
Const MFS_GRAYED As Int32 = 3
Private Structure MENUITEMINFO
Public cbSize, fMask, fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData As Int32, dwTypeData As String, cch As Int32
End Structure
Private Declare Function apiGetMenu Lib "user32" Alias "GetMenu" (ByVal hWnd As Int32) As Int32
Private Declare Function apiGetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
Private Declare Function apiSetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Int32, ByVal uItem As Int32, ByVal fByPosition As Int32, ByRef lpmii As MENUITEMINFO) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hMenu As Int32 = apiGetMenu(Me.Handle.ToInt32)
Dim hSubMenu As Int32 = apiGetSubMenu(hMenu, 0)
Dim mItem As New MENUITEMINFO
mItem.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(mItem)
mItem.fMask = MIIM_STATE
mItem.fState = MFS_GRAYED
apiSetMenuItemInfo(hSubMenu, 0, True, mItem)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|