zoukankan      html  css  js  c++  java
  • delphi线程的创建、挂起、激活与终止(用绘图做实验,简单又好用)

    unit Unit1;

    interface

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

    type
    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    hThread:Thandle;//定义一个句柄
    ThreadID:DWord;
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}
    function MyThreadFunc(P:pointer):Longint;stdcall;
    var
    i:longint;
    DC:HDC;
    S:string;
    begin
    DC:=GetDC(Form1.Handle);
    for i:=0 to 500000 do begin
    S:=Inttostr(i);
    Textout(DC,10,10,Pchar(S),length(S));
    end;
    ReleaseDC(Form1.Handle,DC);
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    //创建线程,同时线程函数被调用
    hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    SuspendThread(hThread); //挂起线程
    end;

    procedure TForm1.Button3Click(Sender: TObject);
    begin
    ResumeThread(hThread); // 激活线程
    end;

    procedure TForm1.Button4Click(Sender: TObject);
    begin
    TerminateThread(hThread,0); // 终止线程
    end;

    end.

    http://blog.csdn.net/cmdasm/article/details/10003493

  • 相关阅读:
    python编码小记
    eventlet学习笔记
    python库文件路径
    paste deploy初探
    python浅拷贝与深拷贝
    Javascript basic knowledge
    用大数据学习心理学
    Postgres Database management operations
    Python Socket and WSGI Sample
    Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory错误处理
  • 原文地址:https://www.cnblogs.com/findumars/p/5789409.html
Copyright © 2011-2022 走看看