⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qqmsgsender.cs

📁 QQ自动消息发送器 适用于适度的骚扰您的好友们。
💻 CS
字号:
/*
 *--------------------------------------------------------
 *	Class Name(类名):	QQMsgSender
 *	Author(创建者):		三角猫
 *	Email(电子邮件):	alex_zzg@163.com
 *	Create Time(创建时间):	2008/11/15 21:27:18 
 *	CLR Version(CLR版本):	2.0.50727.312
 *	Copyright (c) 		三角猫 www.zu14.cn
 *	All Rights Reserved.
 *	File Memo(备注):
 *--------------------------------------------------------
*/
using System;
using System.Collections.Generic;
using System.Text;

namespace QQAutoMsg
{
    /// <summary>
    /// 消息发送
    /// </summary>
    internal static class QQMsgSender
    {
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="qqChatWindows">所以已打开的QQ窗体的列表</param>
        /// <param name="msg">消息内容</param>
        internal static void Go(List<EnumQQChatWindows.QQChatWindow> qqChatWindows, string msg)
        {
            foreach (EnumQQChatWindows.QQChatWindow win in qqChatWindows)
            {
                SendMsg(win.WindowHwnd, msg);
            }
        }

        /// <summary>
        /// 根据窗体句柄,找到输入框和发送按钮,发送消息出去
        /// </summary>
        /// <param name="hWnd">聊天窗口句柄</param>
        /// <param name="msg">消息内容</param>
        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);
                            }
                        }
                    }
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -