本文转载自http://blog.csdn.net/happyhell/article/details/1865014
/************************************************************************/
/* 该函数主要是实现对系统托盘的图标刷新的问题 */
/* */
/* 由于托盘程序如果被强行杀掉进程等操作后,在托盘中的图标不能自动删除 */
/* 顾运用以下的方法,实现模拟鼠标点击托盘图标,使得图标刷新 */
/* */
/* 使用方法: 直接调用 RefurbishTray 函数就可以了 */
/* 作 者: Richard */
/* 邮 箱:
happyhell@gmail.com */
/* 日 期: 2006-11-06 */
/************************************************************************/
/* 日 期: 2006-11-06 */
/************************************************************************/
void CGreenSpanDlg::RefurbishTray()
{
RECT WindowRect ;
POINT point ;
int x ;
int y ;
// int SmallIconWidth , SmallIconHeight ;
// SmallIconWidth = GetSystemMetrics(SM_CXSMICON);
// SmallIconHeight = GetSystemMetrics(SM_CYSMICON);
{
RECT WindowRect ;
POINT point ;
int x ;
int y ;
// int SmallIconWidth , SmallIconHeight ;
// SmallIconWidth = GetSystemMetrics(SM_CXSMICON);
// SmallIconHeight = GetSystemMetrics(SM_CYSMICON);
HWND hwnd = GetSysTrayWnd() ;
::GetWindowRect(hwnd , &WindowRect ) ;
::GetCursorPos(&point) ;
::GetWindowRect(hwnd , &WindowRect ) ;
::GetCursorPos(&point) ;
for( x = 1 ; x < WindowRect.right - WindowRect.left - 1 ; x ++ )
{
for( y = 1 ; y < WindowRect.bottom - WindowRect.top - 1 ; y ++ )
{
SetCursorPos( WindowRect.left + x, WindowRect.top + y ) ;
Sleep(0);
}
{
for( y = 1 ; y < WindowRect.bottom - WindowRect.top - 1 ; y ++ )
{
SetCursorPos( WindowRect.left + x, WindowRect.top + y ) ;
Sleep(0);
}
}
// SetCursorPos(SmallIconWidth,SmallIconHeight);
}
}
/************************************************************************/
/* 该函数主要是获取系统托盘句柄 */
/* */
/* 这个方法只支持NT以上的版本,如果是NT 以下的版本,则需要根据
/* 任务栏窗口以及其子窗口结构 修改 */
/* 作 者: Richard */
/* 该函数主要是获取系统托盘句柄 */
/* */
/* 这个方法只支持NT以上的版本,如果是NT 以下的版本,则需要根据
/* 任务栏窗口以及其子窗口结构 修改 */
/* 作 者: Richard */
/* 邮 箱:
happyhell@gmail.com */
/* 日 期: 2006-11-06 */
/************************************************************************/
HWND CGreenSpanDlg::GetSysTrayWnd()
{
HWND hwnd ;
hwnd = ::FindWindow("Shell_TrayWnd", NULL ) ;
hwnd = ::FindWindowEx(hwnd, 0, "TrayNotifyWnd", NULL );
/* 日 期: 2006-11-06 */
/************************************************************************/
HWND CGreenSpanDlg::GetSysTrayWnd()
{
HWND hwnd ;
hwnd = ::FindWindow("Shell_TrayWnd", NULL ) ;
hwnd = ::FindWindowEx(hwnd, 0, "TrayNotifyWnd", NULL );
return hwnd ;
}
}