已测试成功 可在qq2013以及以下版本使用
public partial class QQAutoSendMsgForm : Form
{
private List<QQChatWindows> _QQListWindows = new List<QQChatWindows>();
private int _SendIntervalTime = 30;
private int _CountTime = 0;
private string _Title = "QQ消息自动发送工具";
public QQAutoSendMsgForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
this.btLoopSend.Enabled = true;
this.btStopLoop.Enabled = true;
this.txtIntervalTime.Text = this._SendIntervalTime.ToString();
this.EnumQQChatWindows();
}
private void btUpdate_Click(object sender, EventArgs e)
{
this.EnumQQChatWindows();
}
private void btTestSend_Click(object sender, EventArgs e)
{
this.listSendRecord.Items.Clear();
if (this.txtSendText.Text.Equals("<输入要发送的内容>") || this.txtSendText.Text.Equals(String.Empty))
{
MessageBox.Show("请输入要发送的内容"); return;
}
if (this._QQListWindows.Count <= 0)
{
MessageBox.Show("没有可用发送的聊天窗体"); return;
}
this.SendQQMsgLoop();
}
private void btLoopSend_Click(object sender, EventArgs e)
{
this.listSendRecord.Items.Clear();
if (this.txtSendText.Text.Equals("<输入要发送的内容>") || this.txtSendText.Text.Equals(String.Empty))
{
MessageBox.Show("请输入要发送的内容"); return;
}
if (this._QQListWindows.Count <= 0)
{
MessageBox.Show("没有可用发送的聊天窗体"); return;
}
this.timer1.Start();
this.btLoopSend.Enabled = false;
this.btStopLoop.Enabled = true ;
}
private void btStopLoop_Click(object sender, EventArgs e)
{
this.timer1.Stop();
this.btLoopSend.Enabled = true;
this.btStopLoop.Enabled = false;
}
private void btTestSingle_Click(object sender, EventArgs e)
{
TestSendToolStripMenuItem_Click(sender, e);
}
private void TestSendToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.txtSendText.Text.Equals("<输入要发送的内容>") || this.txtSendText.Text.Equals(String.Empty))
{
MessageBox.Show("请输入要发送的内容"); return;
}
if (this._QQListWindows.Count <= 0)
{
MessageBox.Show("没有可用发送的聊天窗体"); return;
}
if (this.listQQWindows.SelectedItem == null)
return;
string qqcaption = this.listQQWindows.SelectedItem.ToString();
IntPtr hwnd = IntPtr.Zero;
for (int i = 0; i < this._QQListWindows.Count; i )
{
if (this._QQListWindows[i].Caption.Equals(qqcaption))
{
hwnd = this._QQListWindows[i].WindowHwnd; break;
}
}
if (hwnd == IntPtr.Zero)
{
MessageBox.Show("没有找到可发送信息的QQ聊天窗体");
}
else
{
if (this.SendQQMsg(hwnd, qqcaption, this.txtSendText.Text))
MessageBox.Show("测试成功");
else
MessageBox.Show("测试失败");
}
}
private void SendQQMsgLoop()
{
string text = this.txtSendText.Text;
for (int i = 0; i < this._QQListWindows.Count; i )
{
IntPtr hwnd=this._QQListWindows[i].WindowHwnd;
string caption=this._QQListWindows[i].Caption;
try
{
if (this.listSendRecord.Items.Count >= 1000)
this.listSendRecord.Items.Clear();
if(this.SendQQMsg(hwnd,caption , text))
this.listSendRecord.Items.Insert(0, caption ":" "发送成功");
else
this.listSendRecord.Items.Insert(0, caption ":" "发送失败");
}
catch (System.Exception ex)
{
this.listSendRecord.Items.Insert(0, caption ":" ex.Message);
}
finally
{
System.Threading.Thread.Sleep(500);
}
}
}
private bool SendQQMsg(IntPtr hWnd, string qqcaption, string sendtext)
{
try
{
NativeMethods.ShowWindow(hWnd, NativeMethods.ShowWindowCommands.Normal);
NativeMethods.BringWindowToTop(hWnd);
SendKeys.SendWait(sendtext);
SendKeys.SendWait("{ENTER}");
return true;
}
catch
{
return false;
}
}
private void EnumQQChatWindows()
{
this.listQQWindows.Items.Clear();
this._QQListWindows.Clear();
NativeMethods.EnumDesktopWindows(IntPtr.Zero, new NativeMethods.EnumDesktopWindowsDelegate(EnumWindowsProc), IntPtr.Zero);
}
private bool EnumWindowsProc(IntPtr hWnd, uint lParam)
{
string qqproname = this.GetProcessName(hWnd);
StringBuilder className = new StringBuilder(255 1); //ClassName 最长
NativeMethods.GetClassName(hWnd, className, className.Capacity);
if (!qqproname.Equals(String.Empty) && qqproname.Equals("QQ") && className.ToString().Equals("TXGuiFoundation"))
//if (!qqproname.Equals(String.Empty) && qqproname.Equals("WindowsApplication2"))
{
StringBuilder caption = new StringBuilder(NativeMethods.GetWindowTextLength(hWnd) 1);
NativeMethods.GetWindowText(hWnd, caption, caption.Capacity);
if (!caption.ToString().Equals(String.Empty) && !caption.ToString().Equals("TXFloatingWnd") && !caption.ToString().Equals("TXMenuWindow") && !caption.ToString().Equals("QQ2011"))
{
QQChatWindows qqchat = new QQChatWindows(hWnd, caption.ToString());
this._QQListWindows.Add(qqchat);
this.listQQWindows.Items.Add(caption);
}
}
return true;
}
public string GetProcessName(IntPtr hWnd)
{
try
{
string processname = String.Empty;
int proid = 0;
uint threadid = NativeMethods.GetWindowThreadProcessId(hWnd, out proid);
if (threadid > 0 && proid > 0)
{
Process pro = Process.GetProcessById(proid);
processname = pro.ProcessName;
}
return processname;
}
catch
{
return String.Empty;
}
}
private void Link_Click(object sender, EventArgs e)
{
//System.Diagnostics.Process.Start("http://www.bmpj.net");
}
private void txtSendText_Enter(object sender, EventArgs e)
{
if (this.txtSendText.Text.Equals("<输入要发送的内容>"))
{
this.txtSendText.Text = "";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this._CountTime ;
if (this._CountTime >= this._SendIntervalTime)
{
this.SendQQMsgLoop();
this._CountTime = 0;
}
}
private void btExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtIntervalTime_Leave(object sender, EventArgs e)
{
try
{
int time = Convert.ToInt32(this.txtIntervalTime.Text);
if (time >= 1)
this._SendIntervalTime = time;
else
{
this.txtIntervalTime.Text = this._SendIntervalTime.ToString();
MessageBox.Show("不能小于 1");
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btClear_Click(object sender, EventArgs e)
{
this.txtSendText.Text = "";
}
}
资源文件列表
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend.sln , 920
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend.suo , 37888
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Debug/QQAutoSend.exe , 67072
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Debug/QQAutoSend.pdb , 38400
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Debug/QQAutoSend.vshost.exe , 14328
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Release/QQAutoSend.pdb , 36352
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Release/QQAutoSend.vshost.exe , 14328
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/bin/Release/QQAutoSend.vshost.exe.manifest , 490
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/NativeMethods.cs , 8338
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.csproj.FileListAbsolute.txt , 877
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.csproj.GenerateResource.Cache , 859
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.exe , 67072
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.pdb , 38400
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.Properties.Resources.resources , 180
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/QQAutoSend.QQAutoSendMsgForm.resources , 15652
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll , 4608
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.csproj.FileListAbsolute.txt , 893
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.csproj.GenerateResource.Cache , 919
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.exe , 50688
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.pdb , 36352
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.Properties.Resources.resources , 180
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/QQAutoSend.QQAutoSendMsgForm.resources , 15652
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/obj/Release/TempPE/Properties.Resources.Designer.cs.dll , 4608
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Program.cs , 481
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Properties/AssemblyInfo.cs , 1204
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Properties/Resources.Designer.cs , 2844
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Properties/Resources.resx , 5612
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Properties/Settings.Designer.cs , 1108
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/Properties/Settings.settings , 249
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/qq.ico , 15086
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQAutoSend.csproj , 4485
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQAutoSend.csproj.user , 168
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQAutoSendMsgForm.cs , 9614
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQAutoSendMsgForm.Designer.cs , 14199
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQAutoSendMsgForm.resx , 29343
QQ╧√╧ó╫╘╢»╖ó╦═╣ñ╛▀/QQAutoSend/QQChatWindows.cs , 680
