www.pudn.com > QQShield.rar > MainC.cs


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 
using System.Runtime.InteropServices;  
using System.Text; 
 
 
namespace QQShield 
{ 
	public delegate bool CallBack(IntPtr hwnd, int lParam); 
	///  
	/// Main 的摘要说明。 
	///  
	public class MainC 
	{	 
 
		 
		public const int WM_SYSCOMMAND = 0x0112; 
		public const int SC_CLOSE = 0xF060;  
 
		[DllImport("user32.dll")] 
		public static extern  bool SetWindowText(IntPtr hWnd, string lpString  ); 
 
 
		[DllImport("user32.dll")] 
		public static extern  bool EnableWindow(IntPtr hWnd,bool bEnable); 
 
 
 
		[DllImport("user32")] 
		public static extern int EnumWindows(CallBack x, int y);  
 
		[DllImport("user32.dll")] 
		public static extern int GetWindowText( IntPtr hwnd,System.Text.StringBuilder buf, int nMaxCount); 
 
 
		[DllImport("user32.dll",CharSet=CharSet.Auto)] 
		public static extern IntPtr FindWindowEx(IntPtr parent, //HWND 
			IntPtr next, //HWND 
			string sClassName, 
			string  sWindowTitle);  
 
		[DllImport("user32.dll",CharSet=CharSet.Auto)]//用于向窗口发送命令 
		public static extern int SendMessage(IntPtr hWnd,int msg, int wParam, int lParam); 
 
	 
		///  
		///  根据窗口句柄,设置指定窗口为前置窗口。 
		///  
		/// 			 
		[DllImport("user32.dll")] 
		public static extern void SetForegroundWindow(IntPtr hwnd);		 
		 
		[DllImport("user32.dll")] 
		public static extern IntPtr FindWindow(String lpClassName,String lpWindowName); 
 
		public static Hashtable hs=new Hashtable(); 
		public MainC() 
		{ 
			// 
			// TODO: 在此处添加构造函数逻辑 
			// 
		} 
		public static IntPtr FindWindows(string name) 
		{ 
			return FindWindow(null,name); 
		} 
		public static void CloseWindows(IntPtr hwnd) 
		{ 
			SendMessage(hwnd,WM_SYSCOMMAND,SC_CLOSE,(int)IntPtr.Zero); 
 
		} 
		public static bool Report(IntPtr hwnd, int lParam) 
		{ 
			StringBuilder buf=new StringBuilder(256); 
			GetWindowText(hwnd,buf,256); 
			if((buf.ToString().IndexOf("聊天中")!=-1)||(buf.ToString().IndexOf("- 发送消息")!=-1)) 
			{ 
				hs.Add(hwnd,null); 
			} 
			return true; 
 
		} 
		public static void check()    //检查有没有打开聊天窗口,并关闭其中的“聊天记录”按键 
		{ 
			hs.Clear(); 
			CallBack myCallBack = new CallBack(Report); 
			EnumWindows(myCallBack, 1);  
 
			foreach(System.Collections.DictionaryEntry de in hs) 
			{ 
				IntPtr hd=(IntPtr)(de.Key); 
				IntPtr frameh=FindWindowEx(hd,IntPtr.Zero,"#32770",null);  
				if((int)frameh!=0) 
				{ 
					IntPtr ip=FindWindowEx(frameh,IntPtr.Zero,"Button","聊天记录(&H)"); 
					if((int)ip!=0) 
					{ 
						MainC.SetWindowText(ip,"禁止查看"); 
						MainC.EnableWindow(ip,false); 
					} 
				} 
			} 
		} 
 
		 
 
		 
		 
	} 
}