QQ聊天记录保护器制作全过程

王朝学院·作者佚名  2011-12-12
窄屏简体版  字體:   |    |    |  超大  

闲来无事,做了个访止别人偷看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)

{

MainC.SetWindowText(ip,"禁止查看");

MainC.EnableWindow(ip,false);

}

}

}

}

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;

}

"#32770"是QQ窗口的类名,用Sky++可以查到,并可以了解其子窗口情况。

禁用了聊天记录的QQ窗口如图:

最后实现开机运行,这个容易实现,下面的代码就可以啦:

private void autorun(bool run)//实现程序开机运行

{

string path=System.IO.Directory.GetCurrentDirectory()+"\\"+"svchost.exe";

RegistryKey rLocal = Registry.LocalMachine;

RegistryKey key1=null;

if(run==true)

{

try

{

key1 = rLocal.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);

key1.SetValue ("systemid",path);

key1.Close();

}

catch

{

}

if(key1 ==null)

{

try

{

RegistryKey key2=rLocal.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

key2.SetValue ("systemid",path);

key2.Close();

}

catch

{

}

}

}

else

{

try

{

key1 = rLocal.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true);

key1.DeleteValue("systemid");

key1.Close();

}

catch

{

}

if(key1 ==null)

{

try

{

RegistryKey key2=rLocal.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");

key2.DeleteValue("systemid");

key2.Close();

}

catch

{

}

}

}

}

参数为True时开启开机启动,为False时关闭开机启动。

另外把程序主窗休拉成最小,并隐藏了。这样谁都看不道这个程序了。

如果自已想聊天记录可以按F9健弹出个窗口,输入密码后就暂停保护,用RegisterHotKey(函数注册个系统热建就可以实现啦。

到此,所有功能都实现了。用了几天,感觉挺好用。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航