Link to home
Start Free TrialLog in
Avatar of HATCHET
HATCHET

asked on

Changing form titlebar color

I know how to change the system colors so that ALL the titlebars of all the windows change color using a Windows API.  My question is how can I make JUST ONE form change?  

For example, I create a new project and have a form called Form1.  The active window titlebar color is BLUE.  How can I change JUST Form1's titlebar color to say GREEN?

Please provide sample code.

HATCHET
Avatar of caraf_g
caraf_g

You can't do this unless you draw your own title bar for the form.

Why do this? The user has chosen a colour scheme for their desktop. Respect that.
caraf_g is right. The title bar is part of the desktop and not your application. Thus there is no programmatic control for it. This is not a bug, but a feature. You also can't change the font without changing the entire desktop's appearance.

M
Check this out... http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=1132 
 

The guy that posted it didn't post all of the code, but you could email'm for it....



Cheers!
Avatar of HATCHET

ASKER

caraf_g   and   mark2150,

I'm sorry, I should have been more specific as to what I needed this for.  Maybe would have gotten people off to a better start.

I'm using some code I found to subclass a form and gradiate it's titlebar.  I've managed to fix a lot of bugs in the code that prevent it from drawing the gradient correctly, however there's one last thing I'm stumpted on.  I can make it draw a 2 color gradient on the titlebar given 2 colors.  What it does is draws the gradient over the existing titlebar, draws the icon in the right place, draws the text in the right place and I'm done.  The problem occurs if your second color (the color on the right side) is different from the default windows colors for the titlebar.  Say I specify RED for the start color on the left and GREEN for the end color on the right.  If the default active color for windows titlebars is BLUE, then you'll see gradiation from RED over to GREEN then the control box containing the MIN/MAX/CLOSE buttons is BLUE and doesn't match at all.

If the fix for this is drawing over that area, that's kewl... but I need sample code to head me in the right direction.  Or is there another way to do what I'm trying to do?  I was figuring that if I changed the color of THAT form to the end color, it would match and look right.  

You're right, I don't want to mess with the user's colors and I won't do that.  Need something that's form specific.

---------------------------------------------------

mcrider,

I checked out the page you specified and the code is chopped in half and I can't see how to get in touch with the guy.  His web page link is PATHETIC!  Any ideas?

---------------------------------------------------

HATCHET
this sample will cover the titlebar with a bitmap hope it helps plus i need the points

'Windows global API
Option Explicit
DefLng A-Z
Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As Long, ByVal lpBitmapName As String) As Long

Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Declare Function CloseClipboard Lib "user32" () As Long
Declare Function EmptyClipboard Lib "user32" () As Long
Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Const CF_BITMAP = 2
Public Const LR_LOADMAP3DCOLORS = &H1000
Public Const LR_LOADFROMFILE = &H10
Public Const LR_LOADTRANSPARENT = &H20
Public Const IMAGE_BITMAP = 0

'source code
Public Sub MakeFileTrans(ImgPic As Object, ByVal FileName As String)
'You'll need to add an NT 4.0 procedure
Dim BitMapLong As Long
Dim TempLong As Long
 
TempLong = OpenClipboard(0)
TempLong = EmptyClipboard()
 
BitMapLong = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, _
                LR_LOADFROMFILE Or LR_LOADMAP3DCOLORS Or LR_LOADTRANSPARENT)
 
TempLong = SetClipboardData(CF_BITMAP, BitMapLong)
TempLong = CloseClipboard()

Set ImgPic.Picture = Clipboard.GetData(vbCFBitmap)
Clipboard.SetText ""

End Sub
Avatar of HATCHET

ASKER

cody76589,

Either you didn't read the question or you don't know jack about Visual Basic programming.  The code you gave me was to clear the clipboard, load a specified image into a PictureBox control, then store the picture in your clipboard.  There's NOTHING in your code about anything to do with the titlebar of the form!  And the way you worked with the clipboard is all thru the Win32 API... next time look into the "Clipboard" object in VB.

However, I did find it interesting that it made certain colors in the loaded image trasparent even though it was a bitmap.

Nevertheless... I'm rejecting your answer in hope that someone has an answer... though I fear no one will and I'll have to JimmyRig the code or give up on my idea.

Oh wel, Cea la vi.

HATCHET
I thought the guy had an email address there... Oh well, you could leave a message on that thread and invite him here...


Cheers!
ASKER CERTIFIED SOLUTION
Avatar of mark2150
mark2150

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try implement source code from:
http://www.vb-helper.com/HowTo/titlebar.zip

Cheers
Thats good one.
Avatar of HATCHET

ASKER

georgeman,

That's an interesting way of doing it, but not the best because the gradient still does not cover the control area and the gradient does not resize with the form.  I can see a benefit to that though... if you want to put a company logo in the titlebar or something... that would be great.

I've been doing some searching and the simplest way to do gradients that I've found is a control called ARFormExtender.  Just put it on the form, set the Gradient Titlebar property to TRUE, and you're done!  Seems to do a good job with the gradient and NO CODING REQUIRED!  Yee haa.

http://sevillaonline.com/ActiveX/vb5/ARFormExtender.htm

Anyways... I'm going to give it one last shot with mark2150's idea and remove the control box, then add my own system drop downs to emulate the control box with gradient effects.  I really don't think it will work but it's worth a shot.  In the meanwhile... he's made a good point about the standard Windows GUI and I'll stick to the GetSysColor(COLOR_ACTIVECAPTION) and GetSysColor(COLOR_INACTIVECAPTION) for the standard active and inactive colors on the right side.  That way the color always blends into the control box colors but allows for the initial color to be customized.

Thanks again for all the help and input on this one.

HATCHET