Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A button on the Caption

Posted on 1999-07-28
28
Medium Priority
?
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

721 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