Solved

Change the Color of the Title Bar

Posted on 2001-08-05
9
465 Views
Last Modified: 2011-10-03
Hi All!
Need to use the rest of my points before I go on vacation.
How can I change the color of the Title Bar on the MDI Form and all Child forms in an application?  I have a function, but the right area of the title bar remains light blue.  I'd like it to be one solid color.
Here is what I have (from freevbcode.com):
Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, _
                    lpColorValues As Long) As Long
Global Const COLOR_ACTIVECAPTION = 2

Public Function ChangeTitleBarColor(NewColor As Long) As Boolean
    Dim lRet As Long
   
    lRet = SetSysColors(1, COLOR_ACTIVECAPTION, NewColor)
    ChangeTitleBarColor = lRet > 0
End Function

Public Function GetTitleBarColor() As Long
    GetTitleBarColor = GetSysColor(COLOR_ACTIVECAPTION)
End Function
0
Comment
Question by:alicelknight
[X]
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
9 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6353133
try this

t& = SetSysColors(1, COLOR_ACTIVECAPTION, RGB(255,0,0))                    

cheers
Andyt
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6353137
you might find this useful, if not then nothing lost

Declare Function SetSysColors Lib "user32" Alias _
"SetSysColors" (ByVal nChanges As Long, lpSysColor As _
Long, lpColorValues As Long) As Long          
         
The Constants are:

Public Const COLOR_SCROLLBAR = 0 'The Scrollbar colour  
Public Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper  
Public Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window  
Public Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window  
Public Const COLOR_MENU = 4 'Menu  
Public Const COLOR_WINDOW = 5 'Windows background  
Public Const COLOR_WINDOWFRAME = 6 'Window frame  
Public Const COLOR_MENUTEXT = 7 'Window Text  
Public Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)  
Public Const COLOR_CAPTIONTEXT = 9 'Text in window caption  
Public Const COLOR_ACTIVEBORDER = 10 'Border of active window  
Public Const COLOR_INACTIVEBORDER = 11 'Border of inactive window  
Public Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop  
Public Const COLOR_HIGHLIGHT = 13 'Selected item background  
Public Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item  
Public Const COLOR_BTNFACE = 15 'Button  
Public Const COLOR_BTNSHADOW = 16 '3D shading of button  
Public Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.  
Public Const COLOR_BTNTEXT = 18 'Button text  
Public Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window  
Public Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button  


cheers
Andy
0
 

Author Comment

by:alicelknight
ID: 6353157
andysalih:
This is how I call it and I still get light blue on the right side.

Public l as long

MDIForm_Load()

l = GetTitleBarColor
   
ChangeTitleBarColor RGB(255, 0, 0)
End Sub

MDIForm_Unload()

ChangeTitleBarColor l
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:andysalih
ID: 6353274
try this

http://www.planetsourcecode.com/xq/ASP/txtCodeId.7995/lngWId.1/qx/vb/scripts/ShowCode.htm

even shows you what it will look like.

you can download the code and cut & paste it into yours

good luck

andy
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 100 total points
ID: 6353823
Sounds like you're running Win98/2000/Me and have got the gradient turned on.  I don't have a system to test it on, but either this:

1) Switching both the gradient and the active to the same color.

Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, ByRef lpSysColor As Long, ByRef lpColorValues As Long) As Long
Private Const COLOR_GRADIENTACTIVECAPTION = 27
Private Const COLOR_ACTIVECAPTION = 2

Private Sub Command1_Click()

  Dim items(1) As Long
  Dim colors(1) As Long

  colors(0) = RGB(255, 0, 0)
  colors(1) = RGB(255, 0, 0)

  items(0) = COLOR_GRADIENTACTIVECAPTION
  items(1) = COLOR_ACTIVECAPTION

  SetSysColors 2, items(0), colors(0)
   
End Sub



2) Or disabling the gradient effect

Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPI_SETGRADIENTCAPTIONS = &H1009

Private Sub Command2_Click()

    Dim toggle As Long
   
    toggle = 0
   
    SystemParametersInfo SPI_SETGRADIENTCAPTIONS, 0, toggle, 0

End Sub
0
 

Author Comment

by:alicelknight
ID: 6354128
clockwatcher:
Thanks!  That was the problem!

andysalih:  I'm awarding you points also as you got me 75% there!  Look for some points and Thanks!
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6354198
thanks alice
0
 

Expert Comment

by:RBETTISON
ID: 6360079
Just a comment on the above.....re SetSysColors..I found on an application of mine, using this function to change the color of the title bar in response to different messages coming into the machine...eventually took all the resources and crashed windows! I think this routine has a memory leak....and I can't find any reference to it anywhere!


Just thought you would like to know!


0
 

Author Comment

by:alicelknight
ID: 6362113
RBettison:
Thanks for the information!  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

734 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