-
I'm trying to grey out the Restore menu item on a from's menu. I thought i should be able to do it something like this, but it's not working....
Code:
Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
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
Const MF_GRAYED = &H1
Dim hMenu As Long
Dim hID As Long
Dim hSubMenu As Long
hMenu = GetMenu(Current.hWnd)
hSubMenu = GetSubMenu(hMenu, 0)
hID = GetMenuItemID(hMenu, 0)
ModifyMenu hMenu, hID, MF_GRAYED, hSubMenu, "Restore"
but it doesnt work. hMenu (and consequently hSubMenu and hID ) all return 0.
Can someone tell me where i am going wrong?
-
Code:
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID 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
Private Const MF_GRAYED = &H1
Public Sub GrayMenu()
Dim hMenu&
Dim hID&
Dim hSubMenu&
hMenu = GetMenu(Me.hWnd)
hSubMenu = GetSubMenu(hMenu, 0)
hID = GetMenuItemID(hSubMenu, 0)
ModifyMenu hSubMenu, hID, MF_GRAYED, 0&, "GettheMenuTextBeforehand"
End Sub
Private Sub Command1_Click()
GrayMenu
End Sub
-
Code:
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID 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
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Const MF_GRAYED = &H1
Private Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
hMenu = GetSystemMenu(hwnd, 0)
ModifyMenu hMenu, 0, MF_BYPOSITION, MF_GRAYED, "Restore"
End Sub
-
This last answer is a good one, you can also use MF_BYCOMMAND
to make the job.
Unhappily it does not work anymore with Windows XP, and I would like to find a solution.
Thank you.