L
lhandyl
Unregistered / Unconfirmed
GUEST, unregistred user!
这段程序能够找到QQ聊天窗口的句柄,但是却找不到文本框的句柄,是不是qq2005的消息框又改了?
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('聊天中',WndText)>0) or (Pos('发送消息',WndText)>0) then
begin
Result:=hCurrentWindow;
Exit;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=0;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
qqWnd,txtWnd,btnWnd:HWND;
Msg:String;
begin
qqWnd:=GetQQWnd;
if qqWnd=0 then
begin
memo1.Lines.Add('没有找到窗口!');
Exit;
end;
txtWnd:=Findhwd(qqWnd);
if (txtWnd=0) then
begin
memo1.Lines.Add('没有找到文本框!');
Exit;
end;
Msg:=GetWndText(txtWnd);
memo1.Lines.Add(Msg);
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('聊天中',WndText)>0) or (Pos('发送消息',WndText)>0) then
begin
Result:=hCurrentWindow;
Exit;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
Result:=0;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
qqWnd,txtWnd,btnWnd:HWND;
Msg:String;
begin
qqWnd:=GetQQWnd;
if qqWnd=0 then
begin
memo1.Lines.Add('没有找到窗口!');
Exit;
end;
txtWnd:=Findhwd(qqWnd);
if (txtWnd=0) then
begin
memo1.Lines.Add('没有找到文本框!');
Exit;
end;
Msg:=GetWndText(txtWnd);
memo1.Lines.Add(Msg);
end;