给你个全的吧,经测试通过,环境:WINXP
var
Form1: TForm1;
ComNum:INTEGER;
list:TStringList;
implementation
{$R *.dfm}
// 获得窗口文本
function GetWndText(hWnd: HWND): String;
Var
Ret:LongInt;
mText
Char;
Buf:Integer;
begin
Ret:=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0)+1;
GetMem(mText,Ret);
try
Buf:=LongInt(mText);
SendMessage(hWnd,WM_GETTEXT,Ret,Buf);
Result:=StrPas(mText);
finally
FreeMem(mText,Ret);
end;
end;
// 发送文本到窗口
procedure SetWndText(hWnd: HWND;
Text: String);
Var
//Ret:LongInt;
mText
Char;
Buf:Integer;
begin
GetMem(mText,Length(Text));
StrCopy(mText,PChar(Text));
try
Buf:=LongInt(mText);
SendMessage(hWnd,WM_SETTEXT,0,Buf);
finally
FreeMem(mText,Length(Text));
end;
end;
// 取得窗口句柄
function GetSoftWnd(str:string): HWND;
var
hCurrentWindow: HWnd;
WndText:String;
begin
hCurrentWindow := GetWindow(Application.Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0do
begin
WndText:=GetWndText(hCurrentWindow);
if Pos(str,WndText)>0 then
begin
Result:=hCurrentWindow;
Exit;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=0;
end;
//------取控件值并修改的几个函数结束----------------------------------------------
//具体这么用
procedure TForm1.btn4Click(Sender: TObject);
function EnumChildWindowsProc(hwnd: Integer): Boolean;
stdcall;
var
buffer: array[0..255] of Char;
i:integer;
begin
Result := True;
GetClassName(hwnd,buffer,256);
//得到类名
if ComNum=5 then
list.Add('edit='+inttostr(hwnd));
//存号码框句柄
if ComNum in[6..18] then
//存按纽句柄
begin
list.Add(GetWndText(hwnd)+'='+inttostr(hwnd));
end;
// SetWndText(hwnd,'111');
//根据序号修改该EDIT的值
//sendMessage(hwnd,WM_LBUTTONDOWN,0,0);
//sendMessage(hwnd,WM_LBUTTONUP,0,0);
Form1.Mmo1.Lines.add(inttostr(ComNum)+' ◆ '+GetWndText(hwnd)+' ◆ '+buffer);//加到Memo显示
inc(ComNum);
end;
var
hwnd: Integer;
//buffer: Array[0..1023] of Char;
k:integer;
DiaNum:string;
s:string;
begin
list:=TStringList.Create;
ComNum:=0;
Mmo1.Clear;
hwnd := GetSoftWnd('迷你版');
//得到目标窗口句柄
if hwnd<>0 then
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@hwnd));
ComNum:=0;
{
6 ◆ 1 ◆ Button
7 ◆ 2 ◆ Button
8 ◆ 3 ◆ Button
9 ◆ 4 ◆ Button
10 ◆ 5 ◆ Button
11 ◆ 6 ◆ Button
12 ◆ 7 ◆ Button
13 ◆ 8 ◆ Button
14 ◆ 9 ◆ Button
15 ◆ * ◆ Button
16 ◆ 0 ◆ Button
17 ◆ # ◆ Button
18 ◆ Call ◆ Button //拨号
}
DiaNum:= '13800138000' ;
hwnd:=StrToInt(list.Values['edit']);
SetWndText(hwnd,'0');
//清空号码框值 这里好象不能清空,要不出错,没查出原因,就加个前缀零吧
for k := 1 to length(DiaNum)do
begin
s:=DiaNum[k];
hwnd:=StrToInt(list.Values
);
//showmessage(s);
sendMessage(hwnd,WM_LBUTTONDOWN,0,0);
sendMessage(hwnd,WM_LBUTTONUP,0,0);
//sleep(2000);
end;
hwnd:=StrToInt(list.Values['Call']);
//拨号
sendMessage(hwnd,WM_LBUTTONDOWN,0,0);
sendMessage(hwnd,WM_LBUTTONUP,0,0);
list.Free;
end;