1. 程式人生 > >隱藏指定程式托盤圖示的方法

隱藏指定程式托盤圖示的方法

#include <atlconv.h>

HWND hWnd,hWndTmp;
 unsigned long lngPID;
 long ret,lngButtons;
 HANDLE hProcess;
 LPVOID lngAddress;
 long lngTextAdr,lngHwndAdr,lngHwnd,lngButtonID;
 char strBuff[1024]={0};
 char* str = NULL;
 hWnd=::FindWindow("Shell_TrayWnd",NULL);
    hWnd=::FindWindowEx(hWnd,0,"TrayNotifyWnd",NULL);
    hWndTmp=::FindWindowEx(hWnd,0,"SysPager",NULL);
 if(!hWndTmp)
  hWnd=::FindWindowEx(hWnd,0,"ToolbarWindow32",NULL);
 else
  hWnd=::FindWindowEx(hWndTmp,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));
   //   MessageBox((const char*)(strTmp),NULL,MB_OK);//Just for test
   if(strstr(str,"PPStream")>0){
    if(1){
     ::SendMessage(hWnd, TB_HIDEBUTTON , lngButtonID, 1);
    }
    else{
     ::SendMessage(hWnd, TB_HIDEBUTTON , lngButtonID, 0);
    }
   }
  }
    }
    ::VirtualFreeEx( hProcess,  lngAddress,  0X4096, MEM_RELEASE);
    ::CloseHandle(hProcess);