A few days ago, I saw an article on developing QQ chat robots on the magazine. When I talked about the content of the QQ cycle, I feel very fun, so I started the road of Delphi and started my QQ chat robot.
First of all, we must understand what you have to do. Everyone has used QQ, know the whole process of sending messages to others! The function to achieve loop sending messages should have the following conditions:
1. Must be done in chat mode. This is still present after the message is sent, and the QQ form also exists.
2. Second, it is to find the handle of the QQ text form.
3. Post you want to say to the QQ text form. Then click on the send button yourself.
The idea is very simple, then we will start to implement it.
First click on the handle of the QQ text form. At this time, I used SPY to view QQ form. The result is as follows:
This way is there. To find the handle of the QQ text form, you have to find its parent class: The flag is 00620252 Class Name: AFXWND42 Control ID: 00000000. To find it, you must find the QQ message dialog box,.
Use several API functions at this time:
1.FindWindowEx (
HWND1: long, // In these parent windows, if set to 0, indicating that using the desktop window (usually the top window is considered a sub-window of the desktop)
HWND2: long, // Start looking up after this window. Such as 0, indicating that the first sub-window starts searching.
LPSZ1: String, // To search for class name, 0 means ignored.
LPSZ2: String // Class name to search, 0 is ignored.
);
2.Getwindow
HWnd: long, // Source window.
WCMD: long // Specifies the relationship between the result window and the source window (here GW_CHILD) represents the first sub-window for the source window.
);
3. Getdlgitem
HWND: long, // The handle of the source window.
INT: Niddlgitem / / I want to find the ID number of the window
);
In fact, when I first started looking for a QQ dialog window, I first thought of findwindow (). This function can look for the form handle directly through the window title name.
I am looking for:
Var hParent: hwnd;
Hparent: = FindWindow (NIL, 'Sending Information'); // This is also very effective in 2003. ^ _ ^
The result is an error. Why?
Later, I found out that the title of each QQ2003 was changed: as the figure above: Cold as a meal ).
This may be a security measures taken by QQ2003! Ha ha! You may see the tools for sending a message bomb on the Internet sometimes to enter the other party's nickname. (Easy to get a form handle through the nickname).
But have there be a better way! Have! It is necessary to use findwindowex (). Take a closer look at its parameters, the key is the second hwnd2 - we can call FindWindowEx to find the eligible sub-window by it. The following is my code:
Var hParent: hwnd; // Defined as global variables. To record the handle of the form found after the FindWindowEx () each time you call.
Procedure TFORM1.FormCreate (Sender: TOBJECT);
Begin
HParent: = 0; // Initialization, find all the top window of the desktop start.
END;
Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);
Var hbutton, hbutton1: hwnd; begin
Repeat
HParent: = FindWindowEx (0, HParent, '# 32770', nil); // QQ dialog class is # 32770, so that the cycle calls FindWindowEx () can update the value of HParent each time the clock is effective. Find a form that meets the requirements after the HParent form is available.
HButton: = FindWindowEx (HParent, 0, NIL, 'Send (& S)'); // Determine the handle of the found window to see if the 'Send (& S)' button exists in this form. The existence has found the correct QQ dialog.
Until HButton <> 0; // Find the QQ dialog and jump out of the loop.
HButton1: = FindWindowEx (HParent, 0, NIL, 'chat mode (& T)'); // After finding the QQ dialog, look up the chat mode button handle.
If HBUTTON1 <> 0 THEN // If there is a chat mode button now, the QQ form is in the message mode status.
SendMessage (HButton1, BM_Click, 0, 0); // Send a click message to the chat mode button. Convert the form to chat mode.
END;
This way we will successfully find the QQ dialog box. And the Successful Setup dialog is a chat mode. The task is finally completed first, huh, huh! More depressed, I am still behind.
Then, start the handle of the form of the QQ input text. At this time, Getdlgitem () Everyone knows that a control ID of a type of control in a form is constant in this form class (removed some static cultural somewhere) over SPY I know the window of QQ input text. The body's Control ID is 0000037E. So I wrote the following statement.
Var hmemo: hwnd;
HMEMO: = Getdlgitem (HParent, $ 0000037E);
As a result, it was found that there was no effect that the stuff did not have its own expectations. Ha ha! Still pick up SPY, ha! It is found that there is more than one control ID to 0000037E. And we want to get the location of the form of QQ input text is not the forefather (if the forefather, the above statement is also available ^ _ ^). Depressed is not. No way, start with its parent class! Can not be obtained in one step. Take a closer look. Find it!
The logo is 00620252 Class Name: AFXWND42 Control ID: 00000000 is the parent class of the form of QQ input text, and it is all of the first Class Name: AfxWnd42. So we can find its handle. I can't run. With it, the handle of the form of QQ input text is very easy to find, haha! 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 sub-window handle under the parent class (HMEMO1 即 QQ input text, the handle of the form of the text, "
By the way, talking with getWindow () usage:
GetWindow
HWND: long, // Source window handle.
Wcnd: long // Specifies the relationship between the result window and the source window. (GW_CHILD is the first sub-window handle under the source form)
)
More constant relationships You go to view msdn! You don't have to take up the space of the cold spring. what!
At this point, we have already got this, the handle of the QQ dialog and QQ input text window, the following steps are the words you want to write, please enter the QQ into the text window, click to send, you will depressed others! I have applied my code now for your reference:
Procedure TFORM1.FormCreate (Sender: TOBJECT);
Begin
I: = 0;
// Import the file content to the ComboBox control.
ComboBox1.Items.LoadFromFile (applfilepath (application.exename) 'text.txt');
ComboBOX1.Text: = ComboBox1.Items.Strings [0];
END;
Procedure TFORM1.TIMER1TIMER (Sender: TOBJECT);
Var hmemo1: hwnd; // hmemo1 is found to find QQ text input box handle
Begin
If CheckBox1.checked the // Click the loop Send check box.
Begin
IF I> ComboBox1.Items.count-1 Then
I: = 0;
Edit1.Text: = ComboBox1.Items.Strings [i];
Edit1.SelectAll;
Edit1.copytoclipboard; // Copy to the shear board
SendMessage (HMEMO1, WM_PASTE, 0, 0); // Send a paste message for QQ input text form.
SendMessage (HButton, BM_Click, 0, 0); // Click Send button
i: = i 1;
END;
If CheckBox1.checked = false then // No Cycurse Send check box.
Begin
Edit1.Text: = Combobox1.text;
Edit1.SelectAll;
Edit1.copytoclipboard;
SendMessage (HMEMO1, WM_PASTE, 0, 0);
SendMessage (Hbutton, BM_Click, 0, 0);
END;
END;
Attach a brief description: Because I know limited, I don't know how to copy the known string to the shear board with the shear board function. So you can only borrow on the control. Because all text classes have a method, it is -edit1.copytoclipboard, so you can only turn Edit1 to an invisible control. Each time you will pass the content you want to send to Edit1, follow the contents of Edit1 CopyToClipboard. what! This is just a way to take a way. If you know what a better way, I hope to tell it, huh!
postscript:
The above code is for the QQ2003 version. Although there is a good tool for wavering thousands of capping. But as a small rookie. But I like to be programmed. One of yourself DIY (Do It Youtseelf) is also a very cool thing! I also referred to the waver of the waves, I feel that it has its function! not bad. In fact, there is not much technical things, just use a few API functions. I only hope that my friends who have just learned Delphi have been helped. Of course, the master can not use it.
If you need a friend, please go to my website to download (in my work):
Hottey 2003-10-29 in Taiyuan, Shanxi
- Because I don't say it. If you have not, please forgive!