各位高手,最近可用分没见长大家不要闲小弟吝啬啊!下面是我在Delphi编程技术内幕一书中遇到的一段代码,有些地方看不大明白,请高人指点!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
UseThread: TButton;
NoThread: TButton;
procedure UseThreadClick(Sender: TObject);
procedure NoThreadClick(Sender: TObject); end;var
Form1: TForm1;implementation{$R *.dfm}
function ThreadFunc(p:Pointer):Longint;stdcall; //这里的函数没有声明,
//为什么声明了反而出错
var
i:integer;
DC:HDC;//这个变量是干什么用的?
s:string;
begin
DC:= GetDC(Form1.Handle);//这里又是什么意思?
for i:=0 to 1000000 do
begin
s:=inttostr(i);
TextOut(DC,10,10,Pchar(s),Length(s));//看F1帮助TextOut里面好像不是这样用的(里面的参数没有DC啊!)
end;
releaseDC(Form1.Handle,DC);
end;
procedure TForm1.UseThreadClick(Sender: TObject);
var
hThread:THandle;
ThreadID:DWord;
begin
hThread:=CreateThread(nil,0,@ThreadFunc,nil,0,threadID);
if hthread = 0 then
MessageBox(Handle,'no thread',nil,MB_OK);
end;procedure TForm1.NoThreadClick(Sender: TObject);
begin
ThreadFunc(nil);//这里又是什么意思呢?是不是将ThreadFunc的内存分配指针为空,这样调用ThreadFunc就没有创建线程?
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
UseThread: TButton;
NoThread: TButton;
procedure UseThreadClick(Sender: TObject);
procedure NoThreadClick(Sender: TObject); end;var
Form1: TForm1;implementation{$R *.dfm}
function ThreadFunc(p:Pointer):Longint;stdcall; //这里的函数没有声明,
//为什么声明了反而出错
var
i:integer;
DC:HDC;//这个变量是干什么用的?
s:string;
begin
DC:= GetDC(Form1.Handle);//这里又是什么意思?
for i:=0 to 1000000 do
begin
s:=inttostr(i);
TextOut(DC,10,10,Pchar(s),Length(s));//看F1帮助TextOut里面好像不是这样用的(里面的参数没有DC啊!)
end;
releaseDC(Form1.Handle,DC);
end;
procedure TForm1.UseThreadClick(Sender: TObject);
var
hThread:THandle;
ThreadID:DWord;
begin
hThread:=CreateThread(nil,0,@ThreadFunc,nil,0,threadID);
if hthread = 0 then
MessageBox(Handle,'no thread',nil,MB_OK);
end;procedure TForm1.NoThreadClick(Sender: TObject);
begin
ThreadFunc(nil);//这里又是什么意思呢?是不是将ThreadFunc的内存分配指针为空,这样调用ThreadFunc就没有创建线程?
end;end.
解决方案 »
- 代码错在哪里? 用Delphi编写将EXCEL远程导入SQL SERVER
- 高手来帮个忙,好吗?
- 我根据需要在form的panel上动态创建一些button组件(数量不定),如何确定每个组件的点击事件?
- 怎样得到本地打印机\网络打印机的打印消息?(N多分相送)
- 模拟按键及取窗体的Windows Caption
- 用Delphi在SQL Server2000中存放文件与图片的问题
- 很简单的问题,马上给分
- SQL2000的问题,在连接过程中出现 SQLQuery1:opertion not allowed on a unidirectional Dataset1
- 急高分求汉字字库编码,delphi环境下的。
- 长整数处理问题
- 介绍几本Dephi的经典书籍
- dickeybird888请进。.
老大,你没看清楚吧?stdcall,还要怎么声明啊?
2.HDC = type LongWord
The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window. The display device context can be used in subsequent GDI functions to draw in the client area of the window. This function retrieves a common, class, or private device context depending on the class style specified for the specified window. For common device contexts, GetDC assigns default attributes to the device context each time it is retrieved. For class and private device contexts, GetDC leaves the previously assigned attributes unchanged.
3。BOOL TextOut( HDC hdc, // handle of device context
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // address of string
int cbString // number of characters in string
);第一个参数就是,你怎么看的帮助啊??
4 ThreadFunc写的好像有问题啊!楼主你保证没写错嘛?传入参数q根本没用到啊?
//在这里申明的函数是全局的。也就是说。这个函数是在这里被申明的。
..
function ThreadFunc(p:Pointer):Longint;stdcall; //这里的函数没有声明,
//为什么声明了反而出错DC:HDC;//这个变量是干什么用的?
//////
用过C++你就知道这个是什么东西了。“设备描述符”,比如一个绘画场景的HANDLE。CANVAS.Handle........
///////////
DC:= GetDC(Form1.Handle);//这里又是什么意思?
可以猜到接下来的代码里应该是要在FORM上绘画。。
/////
TextOut(DC,10,10,Pchar(s),Length(s));//看F1帮助TextOut里面好像不是这样用的(里面的参数没有DC啊!)
你知道有CANVAS。TEXTOUT();这个方法的本质就是这个API。textout;你可以去看SDK HELP里它的说明。//////////
ThreadFunc(nil);//这里又是什么意思呢?
这里我看不懂,这个函数不全,没有返回值,没有看到参数的使用情况,猜不到想干什么。
var
hThread:THandle;
ThreadID:DWord;
begin,@ThreadFunc
hThread:=CreateThread(nil,0,@ThreadFunc,nil,0,threadID);//那这里的 @ThreadFunc是怎么回事?
if hthread = 0 then
MessageBox(Handle,'no thread',nil,MB_OK);
end;
这些东西都是windows的API即使是Delphi编程也要对系统API很熟悉