- #include <atlbase.h>
- #include <atlconv.h>
- #pragma comment(lib, "LIBCMTD.LIB")
- VOID ShowTrayIcon(TCHAR *szIcon)
- {
- HWND hwnd, hwndPager;
- ULONG lngPid;
- LONG ret, lngButtons;
- HANDLE hProcess;
- LPVOID lngAddress;
- LONG lngTextAdr,lngHwndAdr,lngHwnd,lngButtonID;
- TCHAR strBuff[1024] = {0};
- TCHAR *pp = NULL, *str = NULL;
- hwnd = FindWindow("Shell_TrayWnd", NULL);
- hwnd = FindWindowEx(hwnd, 0, "TrayNotifyWnd", NULL);
- hwndPager = FindWindowEx(hwnd, 0, "SysPager", NULL);
- if (hwndPager)
- hwnd = FindWindowEx(hwndPager, 0, "ToolbarWindow32", NULL);
- else
- hwnd = FindWindowEx(hwnd, 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 = _tcsstr(str, szIcon);
- if (pp != NULL)
- SendMessage(hwnd,TB_HIDEBUTTON,lngButtonID,TRUE);
- }
- }
- VirtualFreeEx(hProcess, lngAddress, 0x4096, MEM_RELEASE);
- CloseHandle(hProcess);
- }
隐藏托盘图标
最新推荐文章于 2024-04-05 09:47:55 发布