admin管理员组文章数量:1532030
对于使用托盘图标的程序,当我们通过强制结束进程,或者程序异常退出时,托盘图标区域总会有托盘图标的残留,需要我们用鼠标移到残留区域时,托盘图标才会自动消失。有时我们需要去做相关的处理,比如在软件升级时,会强制结束进程,这时需要自动的去清除残留的托盘图标。通过研究和查阅网络,整理如下的方法。
hWnd = ::FindWindow( "Shell_TrayWnd", NULL );
hWnd = ::FindWindowEx( hWnd, 0, "TrayNotifyWnd", NULL );
hWndPager = ::FindWindowEx( hWnd, 0, "SysPager", NULL );
hWnd = ::FindWindowEx( hWnd, 0, "ToolbarWindow32", NULL); // 对于Win2000,没有SysPager窗口
hWnd = ::FindWindowEx( hWndPager, 0, "ToolbarWindow32", NULL ); // XP有SysPager窗口
RECT rTrayToolBar;
::GetClientRect(hwnd, &rTrayToolBar); // 获取托盘图标区域坐标
for(int x = 1; x < rTrayToolBar.right - 1; x++)
{
for (int y = 1; y < rTrayToolBar.bottom; y++ )
{
::SendMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
}
}
HWND hWnd,hWndPaper;
unsigned long lngPID;
HANDLE hProcess;
LPVOID lngAddress;
hWnd = ::FindWindow( "Shell_TrayWnd", NULL );
hWnd = ::FindWindowEx( hWnd, 0, "TrayNotifyWnd", NULL );
hWndPaper = ::FindWindowEx( hWnd, 0, "SysPager", NULL );
hWnd = ::FindWindowEx( hWnd, 0, "ToolbarWindow32", NULL );
hWnd = ::FindWindowEx( hWndPaper, 0, "ToolbarWindow32", NULL );
ret = GetWindowThreadProcessId
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 );
{
ret = ::SendMessage( hWnd, TB_GETBUTTON, i, long(lngAddress) );
ret = ReadProcessMemory( hProcess, LPVOID(long(lngAddress) + 16), &lngTextAdr, 4, 0 );
{
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,"阿里旺旺" ); // 通过窗口名称来比对
{
::SendMessage( hWnd, TB_HIDEBUTTON, lngButtonID, 1 );
}
}
}
VirtualFreeEx( hProcess, lngAddress, 0X4096, MEM_RELEASE );
CloseHandle( hProcess );
版权声明:本文标题:XPWIN7系统中删除残留托盘图标的方法 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1726832742a1086312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论