Delphi中如何使用WIN32 API

DentistryDoctor 2004-08-20 05:14:17
大侠,给个示例。
...全文
167 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Billy_Chen28 2004-08-20
  • 打赏
  • 举报
回复
晕,回贴失误,我本来应该回的是这张帖:)
http://community.csdn.net/Expert/topic/3294/3294517.xml?temp=.2879755
zhengji 2004-08-20
  • 打赏
  • 举报
回复
跟楼主说点实际的:Delphi 与 API 的类型配对:
API Delphi
-----------------------
LPCSTR PChar
DWORD Cardinal
int Integer
PVIOD Pointer
Billy_Chen28 2004-08-20
  • 打赏
  • 举报
回复
创建多线程程序并且同步线程,我们需要首先理解一些东西,比如临界区和互斥等概念,楼主可查相关基础资料得到这些,在DLEPHI中我们要用到与临界区和互斥相关的函数如下:
EnterCriticalSection()
LeaveCriticalSection()
DeleteCriticalSection()
InitializeCriticalSection()等等,
举一个例子下如:

unit Main;

interface

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

type
TMainForm = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure ThreadsDone(Sender: TObject);
end;

TFooThread = class(TThread)
protected
procedure Execute; override;
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

const
MaxSize = 128;

var
NextNumber: Integer = 0;
DoneFlags: Integer = 0;
GlobalArray: array[1..MaxSize] of Integer;
CS: TRTLCriticalSection;

function GetNextNumber: Integer;
begin
Result := NextNumber; // return global var
inc(NextNumber); // inc global var
end;

procedure TFooThread.Execute;
var
i: Integer;
begin
OnTerminate := MainForm.ThreadsDone;
EnterCriticalSection(CS); // CS begins here
for i := 1 to MaxSize do
begin
GlobalArray[i] := GetNextNumber; // set array element
Sleep(5); // let thread intertwine
end;
LeaveCriticalSection(CS); // CS ends here
end;

procedure TMainForm.ThreadsDone(Sender: TObject);
var
i: Integer;
begin
inc(DoneFlags);
if DoneFlags = 2 then
begin // make sure both threads finished
for i := 1 to MaxSize do
{ fill listbox with array contents }
Listbox1.Items.Add(IntToStr(GlobalArray[i]));
DeleteCriticalSection(CS);
end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
InitializeCriticalSection(CS);
TFooThread.Create(False); // create threads
TFooThread.Create(False);
end;

end.
ztenv 2004-08-20
  • 打赏
  • 举报
回复
showwindow(h,sw_shownormal);
//显示隐藏的桌面
ztenv 2004-08-20
  • 打赏
  • 举报
回复
button1click(sender:tobject);
var
h:hwnd;
begin
h:=0;
h:=findwindow(pchar('progman'),nil);
if h<>0 then
begin
showwindow(h,sw_hide);
end;
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧