Delphi编写变长参数的cdecl函数
文章来自:http://hi.baidu.com/523399/blog/item/f36e2e9b25041fbdc9eaf4c6.html
学过C语言的人都知道,printf的参数是不固定的,这种参数形式叫做变长参数。带有变长参数的函数必须是cdecl调用约定,由函数的调用者来清除栈,参数入栈的顺序是从右到左。printf是根据格式化串中的占位标记来猜测栈中的参数的。以下就用Delphi模拟一个简单的类似printf的函数sprintf。
type
VA_FN = function(const par1, par2{, ...}: Pointer): Integer; cdecl varargs;
procedure CvtInt;
{ IN:
EAX: The integer value to be converted to text
ESI: Ptr to the right-hand side of the output buffer: LEA ESI, StrBuf[16]
ECX: Base for conversion: 0 for signed decimal, 10 or 16 for unsigned
EDX: Precision: zero padded minimum field width
OUT:
ESI: Ptr to start of converted text (not start of buffer)
ECX: Length of converted text
}
asm
OR CL,CL
JNZ @CvtLoop
@C1: OR EAX,EAX
JNS @C2
NEG EAX
CALL @C2
MOV AL,'-'
INC ECX
DEC ESI
MOV [ESI],AL
RET
@
相关文档:
有时需要使用透明控件用于捕获鼠标消息
1.调用Windows2000,xp新的API函数实现这一功能的过程。使用SetLayeredWindowAttributes
2.直接设置控件的alphablend,alphablendvalue,间接调用上述api.
3.使用TStaticText控件
procedure WMCtrlColor(var Message: TWMCtlColor); message WM_CTLCOLOR;
procedure TForm3.WMCtr ......
常用控件命名前缀
控件类名
前缀
TForm等窗体类
frm
TButton, TSpeedButton等所有的按钮类
btn
TCheckBox等所有的检查框
chk
TRadioButton单选按钮类
rdo
TListBox等所有的列表框类
lst
TPanel等所有的面板类
pnl
TLabel, TStaticText等所有用来显示的标签类
lbl
TE ......
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
制作圆角矩形的窗体:
01.procedure TPortForm.FormCreate(Sender: Tobject);
02.var hr :thandle;
03.begin
04.hr:=createroundrectrgn(0,0,width,height,20,20);
05.setwindowrgn(handle,hr,true);
06.end;
如果不要窗体外框,则使用:
01.procedure TPortForm.FormCreate(Sender: Tobject);
02.var hr :thandl ......