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);
}

 

调用方法:ACCESS

char szIcon[] :要藏的托盘图标;BOOL show:false 为隐匿图标,true为显示图标。例如,隐藏金山词霸的托盘图标:

ShowTrayIcon(“金山词霸”,false);

相关文章