VC 隐藏托盘图标

苦苦寻找的隐藏托盘图标的方法,今天终于搞定,献给大家

#include  < atlbase.h >
#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 );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值