Solved

Change the Color of the Title Bar

Posted on 2001-08-05
9
420 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

813 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

19 Experts available now in Live!

Get 1:1 Help Now