?
Solved

A button on the Caption

Posted on 1999-07-28
28
Medium Priority
?
350 Views
Last Modified: 2010-04-04
Hi Expert.
How Can I draw a button on the caption of my app ?
I'd like to draw the botton with the same size of the close window button (the one on the top right corner.
Regards.
0
Comment
Question by:borgo
  • 7
  • 7
  • 7
  • +4
28 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 120 total points
ID: 1391625
hi borgo,
here you go:

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Buttons;

type
  TTitleBtnForm = class(TForm)
    procedure FormResize(Sender: TObject);
  private
    TitleButton : TRect;
    procedure DrawTitleButton;
    {Paint-related messages}
    procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT;
    procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPAINT;
    procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
    {Mouse down-related messages}
    procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
    procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
    function GetVerInfo : DWORD;
  end;

var
  TitleBtnForm: TTitleBtnForm;

const
  htTitleBtn = htSizeLast + 1;

implementation
{$R *.DFM}

procedure TTitleBtnForm.DrawTitleButton;
var
  bmap : TBitmap; {Bitmap to be drawn - 16 X 16 : 16 Colors}
  XFrame,  {X and Y size of Sizeable area of Frame}
  YFrame,
  XTtlBit, {X and Y size of Bitmaps in caption}
  YTtlBit  : Integer;
begin
  {Get size of form frame and bitmaps in title bar}
  XFrame  := GetSystemMetrics(SM_CXFRAME);
  YFrame  := GetSystemMetrics(SM_CYFRAME);
  XTtlBit := GetSystemMetrics(SM_CXSIZE);
  YTtlBit := GetSystemMetrics(SM_CYSIZE);

  {$IFNDEF WIN32}
    TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
                          YFrame - 1,
                          XTtlBit + 2,
                          YTtlBit + 2);

  {$ELSE}     {Delphi 2.0 positioning}
    if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
      TitleButton := Bounds(Width - (3 * XTtlBit) - ((XTtlBit div 2) - 2),
                            YFrame - 1,
                            XTtlBit + 2,
                            YTtlBit + 2)
    else
      TitleButton := Bounds(Width - XFrame - 4*XTtlBit + 2,
                           XFrame + 2,
                           XTtlBit + 2,
                           YTtlBit + 2);
  {$ENDIF}


  Canvas.Handle := GetWindowDC(Self.Handle); {Get Device context for drawing}
  try
    {Draw a button face on the TRect}
    DrawButtonFace(Canvas, TitleButton, 1, bsAutoDetect, False, False, False);
    bmap := TBitmap.Create;
    bmap.LoadFromFile('c:\help.bmp');
    with TitleButton do
      {$IFNDEF WIN32}
        Canvas.Draw(Left + 2, Top + 2, bmap);
      {$ELSE}
        if (GetVerInfo = VER_PLATFORM_WIN32_NT) then
          Canvas.Draw(Left + 2, Top + 2, bmap)
        else
          Canvas.StretchDraw(TitleButton, bmap);
      {$ENDIF}

  finally
    ReleaseDC(Self.Handle, Canvas.Handle);
    bmap.Free;
    Canvas.Handle := 0;
  end;
end;

{Paint triggering events}
procedure TTitleBtnForm.WMNCActivate(var Msg : TWMNCActivate);
begin
  Inherited;
  DrawTitleButton;
end;

procedure TTitleBtnForm.FormResize(Sender: TObject);
begin
  Perform(WM_NCACTIVATE, Word(Active), 0);
end;

{Painting events}
procedure TTitleBtnForm.WMNCPaint(var Msg : TWMNCPaint);
begin
  Inherited;
  DrawTitleButton;
end;

procedure TTitleBtnForm.WMSetText(var Msg : TWMSetText);
begin
  Inherited;
  DrawTitleButton;
end;

{Mouse-related procedures}
procedure TTitleBtnForm.WMNCHitTest(var Msg : TWMNCHitTest);
begin
  Inherited;
  {Check to see if the mouse was clicked in the area of the button}
  with Msg do
    if PtInRect(TitleButton, Point(XPos - Left, YPos - Top)) then
      Result := htTitleBtn;
end;

procedure TTitleBtnForm.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
begin
  inherited;
  if (Msg.HitTest = htTitleBtn) then
    ShowMessage('You pressed the new button');
end;

function TTitleBtnForm.GetVerInfo : DWORD;
var
 verInfo : TOSVERSIONINFO;
begin
  verInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  if GetVersionEx(verInfo) then
    Result := verInfo.dwPlatformID;
    {Returns:
      VER_PLATFORM_WIN32s             Win32s on Windows 3.1
      VER_PLATFORM_WIN32_WINDOWS        Win32 on Windows 95
      VER_PLATFORM_WIN32_NT           Windows NT }
end;

end.



Regards Barry
0
 
LVL 17

Expert Comment

by:inthe
ID: 1391626
BTW.
>>> bmap.LoadFromFile('c:\help.bmp');

that line is for a glyph.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1391627
Interesting  :o)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 17

Expert Comment

by:inthe
ID: 1391628
yep found some neat windows programming tip sites and got loads o sources for interesting stuff :-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391629
Ain't that form Delumpa's website? ;-))

He's got some neat tricks there...
0
 
LVL 17

Expert Comment

by:inthe
ID: 1391630
hehe
good guess viktor :o)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391631
hehe :)
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1391632
I have a freeware component (downloaded from the web sometime ago) which  make things easier. Let me know if you are interested - I will find out the website for you or send you the component if you like
0
 

Author Comment

by:borgo
ID: 1391633
Hi kjteng
my email is borgo@indi.it
Thanks

Hi Inthe thank you very much for your help. I'll try your code as soon as possible.


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1391634
hi borgo,

take a look to this freeware
http://www.torry.ru/vcl/buttons/captbtn.zip

meikl
0
 
LVL 17

Expert Comment

by:inthe
ID: 1391635
mm...everyone advising components so it seems my turn

http://www.infa.ru/black/ralib.htm

for the great ralib ,many of the more unusual components together in a component package including the RACaptionButton...
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391636
bi_lib has a great component to add a button on the caption bar..

http://www.b-ischo.horizont-is.net/coding.htm
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1391637
Sent
The file was downloaded from
http://www.angen.net/~xacker/delphi.shtml

It is standalone and only about 10K (*.pas)
0
 

Author Comment

by:borgo
ID: 1391638
Thank you very much to all of you who have halped me.

Regards.

Andrea.

0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391639
hm.. 'Andrea' ..   are you female ?
0
 

Author Comment

by:borgo
ID: 1391640
:-) why ?

I'm sorry but I'm male.
In Italy Andrea is a male name, it becomes from Greek and it means "man".
Even I'm a guy I hope you will continue to help me to learn Delph :-)

Bye bye.
 
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391641
sure.. =)

hmm... isn't there any girl programmer ??? is it so hard to find ?

sounds exciting that there's a girl using delphi and programming and etc..

doesn't it ?

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391642
Gwena is a girl :)
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391643
cool ! .. how old is she ? where from ?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391644
I think she is about 17-18 years old :)) Just like me ;) and you? damn.. ;)) but i'm not exactly sure.. here is her profile..

http://www.experts-exchange.com/bin/ShowUser?login=Gwena

;)

..-=ViKtOr=-..


0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391645
I'm 19 =)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391646
yes she's a girl...

http://www.gurlpages.com/computer/gwena/

there is a picture of her.. she's pretty nice :)
0
 
LVL 17

Expert Comment

by:inthe
ID: 1391647
hey bryan7 try here :

http://www.lhc.lg.ua/index.html
0
 
LVL 17

Expert Comment

by:inthe
ID: 1391648
ROFLOL
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391649
aha, now there is something for Bryan to look at  :))
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391650
you've get me wrong..  I have my nice girlfriend yet.. don't need that stuff :)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1391651
sorry Bryan, do you want me to tell her or are you willing to stand up to her and tell her the truth? :)
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1391652
?  ???
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

588 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