[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Visual Basic Menu Bar Colour Change

Posted on 2004-07-30
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 53

Accepted Solution

Ryan Chong earned 500 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

Author Comment

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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

649 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