PDA

Click to See Complete Forum and Search --> : Clicking and Disabling Menus


Rh0ads
Mar 24th, 2001, 08:20 AM
How do i click a menu in another application using API, and how do i disable a sub menu like:

File-
--Open
--Save


how would i go about disabling the open menu? Thanks

gwdash
Mar 24th, 2001, 03:38 PM
you will have to send the WM_COMMAND message. don't have the exact code now, have seen it on the forum, but search is disabled :(

To disable menuitems


Private Const MIIM_SUBMENU = &H4
Private Const MIIM_STATE = &H1
Private Const MFS_GRAYED = &H1
Private Const MFS_ENABLED = &H0


Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, lpmii As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Long, lpmii As MENUITEMINFO) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Private Sub SetEnabled(bEnabled As Boolean, hWnd As Long, index As Integer)

Dim hMenu As Long, hSubMenu As Long, MII As MENUITEMINFO
'get the handle of the current menu
hMenu = GetMenu(hWnd)
'get the handle of the first submenu
hSubMenu = GetSubMenu(hMenu, index)
'initialize the structure

MII.cbSize = Len(MII)

MII.fMask = MIIM_STATE 'state mask
If bEnabled Then
MII.fState = MFS_ENABLED
Else
MII.fState = MFS_GRAYED 'gray menu item
End If
SetMenuItemInfo hSubMenu, 0, True, MII
End Sub

mmr93
Oct 18th, 2002, 12:56 PM
How would you go about disabling the "Save" submenu item?