zoukankan      html  css  js  c++  java
  • BeginPaint和GetDC的区别

    BeginPaint和GetDC的区别

    代码
    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm1
    = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    protected
    procedure WndProc(var Message:TMessage); override;
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    { TForm1 }

    procedure TForm1.WndProc(var Message: TMessage);
    var
    DC: HDC;
    Str: String;
    PS: tagPaintStruct;
    begin
    if Message.Msg = WM_PAINT then
    begin
    Str :
    = 'Hello Ming.';
    DC :
    = BeginPaint(self.Handle,PS);
    TextOut(DC,
    0,0,PChar(Str),Length(Str));
    EndPaint(Self.Handle,PS);
    end;
    inherited;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    DC: HDC;
    Str: String;
    PS: tagPaintStruct;
    begin
    Str :
    = 'Hello Ming.';
    DC :
    = GetWindowDC(Self.Handle);//GetDC(0); 0:Desktop
    TextOut(DC,
    0,0,PChar(Str),Length(Str));
    ReleaseDC(Self.Handle,DC);
    //ReleaseDC(0,DC); 0:Desktop
    { TODO :
    下面的代码并不能实现输出,BeginPaint,EndPaint只能在窗体过程中的WM_PAINT中使用.
    BeginPaint()和EndPaint()可以删除消息队列中的WM_PAINT消息,并使无效区域有效.
    GetDC()和ReleaseDC()并不删除也不能使无效区域有效,因此当程序跳出WM_PAINT 时,
    无效区域仍然存在.系统就回不断发送WM_PAINT消息,于是程序不断处理WM_PAINT消息.
    }
    {
    DC := BeginPaint(self.Handle,PS);
    TextOut(DC,0,0,PChar(Str),Length(Str));
    EndPaint(Self.Handle,PS);
    }
    end;

    end.

  • 相关阅读:
    如何使用EF?
    在一般处理程序中使用session
    C# base64 加密解密
    C#操作WMI文章汇总
    ASP.NET图片防盗链(使用一般处理程序)
    前台生成验证码
    .正则
    iframe标签的初试
    sqli-labs5-10(全程sqlmap)
    sql注入文件写入和读取
  • 原文地址:https://www.cnblogs.com/Jekhn/p/1918675.html
Copyright © 2011-2022 走看看