QQ chat robot Delphi code

QQ chat robot
 
 
A few days ago, I saw an article about the development of the QQ chat robot magazine. We talked about sending a message on QQ loops, feeling pretty fun, then pick up the Delphi began my QQ chat robot's path.
We must first understand what to do, we have used QQ, know the whole process of sending a message to someone else! To realize the function cycle of the transmitted message has the following conditions:
1. must be carried out in chat mode. After such completion sends a message, QQ form also exists.
2. The second is to find the handle QQ text form.
3. Place the QQ text form you want to say. Then click on the Send button yourself.
The idea is very simple, and then we will begin implementation.
First of all to find the handle QQ text form. Then I used to see QQ SPY form. The results in the following figure: this idea came out. To find the handle QQ text of the form have to first locate its parent category namely: flag 00620252 Class Name: AfxWnd42 Control ID: 00000000. But to find it will have to find QQ message dialog box that is: 006B294 "Cold ask Mei - send message" Dialog [# 32770] handle.
Then Api to use several functions:
1.FindWindowEx(
hWnd1: Long, // where to find the child's parent window, such as worst 0, use the desktop window (often said that the top-level windows are considered to be the desktop child window)
hWnd2: Long, // start looking from the window. If set to 0, indicating for the first child window to start the search.
Lpsz1: String, // class name to be searched, 0 ignored.
Lpsz2: String // class name to be searched, 0 ignored.
);
2.GetWindow(
hWnd: Long, // source window.
wCmd: Long // specify the relationship between the results window with the source window (here with GW_CHILD) represents the first child window to find the source window.
);
3. GetDlgItem(
hWnd: Long, // handle to source window.
Int: nIDDlgItem ID number of the window in which to find //
);
In fact just start looking for QQ dialog window, my first thought was FindWindow (), this function can be directly through the window to find the window handle title name.
I was looking for this:
var hparent:HWND;
hparent: = FindWindow (nil, 'send a message'); // this is very effective in the previous version of 2003 ^ _ ^
The result is an error. Why?
Later, a closer look and found that each QQ2003 title is changing: the above chart is: cold plum ask - send a message, but if you send a message to a person becomes: blue wind - sends a message (for example ).
This may be a security measure QQ2003 take it! Ha ha! You might see if the cause of online tools sometimes enter each other's nickname for the bomb to send a message QQ2003. (Easy to handle form obtained by nickname).
However, there is no better way to do that! Have! Then we should use FindWindowEx () a. A closer look at its argument, the key is the second hWnd2-- we can use it to call FindWindowEx find qualified child window several times. The following is my code:
var hparent: HWND; // defined as global variables. Find the handle to record every FindWindowEx call () of the form.
procedure TForm1.FormCreate(Sender: TObject);
begin
hparent: = 0; // initialize, find the desktop of all top-level windows start.
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var hbutton,hbutton1:HWND;
begin
repeat
hparent: = findwindowex (0, hparent, '# 32770', nil); // QQ dialog class # 32770, the cycle calls the FindWindowEx () can be updated each time when the clock value hParent effect. After the handle has been looking to find a form hparent meet the requirements of the form.
hbutton: = findwindowEX (hparent, 0, nil, 'transmission (& S)'); // every time determination window handle found, for the presence of 'transmission (& S)' button in this form. There is namely found the right QQ dialog box.
until hbutton <> 0; // find the QQ dialog box out of the loop.
hbutton1: = findwindowex (hparent, 0, nil, 'chat mode (& T)'); // find the dialogue form QQ find chat mode button handle.
if hbutton1 <> 0 then // if present chat mode button at this time which is now in the form QQ message mode state.
sendmessage (hbutton1, BM_CLICK, 0,0); // send a chat mode button click message. Convert to Form chat mode.
end;
So that we successfully found QQ dialog box. And the success of the Settings dialog box to chat mode. First task finally completed some, huh, huh! More depressed me is yet to come up.
Then, you should start looking for a handle that form the QQ input text. Then I used a GetDlgItem () We all know that a Control ID form some sort of control in this form class is invariant (remove static from some stylistic) SPY I had learned that QQ window to enter text Control ID body is 0000037E. So I wrote the following statement.
Var hmemo:HWND;
hmemo:=GetDlgItem(hparent,$0000037E);
It was found that no written stuff their desired effect. Ha ha! Or pick up the SPY, Ha! I discovered that there was more than one control ID to 0000037E. And we want to get the position of the form QQ input text is not a foremost (and if most previous, by the above statement can also be found ^ _ ^). Not depressed. No way, or start from its parent class now! You can not become seeking in step. A closer look on the map. I found it!
Flag 00620252 Class Name: AfxWnd42 Control ID: 00000000 that is the parent of the form that QQ input text, and it is all Class Name: the one of the most pre-AfxWnd42 position. So we can find its handle. Get away. With it, the form QQ input text handle it very easy to find, ha ha! The following is my code:
Var hmemo,hmemo1:HWND;
hmemo = GetDlgItem (hparent, $ 00000000); // find the parent class.
hmemo1 = GetWindow (hmemo1, GW_CHILD); // get the first child under the parent window handle (hmemo1 i.e., the input text form QQ ^ _ ^ handle done)
Here the way GetWindow () usage:
GetWindow(
Hwnd: Long, // source window handle.
wCnd: Long // specify the relationship results window with the source window. (The GW_CHILD to obtain a first sub-window handle form the source)
)
More constant relationship you went to see the MSDN it! Here we do not have a footprint of Cold Spring. what!
This, handle QQ and QQ input text dialog window we've got, the following step is to write to you, then paste into QQ text input window, tap Send, depressed and do some good!
Now I put a piece of code for your reference:
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
// import the contents of the file to the combobox control.
combobox1.Items.LoadFromFile(extractfilepath(application.ExeName)+'text.txt');
combobox1.Text:=combobox1.Items.Strings[0];
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var hmemo1: HWND; // hmemo1 QQ is the text input box to find the handle
begin
if checkbox1.Checked then // click the check box to send loop.
begin
if i>combobox1.Items.Count-1 then
i:=0;
edit1.Text:=combobox1.Items.Strings[i];
edit1.SelectAll;
edit1.CopyToClipboard; // copy to clipboard
sendmessage (hmemo1, WM_PASTE, 0,0); // send a form of paste QQ input text message.
sendmessage (hbutton, BM_CLICK, 0,0); // click the send button
i:=i+1;
end;
if checkbox1.Checked = false then // does not click the check box to send loop.
begin
edit1.Text:=combobox1.Text;
edit1.SelectAll;
edit1.CopyToClipboard;
sendmessage(hmemo1,WM_PASTE,0,0);
sendmessage(hbutton,BM_CLICK,0,0);
end;
end;
Accompanied by a brief description: Due to my limited knowledge, less likely to use the clipboard function to copy a string to a known method clipboard is not known. We can only route through to the control. Because all of the text type controls have a method that is --edit1.CopyToClipboard, so only first Edit1 becomes invisible control. Every time you want to send content first pass Edit1, then the contents of Edit1 CopyToClipboard. what! It's just a tricky another way, if everyone knows what a better way to look to inform the next, oh!
postscript:
The above code is for QQ2003 version. Although online like: Gone with the Wind Yeqian Fu means good tool. However, as a small rookie. But people who like to program. Own DIY (do it youtself) is a very interesting thing now! I also made reference to Gone with the Wind Yeqian Fu refers to a feeling with its use feature it! not bad. In fact, there is not much technical stuff, just use a few API functions only. Just I want to just learn Delphi help a friend, of course, be no need of a master.
 
Note:. QQ2004 some changes in order to facilitate the code I put up a new change of posts:
 
procedure TForm1.Timer1Timer(Sender: TObject);
var hbutton,hbutton1,hmemo,hmemo1,hparent1:HWND;
begin
repeat
hparent:=findwindowex(0,hparent,'#32770',nil);
 
// QQ2004 is more of the following sentence, another layer window Memo
hparent1:=findwindowex(hparent,0,'#32770',nil);
until hparent1<>0;
hbutton:=findwindowEX(hparent1,0,nil,'发送(&S)');
hbutton1: = findwindowex (hparent1,0, nil, 'chat mode (& T)');
if hbutton1<>0 then
sendmessage(hbutton1,BM_CLICK,0,0);
hmemo1:=GetDlgItem(hparent1,$00000000);
hmemo:=getwindow(hmemo1,GW_CHILD);
if hmemo<>0 then
begin
if checkbox1.Checked then
begin
if i>combobox1.Items.Count-1 then
i:=0;
edit1.Text:=combobox1.Items.Strings[i];
edit1.SelectAll;
edit1.CopyToClipboard;
sendmessage(hmemo,WM_SETTEXT,0,0);
sendmessage(hmemo,WM_PASTE,0,0);
sendmessage(hbutton,BM_CLICK,0,0);
i:=i+1;
end;
if checkbox1.Checked=false then
begin
edit1.Text:=combobox1.Text;
edit1.SelectAll;
edit1.CopyToClipboard;
sendmessage(hmemo,WM_SETTEXT,0,0);
sendmessage(hmemo,WM_PASTE,0,0);
sendmessage(hbutton,BM_CLICK,0,0);
end;
end;
end;
 

Guess you like

Origin www.cnblogs.com/blogpro/p/11426756.html