pr_wainwright
asked on
Change form Caption bar Colour/Font
Is it possible to change a forms caption (title) bar colour and font using Windows API. I can use RxLib's Gradient caption component but would like to do this using API only.
Thanks
Paul.
Thanks
Paul.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bugroger,
Your code works fine for fonts. Any idea's on how to change the colour of the title bar ?. Solid colour required, no gradient necessary.
Thanks
Paul.
Your code works fine for fonts. Any idea's on how to change the colour of the title bar ?. Solid colour required, no gradient necessary.
Thanks
Paul.
hi pr
i think there is no api function to change the
color of a window's caption! You only can change the
system colors. But then all window captions will be
changed.
Look at:
http://www.mindspring.com/~cityzoo/ttlbar1.html
It's an artikel about
Creating Forms with Custom Title Bars
maybe it helps
GL
bug
i think there is no api function to change the
color of a window's caption! You only can change the
system colors. But then all window captions will be
changed.
Look at:
http://www.mindspring.com/~cityzoo/ttlbar1.html
It's an artikel about
Creating Forms with Custom Title Bars
maybe it helps
GL
bug
Heres a bit of code to get you started:
...
private
{ Private declarations }
procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
public
{ Public declarations }
end;
...
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
var
cxWin, cxBit, cxFrame, cyBit, cyCapt, cyFrame : Integer;
Rect : TRect;
H : hdc;
begin
inherited;
cxBit := GetSystemMetrics(SM_CXSIZE );
cxFrame := GetSystemMetrics(SM_CXFRAM E);
cyCapt := GetSystemMetrics(SM_CYCAPT ION);
cyFrame := GetSystemMetrics(SM_CYFRAM E);
GetWindowRect(Form1.Handle , Rect);
cxWin := rect.Right - Rect.Left;
Rect.Top := cyFrame;
Rect.Bottom := Rect.Top + cyCapt - 2;
Rect.Left := cxFrame + cxBit + 1;
Rect.Right := cxWin - cxFrame - 2 * cxBit - 2;
H := GetWindowDC(Form1.Handle);
FillRect(H, Rect, CreateSolidBrush(RGB(255, 0, 0)));
SetBkMode(H, TRANSPARENT);
SetTextColor(H, clBlack);
DrawText(H, PChar(Form1.Caption), -1, Rect, DT_LEFT);
ReleaseDc(Form1.Handle, H);
end;
It paints MOST of the caption bar red (all except around the buttons). This is because to make it look like the whole caption bar is red would mean to paint the buttons and system images over the top of the background manually. Also there are other problems such as when the window becomes inactive and when the window is restored. I will try and code a better working example for you and will post it later on.
Cheers,
Alan
...
private
{ Private declarations }
procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
public
{ Public declarations }
end;
...
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
var
cxWin, cxBit, cxFrame, cyBit, cyCapt, cyFrame : Integer;
Rect : TRect;
H : hdc;
begin
inherited;
cxBit := GetSystemMetrics(SM_CXSIZE
cxFrame := GetSystemMetrics(SM_CXFRAM
cyCapt := GetSystemMetrics(SM_CYCAPT
cyFrame := GetSystemMetrics(SM_CYFRAM
GetWindowRect(Form1.Handle
cxWin := rect.Right - Rect.Left;
Rect.Top := cyFrame;
Rect.Bottom := Rect.Top + cyCapt - 2;
Rect.Left := cxFrame + cxBit + 1;
Rect.Right := cxWin - cxFrame - 2 * cxBit - 2;
H := GetWindowDC(Form1.Handle);
FillRect(H, Rect, CreateSolidBrush(RGB(255, 0, 0)));
SetBkMode(H, TRANSPARENT);
SetTextColor(H, clBlack);
DrawText(H, PChar(Form1.Caption), -1, Rect, DT_LEFT);
ReleaseDc(Form1.Handle, H);
end;
It paints MOST of the caption bar red (all except around the buttons). This is because to make it look like the whole caption bar is red would mean to paint the buttons and system images over the top of the background manually. Also there are other problems such as when the window becomes inactive and when the window is restored. I will try and code a better working example for you and will post it later on.
Cheers,
Alan
ASKER
Bugroger,
Thanks for the source code & link.
Regards
Paul.
Thanks for the source code & link.
Regards
Paul.
www.torry.net/captions.htm
You can find the source code for components that add a gradient to the caption bar of your form and more.
Cheers,
Alan