Results 1 to 7 of 7

Thread: Change the color of the menu bar,tool bar,status bar?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    51

    Change the color of the menu bar,tool bar,status bar?

    hi,i have a quick question:
    how can i change the color of the menu bar,status bar,tool bar
    to a custom color?

    another question: how can i control the close button in the
    control box (top right) ?

    thnx anyway
    FiDz

  2. #2
    Lively Member NuLLziLLa's Avatar
    Join Date
    Nov 2002
    Location
    USA
    Posts
    103
    Well for menu color, you can accompish it by using APIs. Try this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Enum MENUINFO_STYLES
    4.     MNS_NOCHECK = &H80000000
    5.     MNS_MODELESS = &H40000000
    6.     MNS_DRAGDROP = &H20000000
    7.     MNS_AUTODISMISS = &H10000000
    8.     MNS_NOTIFYBYPOS = &H8000000
    9.     MNS_CHECKORBMP = &H4000000
    10. End Enum
    11.  
    12. Private Enum MENUINFO_MASKS
    13.     MIM_MAXHEIGHT = &H1
    14.     MIM_BACKGROUND = &H2
    15.     MIM_HELPID = &H4
    16.     MIM_MENUDATA = &H8
    17.     MIM_STYLE = &H10
    18.     MIM_APPLYTOSUBMENUS = &H80000000
    19. End Enum
    20.  
    21. Private Type MENUINFO
    22.     cbSize As Long
    23.     fMask As MENUINFO_MASKS
    24.     dwStyle As MENUINFO_STYLES
    25.     cyMax As Long
    26.     hbrBack As Long
    27.     dwContextHelpID As Long
    28.     dwMenuData As Long
    29. End Type
    30.  
    31. Private Declare Function GetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
    32. Private Declare Function SetMenuInfo Lib "user32" (ByVal hMenu As Long, mi As MENUINFO) As Long
    33. Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    34. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    35.  
    36. Private Sub Form_Load()
    37.    
    38.     Dim MyMenu As MENUINFO
    39.    
    40.     MyMenu.cbSize = Len(MyMenu)
    41.     MyMenu.fMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
    42.     MyMenu.hbrBack = CreateSolidBrush(vbWhite)
    43.     SetMenuInfo GetMenu(Me.hwnd), MyMenu
    44.    
    45. End Sub

    You can also do this to set the menu color:

    add this to a module
    VB Code:
    1. Private Declare Function GetMenuInfo Lib "user32" _
    2.                                         (ByVal hMenu As Long, _
    3.                                         mi As MENUINFO) As Long
    4.                                        
    5. Private Declare Function SetMenuInfo Lib "user32" _
    6.                                         (ByVal hMenu As Long, _
    7.                                         mi As MENUINFO) As Long
    8.                                        
    9. Private Declare Function GetMenu Lib "user32" _
    10.                                         (ByVal hwnd As Long) As Long
    11.                                        
    12. Private Declare Function CreateSolidBrush Lib "gdi32" _
    13.                                         (ByVal crColor As Long) As Long
    14.  
    15.     Private Type MENUINFO
    16.         cbSize As Long
    17.         fMask As MENUINFO_MASKS
    18.         dwStyle As Long
    19.         cyMax As Long
    20.         hbrBack As Long
    21.         dwContextHelpID As Long
    22.         dwMenuData As Long
    23.     End Type
    24.    
    25.     Private Enum MENUINFO_MASKS
    26.         MIM_MAXHEIGHT = &H1
    27.         MIM_BACKGROUND = &H2
    28.         MIM_HELPID = &H4
    29.         MIM_MENUDATA = &H8
    30.         MIM_STYLE = &H10
    31.         MIM_APPLYTOSUBMENUS = &H80000000
    32.     End Enum
    33.  
    34. Public Sub SetMenuColor(frm As Form, _
    35.                         ByVal MenuColor As Long, _
    36.                         Optional ByVal ApplyToSubMenus As Boolean = True)
    37.                    
    38.     Dim vMenuInfo As MENUINFO
    39.     Dim vMenuInfoMask As Long
    40.    
    41.     If ApplyToSubMenus Then
    42.         vMenuInfoMask = MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS
    43.     Else
    44.         vMenuInfoMask = MIM_BACKGROUND
    45.     End If
    46.    
    47.     With vMenuInfo
    48.         .cbSize = Len(vMenuInfo)
    49.         .fMask = vMenuInfoMask
    50.         .hbrBack = CreateSolidBrush(MenuColor)
    51.         SetMenuInfo GetMenu(frm.hwnd), vMenuInfo
    52.     End With
    53. End Sub

    Then create a form with a menu and either in the form_load event or in a button or whatever put
    VB Code:
    1. SetMenuColor Me, RGB(123, 123, 123)

    RGB= the red green and blue.. values from 0 to 255 which gives you about any color there is.



    As far as the close button goes; if by "Control it" you mean you want to disable it, use the following code:

    VB Code:
    1. Option Explicit
    2. Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    3. Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    4. Private Const MF_BYPOSITION = &H400&
    5. Private Const MF_BYCOMMAND = &H0&
    6. Private Const SC_CLOSE = &HF060&
    7.  
    8. Private Sub Form_Load() 'or whatever
    9.     Dim systemmenu As Long
    10.     systemmenu = GetSystemMenu(Form1.hwnd, False)
    11.     DeleteMenu systemmenu, SC_CLOSE, MF_BYCOMMAND
    12. End Sub

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I use the same code as the first example, but so far to date, I
    cannot paint the main menu when the item is clicked upon.

    Ex. 'Option' will still be gray but the submenus are colored.
    When I click an item to close the menu, the main menu bar is colored again.



    I subclassed the form at the 'WM_INITMENUPOPUP' message
    and tried to repaint the menu using the menuinfo type so the
    menu will always be vbWhite whether its clicked on or not,
    but it didn't work.

    Any suggestions
    Last edited by RobDog888; Mar 31st, 2003 at 02:54 AM.

  4. #4
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    If you want to perform code when X is pressed you need to do sth like this:

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3.    
    4.     Select Case UnloadMode
    5.    
    6.     Case vbFormControlMenu
    7.      ' this is your X Button      
    8.    
    9.     Case vbFormCode
    10.     ' your form gets closed by any other code IE an Button
    11.     Case vbAppTaskManager
    12.      ' your app gets closed by the Task manager  
    13.     .
    14.     .
    15.     .
    16.  
    17.     End Select
    18.                
    19. End Sub

    Hope I could help,

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    To disable the 'x'...
    Code:
    Option Explicit
    
    Private Const MF_BYPOSITION = &H400&
    
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    
    Private Sub Form_Load()
        RemoveMenu GetSystemMenu(hwnd, 0), 6, MF_BYPOSITION
    End Sub

  6. #6
    Hyperactive Member Colonel Klink's Avatar
    Join Date
    Aug 2002
    Location
    Gold Coast, Australia
    Posts
    329
    Originally posted by Sgt-Peppa
    If you want to perform code when X is pressed you need to do sth like this:

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3.    
    4.     Select Case UnloadMode
    5.    
    6.     Case vbFormControlMenu
    7.      ' this is your X Button      
    8.    
    9.     Case vbFormCode
    10.     ' your form gets closed by any other code IE an Button
    11.     Case vbAppTaskManager
    12.      ' your app gets closed by the Task manager  
    13.     .
    14.     .
    15.     .
    16.  
    17.     End Select
    18.                
    19. End Sub

    Hope I could help,

    Stephan
    i tried that with the following code and it didnt work

    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     Select Case UnloadMode
    3.         Case vbFormControlMenu
    4.             frmSStatus.Hide
    5.             stSMain.InTray = True
    6.             Exit Sub
    7.         Case vbAppTaskManager
    8.             frmSStatus.Hide
    9.             stSMain.InTray = True
    10.             Exit Sub
    11.         Case vbFormCode
    12.             frmSStatus.Hide
    13.             stSMain.InTray = True
    14.             Exit Sub
    15.     End Select
    16. End Sub
    (stSMain is the system tray icon control)

  7. #7
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    is frmSStatus.Hide the form from where you press the X button?

    If so don`t think you can hide a form which gets Unloaded!

    Try this simple example I included:

    Hope I could help,


    Stephan
    Attached Files Attached Files
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

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