刷新托盘图标
来源:互联网 发布:诺基亚e66软件 编辑:程序博客网 时间:2024/05/16 01:51
void Refurbish(HWND hToolbarWindow32)
{
if (hToolbarWindow32)
{
DWORD pid = 0;
LPVOID lngAdress = NULL;
long lngButtonID = 0;
LPVOID lngText = NULL;
LPVOID lngRect = NULL;
RECT rc = { 0 };
char strBuff[1024] = { 0 };
GetWindowThreadProcessId(hToolbarWindow32, &pid);
if (NULL == pid)
{
return;
}
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, true, pid);
if (NULL == hProcess)
{
return;
}
int iNum = ::SendMessage(hToolbarWindow32, TB_BUTTONCOUNT, NULL, NULL);
lngAdress = VirtualAllocEx(hProcess, 0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
lngRect = VirtualAllocEx(hProcess, 0, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
lngText = VirtualAllocEx(hProcess, 0, 1024, MEM_COMMIT, PAGE_READWRITE);
for (int i = 0; i <= iNum; i++)
{
long lngTempID = lngButtonID;
int ret = ::SendMessage(hToolbarWindow32, TB_GETBUTTON, i, (LPARAM)(lngAdress));
if (ret != 0)
{
ret = ReadProcessMemory(hProcess, LPVOID((long)lngAdress + 4), &lngButtonID, 4, 0);
ret = ::SendMessage(hToolbarWindow32, TB_GETBUTTONTEXT, (WPARAM)lngButtonID, (LPARAM)(lngText));//一定是buttonID,网上都是i,这样过去到的text不是对应托盘的text.
ret = ReadProcessMemory(hProcess, lngText, strBuff, 1024, 0);
ret = ::SendMessage(hToolbarWindow32, TB_GETITEMRECT, (WPARAM)i, (LPARAM)(lngRect));
ret = ReadProcessMemory(hProcess, lngRect, &rc, sizeof(rc), 0);
if (strcmp(strBuff,"微信")==0)//通过托盘tooltip信息查找自己的程序
{
int iGap = rc.right - rc.left;
::SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM(rc.right - (iGap / 2), rc.bottom -(iGap / 2)));
i--;
//::SendMessage(hToolbarWindow32, TB_DELETEBUTTON, i, 0);
}
}
}
VirtualFreeEx(hProcess, lngAdress, 0x4096, MEM_RELEASE);
VirtualFreeEx(hProcess, lngText, 1024, MEM_RELEASE);
VirtualFreeEx(hProcess, lngRect, sizeof(RECT), MEM_RELEASE);
CloseHandle(hProcess);
}
}
//获取普通托盘区窗口句柄
HWND FindTrayWnd()
{
HWND hWnd = NULL;
HWND hWndPaper = NULL;
//任务栏窗口
if ((hWnd = FindWindow(_T("Shell_TrayWnd"), NULL)) != NULL)
{
//任务栏右边托盘图标+时间区
if ((hWnd = FindWindowEx(hWnd, 0, _T("TrayNotifyWnd"), NULL)) != NULL)
{
//不同系统可能有可能没有这层
hWndPaper = FindWindowEx(hWnd, 0, _T("SysPager"), NULL);
//托盘图标窗口
if (!hWndPaper)
hWnd = FindWindowEx(hWnd, 0, _T("ToolbarWindow32"), NULL);
else
hWnd = FindWindowEx(hWndPaper, 0, _T("ToolbarWindow32"), NULL);
}
}
return hWnd;
}
//获取溢出托盘区窗口句柄
HWND FindNotifyIconOverflowWindow()
{
HWND hWnd = NULL;
hWnd = FindWindow(_T("NotifyIconOverflowWindow"), NULL);
if (hWnd != NULL)
{
hWnd = FindWindowEx(hWnd, NULL, _T("ToolbarWindow32"), NULL);
}
return hWnd;
}
//刷新托盘区域
void RefurbishTray()
{
HWND hToolbarWindow32=NULL;
HWND hToolbarOverWindow32=NULL;
hToolbarWindow32 = FindTrayWnd();
hToolbarOverWindow32 = FindNotifyIconOverflowWindow();
if (NULL != hToolbarWindow32)
{
Refurbish(hToolbarWindow32);//刷新托盘区域
}
if (NULL != hToolbarOverWindow32)
{
Refurbish(hToolbarOverWindow32);//刷新溢出区域
}
}
{
if (hToolbarWindow32)
{
DWORD pid = 0;
LPVOID lngAdress = NULL;
long lngButtonID = 0;
LPVOID lngText = NULL;
LPVOID lngRect = NULL;
RECT rc = { 0 };
char strBuff[1024] = { 0 };
GetWindowThreadProcessId(hToolbarWindow32, &pid);
if (NULL == pid)
{
return;
}
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, true, pid);
if (NULL == hProcess)
{
return;
}
int iNum = ::SendMessage(hToolbarWindow32, TB_BUTTONCOUNT, NULL, NULL);
lngAdress = VirtualAllocEx(hProcess, 0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
lngRect = VirtualAllocEx(hProcess, 0, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
lngText = VirtualAllocEx(hProcess, 0, 1024, MEM_COMMIT, PAGE_READWRITE);
for (int i = 0; i <= iNum; i++)
{
long lngTempID = lngButtonID;
int ret = ::SendMessage(hToolbarWindow32, TB_GETBUTTON, i, (LPARAM)(lngAdress));
if (ret != 0)
{
ret = ReadProcessMemory(hProcess, LPVOID((long)lngAdress + 4), &lngButtonID, 4, 0);
ret = ::SendMessage(hToolbarWindow32, TB_GETBUTTONTEXT, (WPARAM)lngButtonID, (LPARAM)(lngText));//一定是buttonID,网上都是i,这样过去到的text不是对应托盘的text.
ret = ReadProcessMemory(hProcess, lngText, strBuff, 1024, 0);
ret = ::SendMessage(hToolbarWindow32, TB_GETITEMRECT, (WPARAM)i, (LPARAM)(lngRect));
ret = ReadProcessMemory(hProcess, lngRect, &rc, sizeof(rc), 0);
if (strcmp(strBuff,"微信")==0)//通过托盘tooltip信息查找自己的程序
{
int iGap = rc.right - rc.left;
::SendMessage(hToolbarWindow32, WM_MOUSEMOVE, 0, MAKELPARAM(rc.right - (iGap / 2), rc.bottom -(iGap / 2)));
i--;
//::SendMessage(hToolbarWindow32, TB_DELETEBUTTON, i, 0);
}
}
}
VirtualFreeEx(hProcess, lngAdress, 0x4096, MEM_RELEASE);
VirtualFreeEx(hProcess, lngText, 1024, MEM_RELEASE);
VirtualFreeEx(hProcess, lngRect, sizeof(RECT), MEM_RELEASE);
CloseHandle(hProcess);
}
}
//获取普通托盘区窗口句柄
HWND FindTrayWnd()
{
HWND hWnd = NULL;
HWND hWndPaper = NULL;
//任务栏窗口
if ((hWnd = FindWindow(_T("Shell_TrayWnd"), NULL)) != NULL)
{
//任务栏右边托盘图标+时间区
if ((hWnd = FindWindowEx(hWnd, 0, _T("TrayNotifyWnd"), NULL)) != NULL)
{
//不同系统可能有可能没有这层
hWndPaper = FindWindowEx(hWnd, 0, _T("SysPager"), NULL);
//托盘图标窗口
if (!hWndPaper)
hWnd = FindWindowEx(hWnd, 0, _T("ToolbarWindow32"), NULL);
else
hWnd = FindWindowEx(hWndPaper, 0, _T("ToolbarWindow32"), NULL);
}
}
return hWnd;
}
//获取溢出托盘区窗口句柄
HWND FindNotifyIconOverflowWindow()
{
HWND hWnd = NULL;
hWnd = FindWindow(_T("NotifyIconOverflowWindow"), NULL);
if (hWnd != NULL)
{
hWnd = FindWindowEx(hWnd, NULL, _T("ToolbarWindow32"), NULL);
}
return hWnd;
}
//刷新托盘区域
void RefurbishTray()
{
HWND hToolbarWindow32=NULL;
HWND hToolbarOverWindow32=NULL;
hToolbarWindow32 = FindTrayWnd();
hToolbarOverWindow32 = FindNotifyIconOverflowWindow();
if (NULL != hToolbarWindow32)
{
Refurbish(hToolbarWindow32);//刷新托盘区域
}
if (NULL != hToolbarOverWindow32)
{
Refurbish(hToolbarOverWindow32);//刷新溢出区域
}
}
阅读全文
0 0
- 刷新托盘图标
- VB 终止指定进程 ,刷新托盘图标
- Delphi清除右下角的托盘上无用的托盘图标(刷新托盘)
- VC 刷新托盘区图标(模拟鼠标滑过)
- VC 刷新托盘区图标(模拟鼠标滑过)
- 托盘图标
- 托盘图标
- 托盘图标
- 托盘图标
- 托盘图标
- Delphi刷新托盘,去掉非正常退出的程序的托盘图标
- Delphi刷新托盘,去掉非正常退出的程序的托盘图标
- AIR 托盘处理,托盘图标,文件托盘
- 【进程处理】4,刷新任务栏托盘区,清除异常关闭进程的残留图标
- 托盘图标提示
- 托盘图标提示
- 如何制作托盘图标?
- VB中的托盘图标
- (01)Structs初学笔记——开篇
- git命令行
- 数据结构-->c构建线性表
- Linux CentOS6.7 jdk1.8.0_11 安装Elasticsearch5.0.1
- treeview 使用
- 刷新托盘图标
- 0基础lua学习(十三)Metatable
- 单例设计模式
- HDU-2001(两点距离问题)
- win7 python3.6安装教程及环境配置
- Mybatis入门级教程(一)
- 项目管理中的成本计算
- 一中OJ #1086 最大子矩阵 | 贪心连续子序列 + 平面降维压缩 | 解题报告
- 设计模式:单例模式