|
-
Jun 18th, 2003, 07:16 AM
#1
Thread Starter
Addicted Member
Change colour of menu item
Hello,
In VB6 I have a normal form with a menu on it (created with the menu editor).
This works fine so no problem there.
What I want to do is change the colour of the text or background of a specific menu item (depending on some checks I perform)
So imagine I have the following menu structure:
<File><New><Blank>
Now if the user has no rights to create a new file, I want the <New> tag to have a red background colour or the text in red.
Invisible or disabled are not an option because the user must be able to click it anyway (he has to be prompted with a message or so after clicking an 'invalid' menu item)
How can I do this with a normal menu?
If ot is not possible, are there other components I can use?
Thanks for your time and your help!
Christophe
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Jun 18th, 2003, 07:34 AM
#2
Here you go!
VB Code:
Option Explicit
Private Enum MENUINFO_STYLES
MNS_NOCHECK = &H80000000
MNS_MODELESS = &H40000000
MNS_DRAGDROP = &H20000000
MNS_AUTODISMISS = &H10000000
MNS_NOTIFYBYPOS = &H8000000
MNS_CHECKORBMP = &H4000000
End Enum
Private Enum MENUINFO_MASKS
MIM_MAXHEIGHT = &H1
MIM_BACKGROUND = &H2
MIM_HELPID = &H4
MIM_MENUDATA = &H8
MIM_STYLE = &H10
MIM_APPLYTOSUBMENUS = &H80000000
End Enum
Private Type MENUINFO
cbSize As Long
fMask As MENUINFO_MASKS
dwStyle As MENUINFO_STYLES
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End Type
Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Sub Form_Load()
Dim MyMenu As MENUINFO
MyMenu.cbSize = Len(MyMenu)
MyMenu.fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
MyMenu.hbrBack = CreateSolidBrush(vbRed)
SetMenuInfo GetMenu(Me.hwnd), MyMenu
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Jun 18th, 2003, 08:04 AM
#3
Thread Starter
Addicted Member
Thanks!
But now my entire menu is in red 
How can you specify one specific item???
I do not have a specific statement...
so I will use one of my wife
Veni, Vidi, Visa ... I came, I saw, I shopped

-
Jun 18th, 2003, 10:12 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|