Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->Delphi ->正文

从实作标题栏按钮开始浅谈组件的制作

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-05 点击: [收藏] [投稿]

  end;

 

procedure Register;

 

implementation

 

procedure Register;

begin

  RegisterComponents('Liao', [TTitleBarButton]);

end;

 

{ TTitleBarButton }

 

constructor TTitleBarButton.Create(AOwner: TComponent);

var

  ptr: Pointer;

begin

  inherited;

  FForm := GetParentForm(TControl(AOwner));

  FGlyph := TBitmap.Create;

  FColor := clBtnFace;

  FVisible := False;

  FRightMargin := 66;

  FButtonDown := False;

  FOldWndProc := Pointer(GetWindowLong(FForm.Handle,GWL_WNDPROC));

  ptr := MakeObjectInstance(NewWndProc);

  SetWindowLong(FForm.Handle, GWL_WNDPROC, Longint(ptr));

end;

 

destructor TTitleBarButton.Destroy;

begin

  if not (csDestroying in FForm.ComponentState) then

  begin

    SetVisible(false);

    SetWindowLong(FForm.Handle, GWL_WNDPROC, LongInt(FOldWndProc));

  end;

  FGlyph.Free;

  inherited;

end;

 

procedure TTitleBarButton.NewWndProc(var message: TMessage);

 

  function HitButton(APoint: TPoint): Boolean;

  begin

    APoint.x := APoint.x - FForm.Left;

    APoint.y := APoint.y - FForm.Top;

    Result := PtInRect(BoundsRect,APoint);

  end;

 

var

  p: TPoint;

begin

  with message do

  begin

    if Visible then

    begin

      case Msg of

        WM_NCPAINT , WM_NCACTIVATE :

          begin

            Result := CallWindowProc(FOldWndProc,FForm.Handle,Msg,WParam,LParam);

            RePaint;

          end;

        WM_NCHITTEST :

          begin

            Result := CallWindowProc(FOldWndProc,FForm.Handle,Msg,WParam,LParam);

 

            if Result = HTCAPTION then

            begin

              RePaint;

              p.x := LoWord(LParam);

              ScreenToClient(FForm.Handle,p);

              with BoundsRect do                  //减去框架宽度

                if (p.x >= Left-4) and (p.x <= Right-4) then Result := 888;

            end;

          end;

        WM_NCLBUTTONDOWN,WM_NCLBUTTONDBLCLK:

          begin

            Result := CallWindowProc(FOldWndProc,FForm.Handle,Msg,WParam,LParam);

            with TWMNCLButtonDown(message) do

              if not HitButton(Point(XCursor, YCursor)) then Exit;

 

            if WParam = 888 then

            begin

              FButtonDown := True;

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:“98五笔字型输入法”大批量造词   下一篇:如何把数据库的内容写入到Word文档中?

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号