Asked by:
How to change the color of one menu item

Question
-
I have the code that once you click on the button it changes the color of the main menu or sub menu. Does anyone know if tt's possible to change the color of a specific one menu ?
Private Const MIM_BACKGROUND As Long = &H2
Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
Private Type MENUINFO
cbSize As Long
fMask As Long
dwStyle As Long
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End TypePrivate Declare Function DrawMenuBar 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 GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As LongPrivate Sub Command1_Click()
Dim mi As MENUINFO
With mi
.cbSize = Len(mi)
.fMask = MIM_BACKGROUND
.hbrBack = CreateSolidBrush(vbRed)
SetMenuInfo GetMenu(Me.hWnd), mi 'main menu bar
.fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
.hbrBack = CreateSolidBrush(vbCyan)
SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 0), mi 'File menu (item 0)
.hbrBack = CreateSolidBrush(vbBlue)
SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 1), mi 'Edit menu (item 1)
.hbrBack = CreateSolidBrush(vbRed)
SetMenuInfo GetSubMenu(GetMenu(Me.hWnd), 2), mi 'Select menu (item 2)
End With
DrawMenuBar Me.hWnd
End SubThanks
Mary
- Moved by Calvin_Gao Tuesday, February 8, 2011 2:48 AM VB6 is off topic (From:Visual Basic General)
Monday, January 31, 2011 2:58 PM
All replies
-
If you know the name of the menu, yu can directly access it
But if you don't know you can use the For Each... Next statement
Sameer ThigaleMonday, January 31, 2011 4:40 PM -
I know the name of the menu, but this line already setup the color of the main menu.
.hbrBack = CreateSolidBrush(vbBlue)
I want to just set 1 menu item blue.
Thanks
Monday, January 31, 2011 5:01 PM -
Hi MaryXin,
It looks like you are using VB6 or an earlier version.
This forum is usually intended for VB.Net questions.
Please see this thread.>>
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b
You may want to try this forum instead.>>
http://www.programmersheaven.com/mb/VBasic/Board.aspx
By the way you can get a FREE version of VB.NET here and it will not change your VB6 ( or earlier version setup )
as it installs to a separate folder. Give it a try, I think you will like it. :-)
Get it here.>>
http://www.microsoft.com/express/Downloads/
Regards,
John
Click this link to see how to insert a picture into a forum post.Monday, January 31, 2011 5:13 PM -
I agree with John, this seems to be a VB6 question.
Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.comMonday, January 31, 2011 5:35 PM