Results 1 to 4 of 4

Thread: Grey out menu items....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2000
    Location
    Isle of Man
    Posts
    276

    Question

    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?

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Guest
    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

  4. #4
    New Member
    Join Date
    Nov 2002
    Posts
    1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width