The method of hiding the tray icon that you are struggling to find is finally completed today. It is for everyone!
# 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 = find1_wex (hWnd, 0, "traypolicywnd", NULL );
HWndPaper = find1_wex (hWnd, 0, "SysPager", NULL );
If (! HWndPaper)
HWnd = find1_wex (hWnd, 0, "ToolbarWindow32", NULL );
Else
HWnd = find1_wex (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, 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 );
}
Call method:
Char szIcon []: The tray icon to hide; BOOL show: false indicates the hidden icon; true indicates the display icon. For example, hide the tray icon of Kingsoft Mac:
ShowTrayIcon ("Kingsoft", false );