下面的程序在此控件重绘时会引起系统变慢死机.
请告诉我错在哪里谢谢:)Unit QMTextEdits;InterfaceUses
  SysUtils,Classes,Controls,Windows,Messages;Type
  QMBorderStyle=(bsNone,bsLine,bs3D);
  TQMTextEdit=Class(TWinControl)
    Private
      bsBorderStyle:QMBorderStyle;
      Procedure WritebsBorderStyle(Value:QMborderStyle);
      Procedure DrawBorderStyle();
    Public
      Constructor Create(AOwner:TComponent);Override;
      procedure PaintHandle(var Msg:TWMPaint);Message WM_Paint;
    Published
      Property BorderStyle:QMBorderStyle Read bsBorderStyle Write WritebsBorderStyle;
  End;Procedure Register;Implementation
  Procedure Register();
  Begin
    RegisterComponents('Quick Maker',[TQMTextEdit]);
  End;  {START - Define Functions of QMTextEdit of class}
  Constructor TQMTextEdit.Create(AOwner:TComponent);
  Begin
    Inherited Create(AOwner);
    bsBorderStyle:=bs3D;
  End;
  Procedure TQMTextEdit.WritebsBorderStyle(Value:QMBorderStyle);
  Begin
    bsBorderStyle:=Value;
  End;
  Procedure TQMTextEdit.DrawBorderStyle();
  Var
    ConHDC:HDC;
  Begin
    case bsBorderStyle Of
      bsNone:
        Begin
        End;
      bsLine:
        Begin
        End;
      bs3D:
        Begin
          conHDC:=GetDc(Handle);
          Rectangle(conHDC,10,10,20,20);
        End;
    End;
  End;
  Procedure TQMTextEdit.PaintHandle(var msg:TWMPaint);
  Begin
    //Inherited Repaint();
    DrawBorderStyle();
  End;
  {End   - Define Functions of QMTextEdit of class}
End.

解决方案 »

  1.   

    重写过Paint函数?
    TWinControl类没有Paint函数啊!
    大哥请问怎样写?
    50分都给你.
      

  2.   

    你的代码有两个地方需要改进:
    (1)在Rectangle(ConHDC, 10, 10, 20, 20)之后,应当加入:
        ReleaseDC(Handle, ConHDC);
    来释放掉由GetDC取得的系统资源;你没有释放掉,再加上这段代码实在WM_PAINT消息的处理过程中的,自然会很快的消耗系统资源。
    (2)在PaintHandle()消息处理过程中,最好在DrawBorderStyle()前加入
        inherited;
    用以执行Windows需要的那些默认代码(由VCL实现的),这样有助于控件更加稳定。最后,希望你使用VCL对消息过程的命名习惯,这样比较好,即:
    procedure WMPaint(var AMsg: TWMPaint); message WM_PAINT;最好不使用类似于PaintHandle这样的函数名。
      

  3.   

    TommyTong(童童--#改变、突破#) 把我要说的基本上说完了。补充一下,在处理WM_PAINT消息的时候,它的参数会把HDC传进来,
    你就不用自己去GetDC和ReleaseDC了...
      

  4.   

    TWMPaint = packed record
      Msg: Cardinal;
      DC: HDC;
      Unused: Longint;
      Result: Longint;
    end;呵呵,就是就是~