您的位置:首页 > 编程语言 > Delphi

Delphi程序流程三(1)(while)PS:顺便写了个最简单的任务管理器(包含申明API 自己申明参数为结构型API 组件LISTVIEW的用法)

2013-06-19 00:57 591 查看
unit Unit1;

interface

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

type
TForm1 = class(TForm)
btn1: TButton;
ListView: TListView;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
newitem:TListItem; //超级列表框一定要在这里申明 不知道为什么
//一个程序只用一次就可以了,放在按纽事件里有BUG  坑爹的

implementation
type
Snapshot32=record //记录类型的名称
A1:Integer;
A2:Integer;
A3:Integer;
A4:Integer;
A5:Integer;
A6:Integer;
A7:Integer;
A8:Integer;
A9:Integer;
A10:array[0..259]of char;
end;

function CreateToolhelp32Snapshot(x,y: Integer): Integer;
stdcall; external 'kernel32.dll' name 'CreateToolhelp32Snapshot';
function Process32Next(x:Integer;VAR y: Snapshot32): Integer;
stdcall; external 'kernel32.dll' name 'Process32Next';
function Process32First(x:Integer;VAR y: Snapshot32): Integer;
stdcall; external 'kernel32.dll' name 'Process32First';
function CloseHandle(x:Integer): Integer;
stdcall; external 'kernel32.dll' name 'CloseHandle';

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var i,x:Integer;
m:string;
k:Snapshot32;
begin
ListView.Clear;
i:=CreateToolhelp32Snapshot(2,0);
k.A1:=1024;
x:=Process32First(i,k) ;
while x<>0 do
begin
newitem:=Listview.Items.Add;    //要在循环里放入这个 否则他一直加入的是第
//一行   理解的是 超级列表框添加一行 返回新的行数  下面是新行数的标题 和新
//行数的列添加
//循环后再一次添加新一行 ,返回新的行数………依次这样
//超级列表框增加列表项目在 属性 Columns 里设置 然后必须要把属性ViewStyle
//设置为vsreport
newitem.Caption:=k.A10;
newitem.SubItems.Add(IntToStr(k.A3));
x:=Process32Next(i,k);
end;
CloseHandle(x);
end;

end.


最简单的几个API 几分钟就可以写起 却在Listview的属性上花了太多时间 界面编程 最好用 最人性化的还是易语言 不说了 都是泪
算是第一个W32程序吧 截图留个纪念



参考书目:Delphi组件大全PDF及源代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐