vc 刷新系统托盘图标

本文转载自http://blog.csdn.net/happyhell/article/details/1865014

/************************************************************************/
/*       该函数主要是实现对系统托盘的图标刷新的问题                     */
/*                                                                      */
/*  由于托盘程序如果被强行杀掉进程等操作后,在托盘中的图标不能自动删除  */
/*  顾运用以下的方法,实现模拟鼠标点击托盘图标,使得图标刷新            */
/*                                                                      */
/*  使用方法: 直接调用   RefurbishTray 函数就可以了                    */
/*  作    者: Richard                                                     */

/*  邮    箱:  happyhell@gmail.com                                        */
/*  日    期: 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);
 HWND hwnd = GetSysTrayWnd()  ; 
 ::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);
  }
 }
// SetCursorPos(SmallIconWidth,SmallIconHeight);
/************************************************************************/
/*       该函数主要是获取系统托盘句柄                                   */
/*                                                                      */
/*  这个方法只支持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 );
 return hwnd ;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值