|
|
|
|
||
教学课题:SPY++ 结合Delphi7.0利用API函数FindWindow实现取“计算器”窗口句柄
教学目标:用Delphi7.0编程坏境,以计算器为例模拟鼠标输入QQ号:854487915
教学步骤:1、认识API函数:FindWindow,返回值类型:整数型。执行成功返回窗口句柄,否则返回0;参数1类型:字符型,目标窗口的窗口类名;参数2类型:字符型,目标窗口的窗口名称或称标题。函数原型:
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name 参数1:目标窗口的窗口类名
LPCTSTR lpWindowName // pointer to window name 参数2:目标窗口的窗口名称或称标题
);
2、认识Delphi函数:IntToHex,返回值类型:字符型(16进制),函数执行成功返回指定十进制数值的十六进制字符串型;参数1类型:整数型(Integer),目标数值的十进制数值;参数2类型:整数型(Integer),指定使用多少位来显示十六进制数据。函数原型:
function IntToHex(
Value: Integer; //参数1:要转换的十进制数值
Digits: Integer //参数2:使用多少位来显示十六进制数据
): string;
教学源码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
lb1: TLabel;
edt1: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
ck_hwnd:HWND;
begin
ck_hwnd:=FindWindow('SciCalc','计算器');
edt1.Text := IntToHex(ck_hwnd,8);
end;
end.