C#实现自动发送QQ消息

时间:2022-04-16 11:25:58

1、得打开需要发送的聊天窗口,最小化也可,聊天时不能是中文输入法
2、然后AIO名就是窗口左上角的那个名称,括号和QQ号不要,那个名称可能是好友备注,群名称,讨论组名称等。
3、发送消息要设置成按Enter键发送
4、想发图片要先把图片添加到表情,设置快捷键,而后把快捷键输入到消息内容中即可

C#实现自动发送QQ消息

代码:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading; namespace AutoSend
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} //找窗体
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//把窗体置于最前
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd); //拖动窗体
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002; private void btnSend_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(textBox1.Text);
sendMessage(a);
} //发送消息
public void sendMessage(int num)
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
{
MessageBox.Show("有些框框是空的!!!");
}
else
{
string aioName = textBox3.Text.Trim(); //AIO名
string info = textBox2.Text; //要发送的消息
string str = ""; IntPtr k = FindWindow(null, aioName); //查找窗口
if (k.ToString() != "")
{
SetForegroundWindow(k); //把窗体置于最前
for (int i = ; i <= num; i++)
{
str = i + ": " + info;
SendKeys.SendWait(str);
SendKeys.Send("{ENTER}");
}
}
else
{
MessageBox.Show("木有找到这个聊天窗口");
}
}
} private void btnClose_Click(object sender, EventArgs e)
{
this.Dispose();
this.Close();
} //拖动窗体
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, );
}
}
}