home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / design / menuon / mnuenabl.txt < prev    next >
Text File  |  1995-02-26  |  2KB  |  45 lines

  1. Declare Function GetMenu Lib "User" (ByVal Hwnd As Integer) As Integer
  2. Declare Sub DrawMenuBar Lib "User" (ByVal Hwnd As Integer)
  3. Declare Function EnableMenuItem Lib "User" (ByVal hMenu As Integer, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
  4. Declare Function GetMenuItemCount Lib "User" (ByVal hMenu As Integer) As Integer
  5.  
  6. Const MF_BYPOSITION = &H400
  7. Const MF_ENABLED = &H0
  8. Const MF_GRAYED = &H1
  9.  
  10. Sub MenuEnable (FormHandle%, Enable%)
  11. '
  12. '  Enable/Disable Form's Menu Bar Items
  13. '
  14. '     FormHandle%   is the Handle of the VB Form Containing the
  15. '                   Menu to be Enabled or Disabled
  16. '
  17. '                   Obtain by FormHandle%=MainForm.Hwnd
  18. '
  19. '     Enable%       is TRUE (-1) if the Menu Bar is to be Enabled,
  20. '                   or FALSE (0) if the Menu Bar is to be Disabled
  21. '
  22. '  Example:  To Disable Menu Bar on Form FirstForm:
  23. '
  24. '                   MenuEnable (FirstForm.Hwnd), FALSE
  25. '
  26. '
  27.  
  28. MenuHandle% = GetMenu(FormHandle%)              'Get Menu Bar Handle
  29. ''' Build Enable/Disable Flags
  30. If Enable% Then
  31.   i% = MF_ENABLED Or MF_BYPOSITION              'Enable Menu Items
  32. Else
  33.   i% = MF_GRAYED Or MF_BYPOSITION               'Disable Menu Items
  34.   End If
  35.  
  36. ''' Loop Thru Menu Items, Enabling/Disabling Them
  37. For j% = 0 To GetMenuItemCount(MenuHandle%) - 1 'Loop Thru all Menu Items
  38.   k% = EnableMenuItem(MenuHandle%, j%, i%)      'Enable or Disable an Item
  39.   Next j%
  40.  
  41. DrawMenuBar FormHandle%         'Redraw Bar on ENABLE
  42.  
  43. End Sub
  44.  
  45.