?? qqmsgsender.cs
字號:
?/*
*--------------------------------------------------------
* Class Name(類名): QQMsgSender
* Author(創(chuàng)建者): 三角貓
* Email(電子郵件): alex_zzg@163.com
* Create Time(創(chuàng)建時間): 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>
/// 消息發(fā)送
/// </summary>
internal static class QQMsgSender
{
/// <summary>
/// 發(fā)送消息
/// </summary>
/// <param name="qqChatWindows">所以已打開的QQ窗體的列表</param>
/// <param name="msg">消息內(nèi)容</param>
internal static void Go(List<EnumQQChatWindows.QQChatWindow> qqChatWindows, string msg)
{
foreach (EnumQQChatWindows.QQChatWindow win in qqChatWindows)
{
SendMsg(win.WindowHwnd, msg);
}
}
/// <summary>
/// 根據(jù)窗體句柄,找到輸入框和發(fā)送按鈕,發(fā)送消息出去
/// </summary>
/// <param name="hWnd">聊天窗口句柄</param>
/// <param name="msg">消息內(nèi)容</param>
private static void SendMsg(IntPtr hWnd, string msg)
{
if (NativeMethods.IsWindow(hWnd)) //確認該聊天窗口仍然有效
{
////找到 發(fā)送 按鈕
IntPtr hwndButton = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "Button", "發(fā)送(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)
{
////發(fā)送消息,因為QQ屏蔽了 WM_SETTEXT, WM_PASTE 命令,所有采用 EM_REPLACESEL 來實現(xiàn)
NativeMethods.SendMessage(hwndRichEdit, NativeMethods.EM_REPLACESEL, IntPtr.Zero, msg);
////給發(fā)送按鈕發(fā) 鼠標單擊消息
NativeMethods.SendMessage(hwndButton, NativeMethods.BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
}
}
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -