L
lovenuo
Unregistered / Unconfirmed
GUEST, unregistred user!
理解不了,有朋友能给解释,一下吗,最好详细一点!
function GetWndText(hWnd: HWND): String;
var
Ret:LongInt;
mTextChar;
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;
function GetQQWnd: HWND;
var
hCurrentWindow: HWnd;
WndText:String;
begin
hCurrentWindow := GetWindow(Application.Handle, GW_HWNDFIRST); //顶级窗口
while hCurrentWindow <> 0 do
begin
WndText:=GetWndText(hCurrentWindow); //找到
if (Pos(Chr(13),WndText)>0) or (Pos(Chr(10),WndText)>0) then //查找目标
begin
Result:=hCurrentWindow;
Exit;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=0;
end;
function GetWndText(hWnd: HWND): String;
var
Ret:LongInt;
mTextChar;
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;
function GetQQWnd: HWND;
var
hCurrentWindow: HWnd;
WndText:String;
begin
hCurrentWindow := GetWindow(Application.Handle, GW_HWNDFIRST); //顶级窗口
while hCurrentWindow <> 0 do
begin
WndText:=GetWndText(hCurrentWindow); //找到
if (Pos(Chr(13),WndText)>0) or (Pos(Chr(10),WndText)>0) then //查找目标
begin
Result:=hCurrentWindow;
Exit;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=0;
end;