home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Tool Box
/
SIMS_2.iso
/
code
/
design
/
menuon
/
mnuenabl.txt
< prev
next >
Wrap
Text File
|
1995-02-26
|
2KB
|
45 lines
Declare Function GetMenu Lib "User" (ByVal Hwnd As Integer) As Integer
Declare Sub DrawMenuBar Lib "User" (ByVal Hwnd As Integer)
Declare Function EnableMenuItem Lib "User" (ByVal hMenu As Integer, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
Declare Function GetMenuItemCount Lib "User" (ByVal hMenu As Integer) As Integer
Const MF_BYPOSITION = &H400
Const MF_ENABLED = &H0
Const MF_GRAYED = &H1
Sub MenuEnable (FormHandle%, Enable%)
'
' Enable/Disable Form's Menu Bar Items
'
' FormHandle% is the Handle of the VB Form Containing the
' Menu to be Enabled or Disabled
'
' Obtain by FormHandle%=MainForm.Hwnd
'
' Enable% is TRUE (-1) if the Menu Bar is to be Enabled,
' or FALSE (0) if the Menu Bar is to be Disabled
'
' Example: To Disable Menu Bar on Form FirstForm:
'
' MenuEnable (FirstForm.Hwnd), FALSE
'
'
MenuHandle% = GetMenu(FormHandle%) 'Get Menu Bar Handle
''' Build Enable/Disable Flags
If Enable% Then
i% = MF_ENABLED Or MF_BYPOSITION 'Enable Menu Items
Else
i% = MF_GRAYED Or MF_BYPOSITION 'Disable Menu Items
End If
''' Loop Thru Menu Items, Enabling/Disabling Them
For j% = 0 To GetMenuItemCount(MenuHandle%) - 1 'Loop Thru all Menu Items
k% = EnableMenuItem(MenuHandle%, j%, i%) 'Enable or Disable an Item
Next j%
DrawMenuBar FormHandle% 'Redraw Bar on ENABLE
End Sub