閑來無事,做了個訪止別人偷看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 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(函數注冊個系統熱建就可以實現啦。
到此,所有功能都實現了。用了幾天,感覺挺好用。
新聞熱點
疑難解答