Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[10802] [질문] 타이틀바 추가 후 궁금점한 점.....
용이... [park6394] 1576 읽음    2006-07-19 10:39
타이틀바에 버튼을 하나 추가했습니다.
델마당의 도움을 많이 받아서...
근데...몇가지를 더 추가하려고 하는데 잘 안되서 도움을 청합니다.
1. 버튼에 이미지를 하나 올리고 싶습니다.
  - 화면 생성시 생성된 모양은 ▲가 있다가 버튼을 눌렀을때 ▼, 다시 눌렀을때 ▲
    이렇게 하고 싶습니다.
2. 생성된 버튼을 더블클릭하면 화면이 저절로 닫히는데...그걸 막고 싶습니다.

여러가지고 해봤는데...잘 안되네요...
고수님들의 한 수 가르침을 바랍니다.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons;

type
TForm1 = class(TForm)
   procedure FormCreate(Sender: TObject);
private
   { Private declarations }
   gnBtnX, gnBtnY, gnCaptionY, gnFrmX, gnFrmY : Integer;

   BtnRect : TRect;
   BtnDown : Boolean;
   BtnFaceDown : Boolean;

   procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPaint;
   procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
   procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
   procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
   procedure WMNCMouseMove(var Msg : TWMMouseMove); message WM_MOUSEMOVE;
   procedure WMLButtonUp(var Msg : TWMLButtonUp); message WM_LBUTTONUP;
   //procedure WMLButtonDbClick(var Msg : TWMLButtonUp); message WM_LB;


   procedure AddButtonToCaption;
   procedure ClickedButton;

public
   { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
gnBtnX     := GetSystemMetrics( SM_CXSIZE );
gnBtnY     := GetSystemMetrics( SM_CYSIZE );
gnCaptionY := GetSystemMetrics( SM_CYCAPTION );
gnFrmX     := GetSystemMetrics( SM_CXSIZEFRAME );
gnFrmY     := GetSystemMetrics( SM_CYSIZEFRAME );

end;

procedure TForm1.AddButtonToCaption;
var
TempHDC : HDC;
begin
BtnRect := Bounds( ClientWidth - gnBtnX * 2, gnFrmX + 2, gnBtnX - 2, gnBtnY -4 );

TempHDC := Canvas.Handle;

Canvas.Handle := GetWindowDC( Handle );


DrawButtonFace( Canvas, BtnRect, 1, bsNew, False, BtnFaceDown, False );

ReleaseDC( Handle, Canvas.Handle );
Canvas.Handle := TempHDC;
end;

procedure TForm1.WMNCPaint(var Msg : TWMNCPaint);
begin
inherited;

AddButtonToCaption;
end;

procedure TForm1.WMNCActivate(var Msg : TWMNCActivate);
begin
inherited;

AddButtonToCaption;
end;

procedure TForm1.WMNCHitTest(var Msg : TWMNCHitTest);
begin
inherited;

if PtInRect(BtnRect, Point(Msg.XPos - Left, Msg.YPos - Top)) then
begin
   Msg.Result := HTSYSMENU;
end;
end;

procedure TForm1.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
begin
inherited;

if PtInRect( BtnRect, Point( Msg.XCursor - Left, Msg.YCursor - Top)) then
begin
   BtnDown := True;
   BtnFaceDown := True;

   AddButtonToCaption;
   SetCapture( Handle );
   Msg.Result := 0;
end;
end;

procedure TForm1.ClickedButton;
begin
//Beep;
end;

procedure TForm1.WMLButtonUp(var Msg: TWMLButtonUp);
begin
if BtnDown then
begin
   if PtInRect( BtnRect, Point(Msg.XPos + gnFrmX, Msg.YPos + gnFrmY + gnCaptionY) ) then
   begin
     ClickedButton;
   end;

   BtnDown := False;
   BtnFaceDown := False;
   AddButtonToCaption;
   ReleaseCapture;
   Msg.Result := 0;
end
else
   inherited;
end;

procedure TForm1.WMNCMouseMove(var Msg: TWMMouseMove);
var
InBtn : Boolean;
begin
if BtnDown then
begin
   InBtn := PtInRect( BtnRect, Point(Msg.XPos + gnFrmX, Msg.YPos + gnFrmY + gnCaptionY) );

   if (InBtn and not BtnFaceDown) or (not InBtn and BtnFaceDown) then
   begin
     BtnFaceDown := not BtnFaceDown;
     AddButtonToCaption;
     Msg.Result := 0;
   end;
end
else
   Inherited;
end;

end.

+ -

관련 글 리스트
10802 [질문] 타이틀바 추가 후 궁금점한 점..... 용이... 1576 2006/07/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.