如何获取win7上没显示在任务栏上的图标(隐藏的托盘图标)?
通过下面的代码,可以得到显示在任务栏上的图标,隐藏的图标如何取得?
private static IntPtr GetTrayPointer()
{
IntPtr h = IntPtr.Zero;
IntPtr hTemp = IntPtr.Zero;
h = Win32API.FindWindow("Shell_TrayWnd", null);
h = Win32API.FindWindowEx(h, IntPtr.Zero, "TrayNotifyWnd", null);
h = Win32API.FindWindowEx(h, IntPtr.Zero, "SysPager", null);
hTemp = Win32API.FindWindowEx(h, IntPtr.Zero, "ToolbarWindow32", null);
return hTemp;
}
public static bool CryptionToolTrayIconIsExisted()
{
IntPtr pid = IntPtr.Zero;
IntPtr lTextAdr = IntPtr.Zero;
IntPtr ipTray = GetTrayPointer();
Win32API.GetWindowThreadProcessId(ipTray, ref pid);
if (pid.Equals(0)) return false;
IntPtr hProcess = Win32API.OpenProcess(Win32API.PROCESS_ALL_ACCESS | Win32API.PROCESS_VM_OPERATION | Win32API.PROCESS_VM_READ | Win32API.PROCESS_VM_WRITE, IntPtr.Zero, pid);
IntPtr lAddress = Win32API.VirtualAllocEx(hProcess, 0, 4096, Win32API.MEM_COMMIT, Win32API.PAGE_READWRITE);
// Get the tray icon number
int lButton = Win32API.SendMessage(ipTray, Win32API.TB_BUTTONCOUNT, 0, 0);
for (int i = 0; i < lButton; i++)
{
Win32API.SendMessage(ipTray, Win32API.TB_GETBUTTON, i, lAddress);
Win32API.ReadProcessMemory(hProcess, (IntPtr)(lAddress.ToInt32() + 16), ref lTextAdr, 4, 0);
if (!lTextAdr.Equals(-1))
{
byte[] buff = new byte[1024];
Win32API.ReadProcessMemory(hProcess, lTextAdr, buff, 1024, 0);
string title = System.Text.ASCIIEncoding.Unicode.GetString(buff);
int nullindex = title.IndexOf("\0");
if (nullindex > 0)
{
title = title.Substring(0, nullindex);
}
if ("application".Equals(title))
{
return true;
}
}
}
Win32API.VirtualFreeEx(hProcess, lAddress, 4096, Win32API.MEM_RELEASE);
Win32API.CloseHandle(hProcess);
return false;
}
------解决方案--------------------
隐藏了还能取得吗?
可以设置快捷键,来启动隐藏的程序。
不懂,帮顶,等高手。