1.
function EnumWindowsProc(HWND:hWnd;param
ointer): Boolean; stdcall;
function EnumWindowsProc(HWND: hWnd; param
ointer): Boolean;
var buffer:array[0..255] of Char;
begin
GetWindowText(hWnd,buffer,256);
if StrComp(buffer,PChar(sMark+sIETitle))>0 then //比较标题,如果符合,加到自定义的数组中.这儿的sMark和sIETitle是以前我用来判断IE窗口标题的,你可以改为你自己想要的标题
// if (Length(string(buffer))>0) then
begin
if (giCountWin<256) then
begin
gWinList[giCountWin].HWND:=hWnd;
StrCopy(gWinList[giCountWin].cWinBuf,buffer);
inc(giCountWin);
end;
end;
Result:=True;
end;
2.用FindWindowEx找窗口的控件.不过,先要知道窗口的handle,与上面结合着用.
ahwnd:=findwindowEX(ahwnd,0,pchar('Tbutton'),pchar('确定')); // 找到该窗口上的确定按钮
3.给你一个函数,我用来抓密码的,WIN2000下的密码都跑不掉,当然你也可以用来取得Button的文字了.
function TFrmAbout.GetPassWord: string;
var p:TPoint;
hWnd,PassChar:integer;
buf:array[0..1023] of char;
begin
GetCursorPos(p);
hWnd:=WindowFromPoint(p);
if hWnd<>0 then
begin
PassChar:=SendMessage(hWnd,EM_GetPasswordChar,0,0);
if PassChar<>0 then
begin
PostMessage(hWnd,EM_SetPasswordChar,0,0);
Sleep(50);
SendMessage(hWnd,WM_GetText,1023,Integer(@buf[0]));
SendMessage(hWnd,EM_SetPasswordChar,wparam(PassChar),0);
end else
SendMessage(hWnd,WM_GetText,1023,Integer(@buf[0]));
end;
Result:=string(Buf);
end;