PDA

Click to See Complete Forum and Search --> : How 2 disable menu items on other application?


Artem
Nov 1st, 2000, 07:14 PM
Greetz.
I am trying to find a way how to disable some of the menu items on other applications. Is it possible? Is there a way to re-enable them again?

gwdash
Nov 1st, 2000, 08:38 PM
Try this, didn't test


Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Public Const MF_DISABLED = &H2&
Public Const MF_ENABLED = &H0&

Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim hMenu As Long, hSubMenu As Long, lngID As Long
Dim hWnd As Long 'handle to the window you want to change
'Get the handle of the form's menu
hMenu = GetMenu(hWnd)
'Get the handle of the form's submenu
hSubMenu = GetSubMenu(hMenu, 0)

'Change first item (index=0)
'to disable
lngID = GetMenuItemID(hSubMenu, 0)
Call ModifyMenu(hMenu, lngID, MF_DISABLED, lngID, CLng(0))

'to enable
lngID = GetMenuItemID(hSubMenu, 0)
Call ModifyMenu(hMenu, lngID, MF_ENABLED, lngID, CLng(0))
End Sub