PDA

Click to See Complete Forum and Search --> : Changing form's titlebar colors


Hyperspaced
May 7th, 2001, 03:22 AM
Hello all.

I am trying to change the colors of a form, especially the colors of the titlebar at run-time.

I am using the GetSysColor API call with the constant COLOR_ACTIVEBORDER to retrieve the color of the titlebar.

However, when using the SetSysColors API call I have some problems.
The more fundemental of those is about the declaration of the call :

Declare Function SetSysColors& Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long)

As you can see guys the lpSysColor is passed byref, as well as the lpColorValues. OK, in my documentation, these are long pointers to matrices, each having a length of nChanges elements. I am creating 2 matrices let's say matrSC and matrCV, each of nChanges elements. When using the declaration I simply pass matrSC() or matrCV(), with no arguments (I hope this passes the pointer to the matrix).
This causes an error; clearly I am making a mistake... Any help ?? :confused:


One more important thing : AM I USING THE CORRECT DECLARATION AT ALL ????!!!!? Any ideas ??? :rolleyes: :rolleyes:

appolospb
Dec 4th, 2008, 06:18 AM
The below code will perform a 'MSN Messenger' style titlebar flash when executed. The below code will need to be launched via a thread otherwise the colour change event gets locked on one colour and wont flash. I also havent found out how to get it to flash when the forms minimised to the startbar.

Private Declare Function SetSysColors Lib "user32.dll" (ByVal nChanges As Int32, ByRef lpSysColor As SystemColor, ByRef lpColorValues As Int32) As Int32
Private Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Int32) As Int32

Public Enum SystemColor As Integer
ScrollBar = 0 'The Scrollbar colour
BackGround = 1 'Colour of the background with no wallpaper
ActiveCaption = 2 'Caption of Active Window
InactiveCaption = 3 'Caption of Inactive window
Menu = 4 'Menu
Window = 5 'Windows background
WindowFrame = 6 'Window frame
MenuText = 7 'Window Text
WindowText = 8 '3D dark shadow (Win95)
CaptionText = 9 'Text in window caption
ActiveBorder = 10 'Border of active window
InactiveBorder = 11 'Border of inactive window
AppWorkspace = 12 'Background of MDI desktop
Highlight = 13 'Selected item background
HighlightText = 14 'Selected menu item
BtnFace = 15 'Button
BtnShadow = 16 '3D shading of button
GrayText = 17 'Grey text, of zero if dithering is used.
BtnText = 18 'Button text
InactiveCaptionText = 19 'Text of inactive window
BtnHightList = 20 '3D highlight of button
SecondActiveCatpion = 27 'Win98 only: 2nd active window color
SecondInactiveCaption = 28 'Win98 only: 2nd inactive window color
End Enum

Sub highlightform()
' This sub procedue needs to be launched via a thread

Dim i As Integer
' Store the position within the for loop
Dim colour1 As Integer
Dim colour2 As Integer
Dim colour3 As Integer
Dim colour4 As Integer
' Store the orginal Windows colours
Dim value1 As Integer = 228
Dim value2 As Integer = 67
Dim value3 As Integer = 18
' Define the red/blue/green values

colour1 = GetSysColor(SystemColor.ActiveCaption)
colour2 = GetSysColor(SystemColor.SecondActiveCatpion)
colour3 = GetSysColor(SystemColor.InactiveCaption)
colour4 = GetSysColor(SystemColor.SecondInactiveCaption)
' Store the orginal colour values

For i = 0 To 12
' Perform the below actions 12 times

thread.Sleep(400)
' Sleep to allow the API time to perform its colour change

SetSysColors(1, SystemColor.ActiveCaption, RGB(value1, value2, value3))
SetSysColors(1, SystemColor.SecondActiveCatpion, RGB(value1, value2, value3))
SetSysColors(1, SystemColor.InactiveCaption, RGB(value1, value2, value3))
SetSysColors(1, SystemColor.SecondInactiveCaption, RGB(value1, value2, value3))
' Change the colour

thread.Sleep(400)
' Sleep to allow the API time to perform its colour change

SetSysColors(1, SystemColor.ActiveCaption, colour1)
SetSysColors(1, SystemColor.SecondActiveCatpion, colour2)
SetSysColors(1, SystemColor.InactiveCaption, colour3)
SetSysColors(1, SystemColor.SecondInactiveCaption, colour4)
' Change the colour back to default

Next

SetSysColors(1, SystemColor.ActiveCaption, colour1)
SetSysColors(1, SystemColor.SecondActiveCatpion, colour2)
SetSysColors(1, SystemColor.InactiveCaption, colour3)
SetSysColors(1, SystemColor.SecondInactiveCaption, colour4)
' Change the colour back to default

End Sub