|
-
Jan 24th, 2006, 08:59 AM
#1
Thread Starter
Member
How to change the color of Menu Bar
Hi,
Can any one tell me how can I change the color of the menubar?
I want to make it blue...
Please Help
-
Jan 24th, 2006, 09:25 AM
#2
Re: How to change the color of Menu Bar
The only way is to owner-draw the menubar and it is a rather complicated stuff which takes weeks of development to handle and make work well. Although something that simple might be slightly easier. If still interested, you can find more information by searching for owner-drawn menus.
-
Jan 24th, 2006, 09:29 AM
#3
Thread Starter
Member
Re: How to change the color of Menu Bar
From where I can find this owner drawn menu bar.......?
-
Jan 24th, 2006, 09:47 AM
#4
Re: How to change the color of Menu Bar
Try this
VB Code:
Option Explicit
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 Type
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert 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 Long
Private Declare Function OleTranslateColor Lib "olepro32.dll" _
(ByVal OLE_COLOR As Long, _
ByVal HPALETTE As Long, _
pccolorref As Long) As Long
Private Const MIM_BACKGROUND As Long = &H2
Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
Private Function SetMenuColour(ByVal hwndfrm As Long, _
ByVal dwColour As Long, _
ByVal bIncludeSubmenus As Boolean) As Boolean
'set application menu colour
Dim mi As MENUINFO
Dim flags As Long
Dim clrref As Long
'convert a Windows colour (OLE colour)
'to a valid RGB colour if required
clrref = TranslateOLEtoRBG(dwColour)
'we're changing the background,
'so at a minimum set this flag
flags = MIM_BACKGROUND
If bIncludeSubmenus Then
'MIM_BACKGROUND only changes
'the back colour of the main
'menu bar, unless this flag is set
flags = flags Or MIM_APPLYTOSUBMENUS
End If
'fill in struct, assign to menu,
'and force a redraw with the
'new attributes
With mi
.cbSize = Len(mi)
.fMask = flags
.hbrBack = CreateSolidBrush(clrref)
End With
SetMenuInfo GetMenu(hwndfrm), mi
DrawMenuBar hwndfrm
End Function
Private Function TranslateOLEtoRBG(ByVal dwOleColour As Long) As Long
OleTranslateColor dwOleColour, 0, TranslateOLEtoRBG
End Function
Private Sub Form_Load()
'Change RGB(180, 210, 240) to the color you want
Call SetMenuColour(Me.hwnd, RGB(180, 210, 240), True)
End Sub
-
Jan 25th, 2006, 09:19 AM
#5
Thread Starter
Member
Re: How to change the color of Menu Bar
 Originally Posted by jcis
Try this
VB Code:
Option Explicit
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 Type
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenu Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert 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 Long
Private Declare Function OleTranslateColor Lib "olepro32.dll" _
(ByVal OLE_COLOR As Long, _
ByVal HPALETTE As Long, _
pccolorref As Long) As Long
Private Const MIM_BACKGROUND As Long = &H2
Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
Private Function SetMenuColour(ByVal hwndfrm As Long, _
ByVal dwColour As Long, _
ByVal bIncludeSubmenus As Boolean) As Boolean
'set application menu colour
Dim mi As MENUINFO
Dim flags As Long
Dim clrref As Long
'convert a Windows colour (OLE colour)
'to a valid RGB colour if required
clrref = TranslateOLEtoRBG(dwColour)
'we're changing the background,
'so at a minimum set this flag
flags = MIM_BACKGROUND
If bIncludeSubmenus Then
'MIM_BACKGROUND only changes
'the back colour of the main
'menu bar, unless this flag is set
flags = flags Or MIM_APPLYTOSUBMENUS
End If
'fill in struct, assign to menu,
'and force a redraw with the
'new attributes
With mi
.cbSize = Len(mi)
.fMask = flags
.hbrBack = CreateSolidBrush(clrref)
End With
SetMenuInfo GetMenu(hwndfrm), mi
DrawMenuBar hwndfrm
End Function
Private Function TranslateOLEtoRBG(ByVal dwOleColour As Long) As Long
OleTranslateColor dwOleColour, 0, TranslateOLEtoRBG
End Function
Private Sub Form_Load()
'Change RGB(180, 210, 240) to the color you want
Call SetMenuColour(Me.hwnd, RGB(180, 210, 240), True)
End Sub
Yeah!!! It is Working Fantastic..!! Thank You So Much Mr.Jcis.
-
Jan 25th, 2006, 09:28 AM
#6
Re: How to change the color of Menu Bar
If this is resolved, please pull down the Thread Tools menu and click the Mark Thread Resolved button. That will let everyone know that you have your answer.
Thank you.
-
Jan 25th, 2006, 10:37 AM
#7
Addicted Member
Re: How to change the color of Menu Bar
Nice one Jcis, I was also wondering if this was possible
Works well
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
|