基本信息
源码名称:C# 模拟QQ发送消息源码
源码大小:0.14M
文件格式:.zip
开发语言:C#
更新时间:2013-01-08
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 10 元×
微信扫码支付:10 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
已测试成功 可在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 = ""; } }