C#实现自动发送QQ消息

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

代码:

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() != "0")
                {
                    SetForegroundWindow(k);             //把窗体置于最前
                    for (int i = 1; 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, 0);
        }
    }
}
View Code

 

 

转载于:https://www.cnblogs.com/fengsiyi/p/3681364.html

作者: 三角猫 出处: http://www.zu14.cn/ 版权归 三角猫 和 真有意思网 所有,转载请注明出处 using System; using System.Collections.Generic; using System.Text; namespace QQAutoMsg { /// /// 消息发送 /// internal static class QQMsgSender { /// /// 发送消息 /// /// 所以已打开的QQ窗体的列表 /// 消息内容 internal static void Go(List qqChatWindows, string msg) { foreach (EnumQQChatWindows.QQChatWindow win in qqChatWindows) { SendMsg(win.WindowHwnd, msg); } } /// /// 根据窗体句柄,找到输入框和发送按钮,发送消息出去 /// /// 聊天窗口句柄 /// 消息内容 private static void SendMsg(IntPtr hWnd, string msg) { if (NativeMethods.IsWindow(hWnd)) //确认该聊天窗口仍然有效 { ////找到 发送 按钮 IntPtr hwndButton = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "Button", "发送(S)"); if (IntPtr.Zero != hwndButton) { ////找到窗体顺序上的第一个RichEdit20A控件,其实就是消息显示框 IntPtr hwndRichEdit = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "RichEdit20A", null); ////利用spy++,可以看到消息输入框的父窗体是类名为 AfxWnd42 的控件 ////在顺序上是显示框的下一个窗体 if (IntPtr.Zero != hwndRichEdit) { ////找到 AfxWnd42 这个窗体 hwndRichEdit = NativeMethods.GetWindow(hwndRichEdit, NativeMethods.GW_HWNDNEXT); if (IntPtr.Zero != hwndRichEdit) { ////这才是真正的消息输入框 hwndRichEdit = NativeMethods.FindWindowEx(hwndRichEdit, IntPtr.Zero, "RichEdit20A", null); if (hwndRichEdit != IntPtr.Zero) { ////发送消息,因为QQ屏蔽了 WM_SETTEXT, WM_PASTE 命令,所有采用 EM_REPLACESEL 来实现 NativeMethods.SendMessage(hwndRichEdit, NativeMethods.EM_REPLACESEL, IntPtr.Zero, msg); ////给发送按钮 鼠标单击消息 NativeMethods.SendMessage(hwndButton, NativeMethods.BM_CLICK, IntPtr.Zero, IntPtr.Zero); } } } } } } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值