• 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,00x4096, MEM_COMMIT, PAGE_READWRITE);
        lngButtons 
    = SendMessage(hWnd, TB_BUTTONCOUNT, 00);

        
    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);
  • 相关阅读:
    missing required cgroups: cpu 天宇轩
    LiteFlow 基本使用教程
    Javaagent 的简单使用
    Docker 容器占用大量磁盘空间
    gitlab文件恢复
    pycharm的git设置
    Qt QThread多线程isRunning 线程明明关闭,isRunning仍然显示true
    Qt QProgressDialog new完后自动弹出问题
    QT progressBar 进度条
    Qt 计算文件夹内的文件数量
  • 原文地址:https://www.cnblogs.com/anjou/p/1359085.html
Copyright © 2020-2023  润新知