Q&A

  • window title bar에 아이콘을 추가하고 아이콘 이벤트를 달고 싶습니다.
이리뒤지고 저리 뒤져도 못찾고 도움을 요청합니다.

form의 title bar의 왼쪽 상단에...
BorderIcons 로 축소,확대,닫기 버튼을 보였다 감추었다가 하듯이
또 하나의 버튼을 축소버튼 옆에 달고 싶습니다.
물로 추가 버튼을 눌렀을때 어떤 작업도 하고 싶고요..

그것이 불가능 하면..  헬프(biHelp)버튼을 이용해도 될법한데...
그것도 찾지 못했슴다.. T.T
고수님들의 답변을 간절히 기다립니다.
2  COMMENTS
  • Profile
    홍성락 2002.07.08 22:49
    hsr//////////////////////////////////////////////////////////////////
    자료실에 DelTip이라는 델파이 팁 소스를 모아 놓은것을 찾으시면 아래 같은 소스가 있더군요....원하시는건지요?

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Buttons;
    type
      TForm1 = class(TForm)
        procedure FormResize(Sender: TObject);
      private
        { Private declarations }
        CaptionBtn : TRect;
       procedure DrawCaptButton;
       procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPaint;
       procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
       procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT;
       procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
       procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;

      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation
    const
    htCaptionBtn = htSizeLast + 1;
    {$R *.DFM}
    //////////////////////////////////////////////////////////////////////
    procedure TForm1.FormResize(Sender: TObject);
    begin
    //Force a redraw of caption bar if form is resized
    Perform(WM_NCACTIVATE, Word(Active), 0);
    end;

    //////////////////////////////////////////////////////////////////////
    procedure TForm1.DrawCaptButton;
    var
    xFrame,
    yFrame,
    xSize,
    ySize  : Integer;
    R : TRect;
    begin
    //Dimensions of Sizeable Frame
    xFrame := GetSystemMetrics(SM_CXFRAME);
    yFrame := GetSystemMetrics(SM_CYFRAME);

    //Dimensions of Caption Buttons
    xSize  := GetSystemMetrics(SM_CXSIZE);
    ySize  := GetSystemMetrics(SM_CYSIZE);

    //Define the placement of the new caption button
    //next to the existing caption buttons
    CaptionBtn := Bounds(Width - xFrame - 4*xSize + 2,
                          yFrame + 2, xSize - 2, ySize - 4);

    //Get the handle to canvas using Form's device context
    Canvas.Handle := GetWindowDC(Self.Handle);

    Canvas.Font.Name := 'Symbol';
    Canvas.Font.Color := clBlue;
    Canvas.Font.Style := [fsBold];
    Canvas.Pen.Color := clYellow;
    Canvas.Brush.Color := clBtnFace;

    try
       DrawButtonFace(Canvas, CaptionBtn, 1, bsAutoDetect, False, False, False);
       //Define a smaller drawing rectangle within the button
       R := Bounds(Width - xFrame - 4 * xSize + 2,
                          yFrame + 3, xSize - 6, ySize - 7);
       with CaptionBtn do
         Canvas.TextRect(R, R.Left + 2, R.Top - 1, 'W');
    finally
       //Get rid of the device context and set the canvas handle to default
       ReleaseDC(Self.Handle, Canvas.Handle);
       Canvas.Handle := 0;
    end;
    end;

    //This traps the default form painting
    procedure TForm1.WMNCPaint(var Msg : TWMNCPaint);
    begin
    inherited;
    DrawCaptButton;
    end;

    //This traps form activation
    procedure TForm1.WMNCActivate(var Msg : TWMNCActivate);
    begin
    inherited;
    DrawCaptButton;
    end;

    //This traps any text being sent to the window
    procedure TForm1.WMSetText(var Msg : TWMSetText);
    begin
    inherited;
    DrawCaptButton;
    end;

    //This traps when the form's caption bar is hit with a mouse
    procedure TForm1.WMNCHitTest(var Msg : TWMNCHitTest);
    begin
    inherited;
    with Msg do
       if PtInRect(CaptionBtn, Point(XPos - Left, YPos - Top)) then
         Result := htCaptionBtn;
    end;

    //Traps a left-click on the caption bar
    procedure TForm1.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
    begin
    inherited;
    if (Msg.HitTest = htCaptionBtn) then
       ShowMessage('You hit the button on the caption bar');
    end;

    end.
  • Profile
    박지현 2002.07.09 02:18
    감솨함다.. (^^)(__)(^^)
    오늘 하루죙일 뒤진 것을 이제야 봅니다.