Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the color of title bar

Status
Not open for further replies.

Per9922

IS-IT--Management
Oct 1, 2004
74
0
0
SE
Hello all,

Is it possible by VBA to change the color of title bar on user form with VBA ? I'm using a SCADA system and the user form takes the window settings, and I would like to change the color so it will fit with all the other colors.

Please help!

Per
 
Not really, no. As you have noticed, the title bar colour is a system wide setting. You can change it using the SetSysColors API call, but ALL standard windows title bars will change colour as well.

The other alternative is not exactly straightforward. You need to switch off the system-provided title bar of your form (which involves some slightly convoluted API work), mess about with client and non-client areas, draw your own, custom title bar and handle all the windows messages it should respond to in order to operate like a real title bar. This involves even more complex API code ...

 
Thanks!

I notice that WinCC uses VBS(And C) and not VBA ... sorry! I tried to search how to change color with SetSysColors but could not fins any good example :(!

Anybody that have done this ?

Kalle
 
If you are using VBS then you can't use the Windows API
 
:( Thanks.

If I you C ? Do you know ?
 
You can certainly use the Windows API from C.

How you would do it in C under WinCC I have no idea.
 
Thanks again! I hope I find away to do it
 
Thanks strongm. I removed the other thread. I tried the code below in VB, but nothing happends. I though I could make an exe file that I could call from my application.

Module Module1
Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, ByVal lpSysColor As Long, ByVal lpColorValues As Long) As Long
' This code goes in the userform module...
Private Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
Private Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
Private Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
Private Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
Private Const COLOR_MENU = 4 'Menu
Private Const COLOR_WINDOW = 5 'Windows background
Private Const COLOR_WINDOWFRAME = 6 'Window frame
Private Const COLOR_MENUTEXT = 7 'Window Text
Private Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
Private Const COLOR_CAPTIONTEXT = 9 'Text in window caption
Private Const COLOR_ACTIVEBORDER = 10 'Border of active window
Private Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
Private Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
Private Const COLOR_HIGHLIGHT = 13 'Selected item background
Private Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
Private Const COLOR_BTNFACE = 15 'Button
Private Const COLOR_BTNSHADOW = 16 '3D shading of button
Private Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
Private Const COLOR_BTNTEXT = 18 'Button text
Private Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
Private Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
Sub Main()
Dim t As Long
t = SetSysColors(1, 1, RGB(255, 0, 0))
t = SetSysColors(1, 2, RGB(255, 0, 0))
t = SetSysColors(1, 3, RGB(255, 0, 0))
t = SetSysColors(1, 4, RGB(255, 0, 0))
t = SetSysColors(1, 5, RGB(255, 0, 0))
t = SetSysColors(1, 6, RGB(255, 0, 0))

t = SetSysColors(1, 7, RGB(255, 0, 0))
t = SetSysColors(1, 8, RGB(255, 0, 0))
t = SetSysColors(1, 9, RGB(255, 0, 0))
t = SetSysColors(1, 10, RGB(255, 0, 0))
t = SetSysColors(1, 11, RGB(255, 0, 0))
t = SetSysColors(1, 12, RGB(255, 0, 0))
t = SetSysColors(1, 13, RGB(255, 0, 0))
t = SetSysColors(1, 14, RGB(255, 0, 0))
t = SetSysColors(1, 15, RGB(255, 0, 0))
t = SetSysColors(1, 16, RGB(255, 0, 0))

t = SetSysColors(1, 18, RGB(255, 0, 0))
t = SetSysColors(1, 19, RGB(255, 0, 0))
t = SetSysColors(1, 20, RGB(255, 0, 0))
End Sub

End Module
 
> WinCC uses VBS

Your code is VBA. It won't work in VBS. Or C
 
Hello,

I compied it and run it in Visual Studio :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top