Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu Bar Color?

Status
Not open for further replies.

kovas

Technical User
Aug 6, 2002
88
US
How can I change the background color of the Menu Bar in VB?

thank you :)
 
I don't know if it helps you but have you had a look at the SetSysColors and GetSysColor API's
 
You may not want to look at GetSysColor/SetSysColors, as this would apply a global effect. But try the following (you'll need aform with a menu on it, obviously...):
[tt]
Option Explicit

Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush As LOGBRUSH) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long
Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, lpcmi As tagMENUINFO) As Long

Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type

Private Type tagMENUINFO
cbSize As Long
fMask As Long
dwStyle As Long
cyMax As Long
hbrBack As Long
dwContextHelpID As Long
dwMenuData As Long
End Type

Private Const BS_SOLID = 0
Private Const MIM_APPLYTOSUBMENUS = &H80000000
Private Const MIM_BACKGROUND = &H2

Private Sub Form_Load()
Dim ret As Long
Dim hMenu As Long
Dim hBrush As Long
Dim lbBrushInfo As LOGBRUSH
Dim miMenuInfo As tagMENUINFO

lbBrushInfo.lbStyle = BS_SOLID
lbBrushInfo.lbColor = RGB(155, 100, 200)
lbBrushInfo.lbHatch = 0
hBrush = CreateBrushIndirect(lbBrushInfo)

hMenu = GetMenu(Me.hwnd)

miMenuInfo.cbSize = Len(miMenuInfo)
ret = GetMenuInfo(hMenu, miMenuInfo) ' 0 means failure

miMenuInfo.fMask = MIM_BACKGROUND 'MIM_APPLYTOSUBMENUS use this to apply to submenus as well
miMenuInfo.hbrBack = hBrush
ret = SetMenuInfo(hMenu, miMenuInfo) '0 means failure

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top