VC 隐藏托盘图标
苦苦寻找的隐藏托盘图标的方法,今天终于搞定,献给大家!
#include <atlconv.h>
#include <CommCtrl.h>
void ShowTrayIcon(char szIcon[],BOOL show)
{
HWND hWnd,hWndPaper;
unsigned long lngPID;
long ret,lngButtons;
HANDLE hProcess;
LPVOID lngAddress;
long lngTextAdr,lngHwndAdr,lngHwnd,lngButtonID;
char strBuff[1024]={0};
char* str = NULL;
char *pp = NULL;
hWnd = FindWindow("Shell_TrayWnd", NULL);
hWnd = FindWindowEx(hWnd, 0, "TrayNotifyWnd", NULL);
hWndPaper = FindWindowEx(hWnd, 0, "SysPager", NULL);
if(!hWndPaper)
hWnd = FindWindowEx(hWnd, 0, "ToolbarWindow32", NULL);
else
hWnd = FindWindowEx(hWndPaper, 0, "ToolbarWindow32", NULL);
ret = GetWindowThreadProcessId(hWnd, &lngPID);
hProcess = OpenProcess(PROCESS_ALL_ACCESS
|PROCESS_VM_OPERATION
|PROCESS_VM_READ
|PROCESS_VM_WRITE,
0,
lngPID);
lngAddress = VirtualAllocEx(hProcess,0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
lngButtons = SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
for(int i=0 ;i< lngButtons - 1;i++)
{
ret = SendMessage(hWnd,TB_GETBUTTON,i,long(lngAddress));
ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 16),&lngTextAdr,4,0);
if(lngTextAdr != -1)
{
ret = ReadProcessMemory(hProcess, LPVOID(lngTextAdr),strBuff,1024,0);
ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 12),&lngHwndAdr,4,0);
ret = ReadProcessMemory(hProcess, LPVOID(lngHwndAdr),&lngHwnd, 4,0);
ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 4),&lngButtonID,4,0);
USES_CONVERSION;
str = OLE2T((LPOLESTR)(strBuff));
pp=strstr(str,szIcon);
if(pp != NULL)
{
if(show)
{
SendMessage(hWnd,TB_HIDEBUTTON,lngButtonID,0);
}
else
{
SendMessage(hWnd,TB_HIDEBUTTON,lngButtonID,1);
}
}
}
}
VirtualFreeEx( hProcess, lngAddress, 0X4096, MEM_RELEASE);
CloseHandle(hProcess);
}
调用方法:
char szIcon[] :要隐藏的托盘图标;BOOL show:false 为隐藏图标,true为显示图标。例如,隐藏金山词霸的托盘图标:
ShowTrayIcon("金山词霸",false);
http://www.cnblogs.com/anjou/archive/2008/12/20/1359085.html