16,472
社区成员
发帖
与我相关
我的任务
分享
#include <atlbase.h>
#include <atlconv.h>
#include <CommCtrl.h>
#include <IOSTREAM.H>
#include <STRING.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);
*/
/*
void main()
{
ShowTrayIcon("迅雷精简版",true);
}
*/
int main( int argc, char *argv[])
{
if (argc!=3)
{
cout<<"参数调用错误"<<endl;
return 0;
}
else
{
int result1 = strcmp(argv[2],"-show");
int result2 = strcmp(argv[2],"-hide");
if( result1==0)
{
ShowTrayIcon(argv[1],true);
return 1;
}
if( result2==0)
{
ShowTrayIcon(argv[1],false);
return 1;
}
else
{
cout<<"需带参数运行或参数调用错误,请看下面详细说明:"<<endl;
cout<<"HideTrayIcon.exe tray_icon_name [-show/-hide]"<<endl;
cout<<"参数1 tray_icon_name指定要隐藏的托盘图标名,鼠标移动到托盘图标上即可看到;"<<endl;
cout<<"参数2 [-show/-hide]为-show时显示改托盘图标,-hide时隐藏改托盘图标。"<<endl;
cout<<"如 HideTrayIcon.exe 金山词霸 -hide 就可以隐藏金山词霸托盘图标。"<<endl;
return 0;
}
}
}
int main(int argc,char* argv[])
{
int index=0;
for(index<argc;index++)
printf("%s\n",argv[index]);
}