Visual Basic Menu Bar Colour Change

Posted on 2004-07-30
Last Modified: 2013-11-25

  Have another small problem, it is how to change the menubar's back color, font size and font style in Visual Basic 6

Thank You for all your answers and support

Question by:bkniazi
  • 2
LVL 49

Accepted Solution

Ryan Chong earned 125 total points
ID: 11674863
Here is an example from web to change menu color:

In a Public Module, add:

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 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

Public 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
   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

Public Function SetSysMenuColour(ByVal hwndfrm As Long, _
                                  ByVal dwColour As Long) As Boolean

  'set system menu colour
   Dim mi As MENUINFO
   Dim hSysMenu As Long
   Dim clrref As Long

  'convert a Windows colour (OLE colour)
  'to a valid RGB colour if required
   clrref = TranslateOLEtoRBG(dwColour)

  'get handle to the system menu,
  'fill in struct, assign to menu,
  'and force a redraw with the
  'new attributes
   hSysMenu = GetSystemMenu(hwndfrm, False)
   With mi
      .cbSize = Len(mi)
      .hbrBack = CreateSolidBrush(clrref)
   End With

   SetMenuInfo hSysMenu, mi
   DrawMenuBar hSysMenu
End Function

Private Function TranslateOLEtoRBG(ByVal dwOleColour As Long) As Long
  'check to see if the passed colour
  'value is and OLE or RGB colour, and
  'if an OLE colour, translate it to
  'a valid RGB color and return. If the
  'colour is already a valid RGB colour,
  'the function returns the colour without
   OleTranslateColor dwOleColour, 0, TranslateOLEtoRBG
End Function

then in your Form_Load Event, try add like:

Private Sub Form_Load()
    SetMenuColour Me.hWnd, &HD9F2F7, True
End Sub
LVL 49

Expert Comment

by:Ryan Chong
ID: 11674867

Author Comment

ID: 11674875
Thanks alot i will look at these and get back to you if i need further help

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now