Results 1 to 7 of 7

Thread: How to change the color of Menu Bar

  1. #1

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    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

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  3. #3

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    Re: How to change the color of Menu Bar

    From where I can find this owner drawn menu bar.......?

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: How to change the color of Menu Bar

    Try this
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type MENUINFO
    4.     cbSize As Long
    5.     fMask As Long
    6.     dwStyle As Long
    7.     cyMax As Long
    8.     hbrBack As Long
    9.     dwContextHelpID As Long
    10.     dwMenuData As Long
    11. End Type
    12.  
    13. Private Declare Function DrawMenuBar Lib "user32" _
    14.     (ByVal hwnd As Long) As Long
    15.  
    16. Private Declare Function GetMenu Lib "user32" _
    17.     (ByVal hwnd As Long) As Long
    18.  
    19. Private Declare Function GetSystemMenu Lib "user32" _
    20.     (ByVal hwnd As Long, _
    21.     ByVal bRevert As Long) As Long
    22.  
    23. Private Declare Function SetMenuInfo Lib "user32" _
    24.     (ByVal hmenu As Long, _
    25.     mi As MENUINFO) As Long
    26.  
    27. Private Declare Function CreateSolidBrush Lib "gdi32" _
    28.     (ByVal crColor As Long) As Long
    29.  
    30. Private Declare Function OleTranslateColor Lib "olepro32.dll" _
    31.     (ByVal OLE_COLOR As Long, _
    32.     ByVal HPALETTE As Long, _
    33.     pccolorref As Long) As Long
    34.  
    35. Private Const MIM_BACKGROUND As Long = &H2
    36. Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
    37.  
    38. Private Function SetMenuColour(ByVal hwndfrm As Long, _
    39.         ByVal dwColour As Long, _
    40.         ByVal bIncludeSubmenus As Boolean) As Boolean
    41.    
    42.     'set application menu colour
    43.     Dim mi As MENUINFO
    44.     Dim flags As Long
    45.     Dim clrref As Long
    46.    
    47.     'convert a Windows colour (OLE colour)
    48.     'to a valid RGB colour if required
    49.     clrref = TranslateOLEtoRBG(dwColour)
    50.    
    51.     'we're changing the background,
    52.     'so at a minimum set this flag
    53.     flags = MIM_BACKGROUND
    54.    
    55.     If bIncludeSubmenus Then
    56.         'MIM_BACKGROUND only changes
    57.         'the back colour of the main
    58.         'menu bar, unless this flag is set
    59.         flags = flags Or MIM_APPLYTOSUBMENUS
    60.     End If
    61.    
    62.     'fill in struct, assign to menu,
    63.     'and force a redraw with the
    64.     'new attributes
    65.     With mi
    66.         .cbSize = Len(mi)
    67.         .fMask = flags
    68.         .hbrBack = CreateSolidBrush(clrref)
    69.     End With
    70.    
    71.     SetMenuInfo GetMenu(hwndfrm), mi
    72.     DrawMenuBar hwndfrm
    73.    
    74. End Function
    75.  
    76. Private Function TranslateOLEtoRBG(ByVal dwOleColour As Long) As Long
    77.     OleTranslateColor dwOleColour, 0, TranslateOLEtoRBG
    78. End Function
    79.  
    80. Private Sub Form_Load()
    81.     'Change RGB(180, 210, 240) to the color you want
    82.     Call SetMenuColour(Me.hwnd, RGB(180, 210, 240), True)
    83. End Sub

  5. #5

    Thread Starter
    Member jalzaaal's Avatar
    Join Date
    Feb 2005
    Posts
    63

    Re: How to change the color of Menu Bar

    Quote Originally Posted by jcis
    Try this
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type MENUINFO
    4.     cbSize As Long
    5.     fMask As Long
    6.     dwStyle As Long
    7.     cyMax As Long
    8.     hbrBack As Long
    9.     dwContextHelpID As Long
    10.     dwMenuData As Long
    11. End Type
    12.  
    13. Private Declare Function DrawMenuBar Lib "user32" _
    14.     (ByVal hwnd As Long) As Long
    15.  
    16. Private Declare Function GetMenu Lib "user32" _
    17.     (ByVal hwnd As Long) As Long
    18.  
    19. Private Declare Function GetSystemMenu Lib "user32" _
    20.     (ByVal hwnd As Long, _
    21.     ByVal bRevert As Long) As Long
    22.  
    23. Private Declare Function SetMenuInfo Lib "user32" _
    24.     (ByVal hmenu As Long, _
    25.     mi As MENUINFO) As Long
    26.  
    27. Private Declare Function CreateSolidBrush Lib "gdi32" _
    28.     (ByVal crColor As Long) As Long
    29.  
    30. Private Declare Function OleTranslateColor Lib "olepro32.dll" _
    31.     (ByVal OLE_COLOR As Long, _
    32.     ByVal HPALETTE As Long, _
    33.     pccolorref As Long) As Long
    34.  
    35. Private Const MIM_BACKGROUND As Long = &H2
    36. Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
    37.  
    38. Private Function SetMenuColour(ByVal hwndfrm As Long, _
    39.         ByVal dwColour As Long, _
    40.         ByVal bIncludeSubmenus As Boolean) As Boolean
    41.    
    42.     'set application menu colour
    43.     Dim mi As MENUINFO
    44.     Dim flags As Long
    45.     Dim clrref As Long
    46.    
    47.     'convert a Windows colour (OLE colour)
    48.     'to a valid RGB colour if required
    49.     clrref = TranslateOLEtoRBG(dwColour)
    50.    
    51.     'we're changing the background,
    52.     'so at a minimum set this flag
    53.     flags = MIM_BACKGROUND
    54.    
    55.     If bIncludeSubmenus Then
    56.         'MIM_BACKGROUND only changes
    57.         'the back colour of the main
    58.         'menu bar, unless this flag is set
    59.         flags = flags Or MIM_APPLYTOSUBMENUS
    60.     End If
    61.    
    62.     'fill in struct, assign to menu,
    63.     'and force a redraw with the
    64.     'new attributes
    65.     With mi
    66.         .cbSize = Len(mi)
    67.         .fMask = flags
    68.         .hbrBack = CreateSolidBrush(clrref)
    69.     End With
    70.    
    71.     SetMenuInfo GetMenu(hwndfrm), mi
    72.     DrawMenuBar hwndfrm
    73.    
    74. End Function
    75.  
    76. Private Function TranslateOLEtoRBG(ByVal dwOleColour As Long) As Long
    77.     OleTranslateColor dwOleColour, 0, TranslateOLEtoRBG
    78. End Function
    79.  
    80. Private Sub Form_Load()
    81.     'Change RGB(180, 210, 240) to the color you want
    82.     Call SetMenuColour(Me.hwnd, RGB(180, 210, 240), True)
    83. End Sub
    Yeah!!! It is Working Fantastic..!! Thank You So Much Mr.Jcis.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  7. #7
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    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
  •  



Click Here to Expand Forum to Full Width