½üÀ´£Ñ£Ñβ°Í²¡¶¾´óËÁ·¢×÷£¬ÎÒÒ²ÊǾ³£ÊÕµ½ÍøÓÑÃÇ·¢µ½À´µÄ´øβ°ÍµÄÏûÏ¢£¬ÓÚÊÇ£¬ºÃÆæÐÄÒ»À´£¬ÎÒÒ²À´Ñо¿Ñо¿´Ë²¡¶¾µÄ·¢×÷ÔÀí¡£Ê×ÏÈ£¬ÎÒ²»ÖªµÀ£Ñ£Ñβ°Í²¡¶¾ÕæÕýµÄÔÀí£¬ÎÒÖ»ÊDz²ⲢÇÒ×Ô¼ºÐ´ÁËÒ»¸öÀàËƵijÌÐòÀ´ÊµÏÖËü¡£ £Ñ£Ñβ°ÍµÄ·¢×÷Çé¿ö£ºµ±Óû§´ò¿ªÒ»¸ö£Ñ£ÑÏûÏ¢·¢ËÍ´°¿Úʱ£¬²¡¶¾»á×Ô¶¯ÍùÏûÏ¢Îı¾¿òÀïÊäÈëÎı¾£¬È»ºó²»µÈÓû§·´Ó¦¹ýÀ´¾Í·¢³öÈ¥ÁË¡£
³ÌÐòʵÏÖ£ºÊ×ÏÈÒªÕÒµ½£Ñ£ÑÏûÏ¢·¢ËÍ´°¿ÚµÄ¾ä±úÒÔ¼°ÏûÏ¢Îı¾¿òÓë¡°·¢ËÍ¡±°´Å¥µÄ´°¿Ú¾ä±ú¡£
Ò»¡¢ ÈçºÎÕÒµ½£Ñ£ÑÏûÏ¢·¢ËÍ´°¿Ú¾ä±ú£º
£Ñ£ÑÏûÏ¢·¢ËÍ´°¿ÚÓÐÁ½ÖÖ£¬Ò»ÖÖÊÇÏûϢģʽ£¬ÔÚÕâÖÖÇé¿öÏ£¬´°¿Ú±êÌ⺬ÓС°·¢ËÍÏûÏ¢¡±×ÖÑù£»Ò»ÖÖÊÇÁÄÌìģʽ£¬´°¿Ú±êÌ⺬ÓС°ÁÄÌìÖС±×ÖÑù£»
ͨ¹ýö¾Ù´°¿Ú¾Í¿ÉÕÒµ½ÏàÓ¦µÄ¾ä±ú£º
// È¡µÃ£Ñ£ÑµÄ·¢ËÍÏûÏ¢´°¿Ú
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;
¶þ¡¢ ÈçºÎÕÒµ½¡°·¢ËÍ¡±°´Å¥´°¿Ú¾ä±ú£º
ÕÒµ½Áˣѣѵķ¢ËÍÏûÏ¢´°¿Úºó£¬¾Í¿ÉÒÔ½øÒ»²½²éÕÒ¡°·¢ËÍ¡±°´Å¥¾ä±úÁË£¬Èç´°¿Ú¾ä±úΪqqWnd£¬Ôò¿ÉÒÔÓÃÒ»¸öÑ»·£¬²éÕÒÎı¾Öк¬ÓС°·¢ËÍ¡±×ÖÑùµÄ´°¿Ú£¬¾¹ýÊÔÑé·¢ÏÖ£¬¡°·¢ËÍ¡±°´Å¥Ç¡Ç¡ÊÇ´°ÌåµÄµÚÒ»¸ö×Ó´°¿Ú£¬ÕâÑù£¬¿ÉÒÔÓÃ
btnWnd:=GetDlgItem(qqWnd,1); // ·¢ËÍ°´Å¥
À´»ñµÃ¡°·¢ËÍ¡±°´Å¥µÄ¾ä±ú¡£
Èý¡¢ ÈçºÎÕÒµ½ÏûÏ¢Îı¾¿ò´°¿Ú¾ä±ú£º
ÏûÏ¢Îı¾¿ò²¢²»ºÃÕÒ£¬²»¹ýÄã¿ÉÒÔÏÈÔÚÏûÏ¢Îı¾¿òÖÐÊäÈ뼸¸ö×Öĸ£¬Èç¡°abcd¡±£¬ÕâÑùÎÒÃǾͿÉÒÔÓÃÉÏÊö·½·¨À´²éÕÒÁË£¬²»¹ýͨ¹ýʵÑéºó£¬·¢ÏÖÏûÏ¢Îı¾¿ò²¢²»ÊǣѣѴ°¿ÚµÄÖ±½Ó×Ó´°¿Ú£¬¶øÊÇÆäÖÐÒ»¸ö×Ó´°¿ÚµÄ×Ó´°¿Ú£¬Í¨¹ýʵÑ飬¿ÉÒÔÓÃ
txtWnd:=GetWindow(GetDlgItem(qqWnd,0),GW_CHILD); // Îı¾¿ò
À´»ñµÃ¡£
ËÄ¡¢ ÈçºÎ»ñµÃÔÏûÏ¢Îı¾¿òµÄÎı¾£º
Òª»ñÈ¡ÔÏûÏ¢Îı¾¿òµÄÎı¾£¬Ö»ÐèÒªÒ»¸ö£Á£Ð£Éº¯Êý¾ÍÐÐÁË£¬ÈçÏ£º
// »ñµÃ´°¿ÚÎı¾
function GetWndText(hWnd: HWND): String;
Var
Ret:LongInt;
mText:PChar;
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:PChar;
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;
Áù¡¢ Èç¹ûÈá°·¢ËÍ¡±°´Å¥×Ô¶¯µã»÷£º
Ò»Çж¼×¼±¸ºÃÁË£¬ÏÖÔÚÒª¿ªÊ¼·¢ËÍÁË£¬ÎªÁËÈÃÏûÏ¢×Ô¶¯·¢ËÍ£¬ÎÒÃÇ¿ÉÒÔÄ£Äâ¡°·¢ËÍ¡±°´Å¥±»µã»÷ÁË¡£
SendMessage(btnWnd,WM_LBUTTONDOWN,MK_LBUTTON,0);
SendMessage(btnWnd,WM_LBUTTONUP,0,0);
ͨ¹ýÄ£ÄâÒ»¸öÊó±êÔÚ¡°¿ªÊ¼¡±°´Å¥Éϵİ´ÏÂÓë·Å¿ª£¬¾ÍʵÏÖÁ˵ã»÷·¢Ë͹¦ÄÜ¡£
Æß¡¢ ÆäËüµÄ¶¨Ê±¹¦ÄܱȽϼòµ¥£¬ÔÚ´ËÒ²²»¶à˵ÁË¡£
°Ë¡¢ È«²¿Ô´´úÂëÈçÏ£º
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// »ñµÃ´°¿ÚÎı¾
function GetWndText(hWnd: HWND): String;
Var
Ret:LongInt;
mText:PChar;
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:PChar;
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 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 TimerProc;
var
qqWnd,txtWnd,btnWnd:HWND;
Msg:String;
begin
qqWnd:=GetQQWnd;
if qqWnd=0 then Exit;
btnWnd:=GetDlgItem(qqWnd,1); // ·¢ËÍ°´Å¥
txtWnd:=GetWindow(GetDlgItem(qqWnd,0),GW_CHILD); // Îı¾¿ò
if (btnWnd=0) or (txtWnd=0) then Exit;
Msg:=GetWndText(txtWnd);
Msg:=Msg+#13+#10+»¶Ó¹âÁÙÂÌÒñÍøhttp://www.lvyin.net;
SetWndText(txtWnd,Msg);
SendMessage(btnWnd,WM_LBUTTONDOWN,MK_LBUTTON,0);
SendMessage(btnWnd,WM_LBUTTONUP,0,0);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
TimerProc;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled :=not Timer1.Enabled;
if Timer1.Enabled then
Button1.Caption :=Í£ Ö¹
else
Button1.Caption :=¿ª ʼ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Interval :=StrToInt(Edit1.Text);
end;
end.
×ܽ᣺ÉÏÃæÖ»½²ÊöÁˣѣÑÏûÏ¢×Ô¶¯·¢Ë͵ÄÖ÷Òª¹¦ÄÜ£¬Õâ»òÐí¸ú£Ñ£Ñβ°ÍµÄÔÀí²»Í¬£¨ÎÒÒ²²»ÖªµÀ£©£¬µ«×ÜÌåÉÏÓ¦¸Ã²î²»¶à¡£Èç¹ûÒª×öµ½ÈÃÓû§¸Ð¾õ²»µ½Òì³££¬¾ÍÒª¸ÄÒ»ÏÂÁË£¬²»Òª×Ô¶¯·¢ËÍ£¬¶øÊÇÔÚµ±Óû§µã»÷ÁË¡°·¢ËÍ¡±°´Å¥ºóÔÙ°ÑÎı¾¼Ó½øÈ¥¡£ÕâÑùµÄ»°¿ÉÊÇÀ¹½Ø¡°·¢ËÍ¡±°´Å¥µÄµã»÷ÏûÏ¢£¬È»ºóÔÙÓÃÉÏÊö·½·¨°ÑÎı¾¼Ó½øÈ¥£¬È»ºó°ÑÏûÏ¢½»»¹Ô³ÌÐò´¦Àí¡£ÖÁÓÚÈçºÎÈÃËü³ÉΪ²¡¶¾£¬»á×ÔÎÒ¸´ÖÆ£¬×ÔÎÒÒþ²ØµÈ¹¦ÄÜ£¬ÄÇÓÖÊÇÁíÍâÒ»¸ö»°ÌâÁË£¬Ôڴ˾Ͳ»¶à½²ÁË¡£ |