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

📄 qqhooks.cs

📁 把QQ群里的消息记录下来
💻 CS
字号:
/* ************************************************************************
 * 描述: QQ钩子
 * 创建: sodak 2006-12-30
 *   
 *					 开 发 历 史 
 * ------------------------------------------------------------------------
 *  
 * 修改日期     修 改 内 容          修改人
 * ------------------------------------------------------------------------
 * 
 * 
 *****************************************************************************/
using System;
using System.Text;
using System.Diagnostics;

namespace TQQ
{
	/// <summary>
	/// QQ钩子
	/// </summary>
	public class QQHooks
	{
		/// <summary>
		/// 发送消息
		/// </summary>
		/// <param name="windowName">窗口标题</param>
		/// <param name="strMsg">消息内容</param>
		public static void SendMsg(string windowName,string strMsg)
		{
			string lpszParentClass = "#32770"; //整个窗口的类名
			string lpszParentWindow = windowName; //窗口标题
			IntPtr ip = WinApi.FindWindow(lpszParentClass,lpszParentWindow);	
			IntPtr EdithParentWnd = WinApi.FindWindowEx(ip,new IntPtr(0),"#32770","");
			IntPtr EdithWnd = WinApi.FindWindowEx(EdithParentWnd,new IntPtr(0),"AfxWnd42","");
			

			string lpszClass_Text = "RICHEDIT"; //消息输入窗口
			string lpszName_Text = ""; //消息输入窗口
			IntPtr THandle = WinApi.FindWindowEx(EdithWnd,new IntPtr(0),lpszClass_Text,lpszName_Text);
			
			//foreach(char c in strMsg.ToCharArray())
			//	WinApi.SendMessage(THandle,WinApi.WM_CHAR,(int)c,"");//发送消息到目标控件
			
			StringBuilder sb = new StringBuilder(strMsg);
			WinApi.SendMessage(THandle,WinApi.EM_SETSEL,-1,-1);//			
			WinApi.SendMessage(THandle,WinApi.EM_REPLACESEL,0,sb);

			string lpszClass_Submit = "Button"; //需要查找的Button的类名
			string lpszName_Submit = "发送(&S)"; //需要查找的Button的标题
			IntPtr TButtonHandle =  WinApi.FindWindowEx(EdithParentWnd,new IntPtr(0),lpszClass_Submit,lpszName_Submit);
			WinApi.SendMessage(TButtonHandle,WinApi.WM_CLICK,new IntPtr(0),"");//发送消息到目标控件使它执行click事件
		}

		/// <summary>
		/// 获取消息
		/// </summary>
		/// <param name="windowName">窗口标题</param>
		/// <returns></returns>
		public static string GetMsg(string windowName)
		{
			string lpszParentClass = "#32770"; //整个窗口的类名
			string lpszParentWindow = windowName; //窗口标题
			IntPtr ip = WinApi.FindWindow(lpszParentClass,lpszParentWindow);	
			IntPtr EdithWnd = WinApi.FindWindowEx(ip,new IntPtr(0),"#32770","");

			string lpszClass_Text = "RichEdit20A"; //查找历史记录类
			string lpszName_Text = ""; //查找历史记录类的标题
			IntPtr THandle = WinApi.FindWindowEx(EdithWnd,new IntPtr(0),lpszClass_Text,lpszName_Text);
			
//			int Length = 3000000;
//			byte[] buf=new byte[Length];
//			int Address = WinApi.VirtualAllocEx(Process.GetCurrentProcess().Handle,0,Length,0x1000,0x04);//在本进程内分配Length大小的内存
//			WinApi.SendMessage(THandle,WinApi.WM_GETTEXT,new IntPtr(255),new IntPtr(Address));//发送消息到目标控件,0x000D就是WM_GETTEXT,255的意思是保存返回的值,new IntPtr(Address)是指保存到Address指定的地址
//			WinApi.ReadProcessMemory(Process.GetCurrentProcess().Handle,Address,buf,Length,0);//读取刚才保存的内容
//			return Encoding.Default.GetString(buf);

			StringBuilder sb = new StringBuilder(300000);
			WinApi.SendMessage(THandle,WinApi.WM_GETTEXT,255,sb);//发送消息到目标控件,返回具体值
			//WinApi.SendMessage(THandle,WinApi.EM_SETSEL,-1,-1);//			
			//WinApi.SendMessage(THandle,WinApi.WM_SETTEXT,0,"");
			return sb.ToString();
		}
	}
}

⌨️ 快捷键说明

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