闲来无事,做了个访止别人偷看QQ聊天记录的东东。对那些长期挂QQ又经常出去的人或许有用。
首先,查看聊天记录的那个窗口叫"信息管理器",如图:

为了访止别人打开这个窗口,做个Timer,每隔一定时间检查每个窗口的名称,看是否有标题为"信息管理器"的,有的话说明有人正在看聊天记录就把它给关掉。这个很容易实现,用到的函数有:FindWindow和SendMessage。代码如下:
//声明API函数
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String lpClassName,String lpWindowName);
[DllImport("user32.dll",CharSet=CharSet.Auto)]//用于向窗口发送命令
public static extern int SendMessage(IntPtr hWnd,int msg, int wParam, int lParam);//声明两个常量
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060; private void timer1_Tick(object sender, System.EventArgs e)//是否有信息管理器在运行
{
IntPtr hwc = FindWindows(null, "信息管理器");
if ((int)hwc != 0)//说明有信息管理器在运行
{
SendMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, (int)IntPtr.Zero);
f.Show();
}
}这样就可以访止别人打开信息管理器啦。Timer的时间设为2秒就可以啦。
另外还有个地方能看到聊天记录,就是聊天窗口的下面有个按纽:"聊天记录(H)",虽然这里显示的聊天记录不全,但也能显示20条左右。在此我只想到一个可用办法,就是禁用了这个按纽(关掉也可以实现,但容易使QQ程序发生错误重启)。用到的API函数有:SetWindowText、EnableWindow、EnumWindows、GetWindowText、FindWindowEx.
代码如下:
[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); public static Hashtable hs=new Hashtable();
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)
共有 0 位网友发表了评论,得分 0 分,平均 0 分 查看完整评论