|
- sing System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace QunSign
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- static string path = System.AppDomain.CurrentDomain.BaseDirectory + "/List.txt";
- [DllImport("user32.dll", EntryPoint = "keybd_event")]
- public static extern void keybd_event(byte bVk, //虚拟键值
- byte bScan,
- int dwFlags, //0 为按下,2为释放
- int dwExtraInfo
- );
- [DllImport("user32.dll")]
- public static extern int SendMessage(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam);
- [DllImport("User32.dll", EntryPoint = "FindWindow")]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
- public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
- private const int WM_MOUSEMOVE = 512;
- private const int WM_LBUTTONDOWN = 513;
- private const int WM_LBUTTONUP = 514;
- private const int WM_LBUTTONDBLCLK = 515;
- private const int WM_SETCURSOR = 32;
- private const int WM_MOUSEACTIVATE = 33;
- private void button1_Click(object sender, EventArgs e)
- {
- if (listBox1.SelectedItems.Count == 0)
- {
- MessageBox.Show("选择目标必须大于0");
- return;
- }
- IntPtr handle = this.Handle;
- this.WindowState = FormWindowState.Minimized;
- List<string> list = new List<string>();
- for (int i = 0; i < listBox1.SelectedItems.Count; i++)
- {
- list.Add(listBox1.SelectedItems[i].ToString());
- }
- System.Threading.ThreadPool.QueueUserWorkItem((o) =>
- {
- for (int i = 0; i < list.Count; i++)
- {
- this.Invoke(new MethodInvoker(() =>
- {
- string qq = list[i].ToString();
- IntPtr QQhWnd = FindWindow("TXGuiFoundation", "QQ"); //获取QQ主窗口句柄
- if (QQhWnd.ToInt32() > 0)
- {
- //恢复显示窗体
- ShowWindow(QQhWnd, 1); //1,正常 2,最小化 3,最大化
- Thread.Sleep(1000);
- //发送单击消息,搜索栏点叉叉。
- SendMessage(QQhWnd, WM_LBUTTONDOWN, (IntPtr)1, (IntPtr)(134 * 65536 + 269)); //(y * 65536 + x)
- SendMessage(QQhWnd, WM_LBUTTONUP, (IntPtr)0, (IntPtr)(134 * 65536 + 269));
- Thread.Sleep(500);
- //发送单击消息,选中搜索框。
- SendMessage(QQhWnd, WM_LBUTTONDOWN, (IntPtr)1, (IntPtr)(134 * 65536 + 130));
- SendMessage(QQhWnd, WM_LBUTTONUP, (IntPtr)0, (IntPtr)(134 * 65536 + 130));
- //发送粘贴消息,将qq群号码复制到搜索框。
- Clipboard.SetText(qq);
- Thread.Sleep(200);
- keybd_event((byte)Keys.ControlKey, 0, 0, 0);//按下
- keybd_event((byte)Keys.V, 0, 0, 0);
- keybd_event((byte)Keys.V, 0, 2, 0);//松开
- keybd_event((byte)Keys.ControlKey, 0, 2, 0);
- //等待1秒,发送双击消息
- Thread.Sleep(1000);
- //发送双击消息,打开被搜索的QQ群。
- SendMessage(QQhWnd, WM_MOUSEACTIVATE, (IntPtr)QQhWnd, (IntPtr)(33619969)); //2010001
- SendMessage(QQhWnd, WM_SETCURSOR, (IntPtr)QQhWnd, (IntPtr)(33619969));
- SendMessage(QQhWnd, WM_LBUTTONDOWN, (IntPtr)1, (IntPtr)(185 * 65536 + 130));
- SendMessage(QQhWnd, WM_MOUSEMOVE, (IntPtr)1, (IntPtr)(185 * 65536 + 130));
- SendMessage(QQhWnd, WM_LBUTTONUP, (IntPtr)0, (IntPtr)(185 * 65536 + 130));
- SendMessage(QQhWnd, WM_SETCURSOR, (IntPtr)QQhWnd, (IntPtr)(33554433)); //2000001
- SendMessage(QQhWnd, WM_MOUSEMOVE, (IntPtr)0, (IntPtr)(185 * 65536 + 130));
- SendMessage(QQhWnd, WM_SETCURSOR, (IntPtr)QQhWnd, (IntPtr)(33619969));
- SendMessage(QQhWnd, WM_LBUTTONDBLCLK, (IntPtr)1, (IntPtr)(185 * 65536 + 130));
- SendMessage(QQhWnd, WM_LBUTTONUP, (IntPtr)0, (IntPtr)(185 * 65536 + 130));
- Thread.Sleep(1000);
- IntPtr hWnd = GetProcessMainFormHandle("QQ"); //获取聊天窗口句柄
- if (hWnd.ToInt32() > 0)
- {
- Clipboard.SetText(textBox1.Text); //将消息内容复制到剪贴板
- Thread.Sleep(20);
- //ctrl+v 粘贴消息
- keybd_event((byte)Keys.ControlKey, 0, 0, 0);//按下
- keybd_event((byte)Keys.V, 0, 0, 0);
- keybd_event((byte)Keys.V, 0, 2, 0);//松开
- keybd_event((byte)Keys.ControlKey, 0, 2, 0);
- Thread.Sleep(500);
- //alt+s 发送消息
- keybd_event((byte)Keys.Menu, 0, 0, 0);//按下
- keybd_event((byte)Keys.S, 0, 0, 0);
- keybd_event((byte)Keys.S, 0, 2, 0);//松开
- keybd_event((byte)Keys.Menu, 0, 2, 0);
- Thread.Sleep(500);
- //alt+c 关闭对话框
- keybd_event((byte)Keys.Menu, 0, 0, 0);//按下
- keybd_event((byte)Keys.C, 0, 0, 0);
- keybd_event((byte)Keys.C, 0, 2, 0);//松开
- keybd_event((byte)Keys.Menu, 0, 2, 0);
- Clipboard.Clear(); //清空剪贴板
- textBox2.AppendText(string.Format("目标:{0} 消息已发出..{1}", qq, Environment.NewLine));
- }
- else
- {
- textBox2.AppendText(string.Format("目标:{0} 发送失败!{1}", qq, Environment.NewLine));
- }
- }
- }));
- }
- Thread.Sleep(1000);
- ShowWindow(handle, 1);
- });
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText("./List.txt"))
- {
- sw.Close();
- }
- }
- var files = File.ReadAllLines(path, Encoding.UTF8);
- listBox1.Items.AddRange(files);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < listBox1.Items.Count; i++)
- {
- listBox1.SetSelected(i, true);
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < listBox1.Items.Count; i++)
- {
- listBox1.SetSelected(i, !listBox1.GetSelected(i));
- }
- }
- /// <summary>
- /// 通过进程名获得主窗口句柄
- /// </summary>
- /// <param name="processName">进程名</param>
- /// <returns>窗口句柄对象</returns>
- public IntPtr GetProcessMainFormHandle(string processName)
- {
- IntPtr m_WindowHandle = IntPtr.Zero;
- System.Diagnostics.Process pro = null;
- System.Diagnostics.Process[] pros = System.Diagnostics.Process.GetProcessesByName(processName);
- if (pros.Length > 0)
- {
- pro = pros[0];
- m_WindowHandle = pro.MainWindowHandle;
- }
- return m_WindowHandle;
- }
- }
- }
复制代码
源码打包下载:
|
|