(2)Me根本不懂OOP-----想读《D4技术内幕》么?follow me(25分)

  • 主题发起人 千中元
  • 开始时间

千中元

Unregistered / Unconfirmed
GUEST, unregistred user!
请看下面代码:P107
1)function ThreadFunc(P: Pointer): LongInt
stdcall;
2)var
3) i: Integer;
4) DC: HDC;
5) S: string;
6)begin
7) DC := GetDC(Form1.Handle);
8) SetBkColor(DC, GetSysColor(color_btnface));
9) for i := 0 to 100000 do begin
10) S := IntToStr(i);
11) TextOut(DC, 10, 10, PChar(S), Length(S));
12) end;
13) ReleaseDC(Form1.Handle, DC);
14)end;

15)procedure TForm1.bUseThreadClick(Sender: TObject);
16)var
17) hThread: THandle;
18) ThreadID: DWord;
19)begin
20) hthread := CreateThread(nil, //Security attribute
0, //Initial Stack
@ThreadFunc, //Starting address of thread
nil, // argument of thread
0, // Create flags
ThreadID)
// thread ID

21) if hthread = 0 then
22) MessageBox(Handle, 'No Thread', nil, MB_OK);
end;

23)procedure TForm1.bNoThreadClick(Sender: TObject);
begin
24) ThreadFunc(nil);
end;
问题1:stdcall的作用---别告诉我看帮助,看了两遍不知道说什么:(
问题2:HDC数据类型???
问题3:Form1.Handle
hThread:Thandle
-----Handle 到底是什么?
问题4:Pchar()的作用。
问题5:帮助中:Textout如下:
procedure TextOut(X, Y: Integer
const Text: string);
这里怎么可以用5个参数?(见第11行)


 
1.我也不清楚
2.HDC是Windows绘图句柄,用过要立即释放
3.Handle是窗体句柄(就是指针)
4.PChar将Pascal字符串转换为C字符串
5.此TextOut为API函数
 
4.字符串指针,常用与windows api
 
C字符串与字符串指针有何不同,原听赐教
 
LeeChange,
》HDC是Windows绘图句柄,用过要立即释放
请问:DC:HDC 怎么解释?
句柄和数据类型有什么区别呢?
Textout(DC,10,10,Pchar(S),Length(S));的各参数什么意思?

 
DC是句柄,HDC是句柄类型
 
其实我也不是很明白 :)
1.使用StdCall指令,可以使调用模块与被调用模块使用相同的参数传递约定。

想问一下LeeChange如何得到屏幕上窗体的Handle(不仅仅是一个应用程序的).
 
1 C 的调用方式 (从右向左入堆栈)
2 HDC 是一个HANDLE 无符号整型
3 handle 是系统用来标识一个对象的一个无符号整数
一个Handle唯一对应一个系统对象(如窗体,线程,进程,DC...)
4 pchar将Pascal字符串转换为C字符串(0结尾,API用的是这种字符串)
4 帮助中textout是TCanvas的方法之一
程序中用的是 API

 
Handle:=FindWindow(lpClassName,lpWindowName);
API函数,不过得知道窗体的标题
 
wrench,
这里为什么用stdcall? 一般什么时候用?
 
调API,调DLL 中的过程还有COM的方法时
 
to wrench,
When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall
stdcall 是这几个里之一,这里为什么用stdcall不用 safecall,cdecl...
(我过的四级白搭了,连帮助都看不明白)
 
以后出本《内幕注释》
 
1.stdcall表明应用程序和Dll使用相同的参数传递约定
(见Delphi4从入门到精通)
2.Windows 用DC(device context设备描述表)来提供输出设备的资源共享,
HDC是DC的句柄。
3.可以把句柄想象成一个指针,通过它来获得窗口的访问
4.Pchar是一个指向零字符结尾字串的指针,一般用在API函数里。
5.你应该看Windows SDK里的帮助,可以查到TextOut API
 
我还没过四级呢,哼哼

Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
参数通过寄存器传递,速度快,左到右传递
pascal Left-to-right Routine No
传统的Pascal 参数传递方法 ,左到右传递(Turbo Pascal 的处理方法)
cdecl Right-to-left Caller No
C的参数传递方法 ,右到左传递,从函数返回时会将参数从堆栈中清空
其他的方式不会,这是ANSI C的处理方式
stdcall Right-to-left Routine No
除了不清空堆栈,同CDECL

safecall Right-to-left Routine No
在stdcall的基础上加上了COM错误和异常的处理

为什么用这个,因为API是用C写的,用的就是Stdcall
所以。。。
 
那么长看到一般就蓝的看了,呵呵
好象只有HDC没解决?
HDC = type LongWord;
 
》好象只有HDC没解决?
CJ,我用F7跟踪 ,到Tform.bUsethreadclick 时候死机了!!!
是不是多线程不能用F7?
如果不能,该怎样调试?
 
handle, 就象 id 一样,只可意会不可言传。
 
SupperMMX,太玄乎了吧。。。。
 
function ThreadFunc(P: Pointer): LongInt
stdcall;
=======想自己再写一遍才发现个问题:为什么线程函数的参数是 pointer?而函数内部的语句中再也没出现过pointe类型的?
ThreadFunc(nil),nil是pointer???

 

Similar threads

I
回复
0
查看
635
import
I
I
回复
0
查看
707
import
I
I
回复
0
查看
700
import
I
I
回复
0
查看
581
import
I
顶部