zoukankan      html  css  js  c++  java
  • c++builder自定义控件

    c++builder自定义控件

    http://docwiki.embarcadero.com/CodeExamples/XE8/en/RegisterComponents_%28C%2B%2B%29

    void __fastcall SetFocusControl(TWinControl* Value);
        void __fastcall CMDialogChar(TWMKey& Message);
        void __fastcall CMTextChanged(TMessage& Message);
     
    protected:
        virtual void __fastcall Notification(TComponent* AComponent, TOperation Operation);
        virtual void __fastcall Paint(void);
     
    public:
        __fastcall virtual TDemoLabel(TComponent* AOwner);
     
    __published:
        __property Caption ;
        __property Color ;
        __property TWinControl* FocusControl = {read=FFocusControl, write=SetFocusControl, nodefault};
        __property Font ;
        __property ParentColor ;
        __property ParentFont ;
    public:
        __fastcall virtual ~TDemoLabel(void) { }
     
    BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(CM_DIALOGCHAR, TWMKey, CMDialogChar);
      MESSAGE_HANDLER(CM_TEXTCHANGED, TMessage, CMTextChanged);
    END_MESSAGE_MAP(TGraphicControl);
    };
    
    
    void __fastcall PACKAGE Register()
    {
      TComponentClass classes[1] = {__classid(TDemoLabel)};
      RegisterComponents("Samples", classes, 0);
      RegisterComponents("MySystem", classes, 0);
    }
     
    __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
        TGraphicControl(AOwner)
    {
      FComponentStyle >> csInheritable;
      Width=64;
      Height=13;
    }
     
    void __fastcall    TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
    {
      TGraphicControl::Notification(AComponent, Operation);
      if ((Operation == opRemove)  && (AComponent == FFocusControl))
        FFocusControl = 0;
    }
     
    void __fastcall    TDemoLabel::SetFocusControl(TWinControl *Value)
    {
      FFocusControl = Value;
     
      // Calling FreeNotification ensures that this component 
      // will receive an opRemove when Value is either removed 
      // from its owner or destroyed.
     
      Value->FreeNotification(Value);
    }
     
    void __fastcall    TDemoLabel::Paint()
    {
      TRect    Rect = ClientRect;
      Canvas->Font = Font;
      Canvas->Brush->Color = Color;
      Canvas->FillRect(Rect);
      DrawText(
        Canvas->Handle,
        Caption.t_str(),
        Caption.Length(),
        &Rect,
        DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
    }
     
    void __fastcall    TDemoLabel::CMDialogChar(TCMDialogKey &Message)
    {
      if (FFocusControl != NULL &&
          Enabled == true &&
          IsAccel(Message.CharCode, Caption))
          if (FFocusControl->CanFocus()){
            FFocusControl->SetFocus();
            Message.Result = 1;
          }
    }
     
    void __fastcall    TDemoLabel::CMTextChanged(TMessage &Message)
    {
      Invalidate();
    }
  • 相关阅读:
    SMTP 服务器要求安全连接或客户端未通过身份验证的各个解决方案(C#)
    远程数据同步的三种方法
    粗俗易懂的SQL存储过程在.NET中的实例运用之二
    SSIS脚本组件的代码
    浅谈C# StackTrace 类的实例说明
    解决了:无法加载文件或程序集'stdole, Version=7.0.3300.0'
    收藏: .NET中类型的转换
    WCF 实例 —— Android 短信助手 (WCF + Android)
    粗俗易懂的SQL存储过程在.NET中的实例运用
    此发送邮件的代码对吗?
  • 原文地址:https://www.cnblogs.com/cb168/p/4643916.html
Copyright © 2011-2022 走看看