타이틀바에 버튼을 하나 추가했습니다.
델마당의 도움을 많이 받아서...
근데...몇가지를 더 추가하려고 하는데 잘 안되서 도움을 청합니다.
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.
|