1在.h文件里定义变量:
protected:
HICON m_hIcon;
HICON m_hIconArray[4];//托盘区动画图标数组
int m_nIconPos; //当前托盘区显示图标
2.cpp文件中加入:
//主程序对话框类构造函数
CCDROMControlDlg::CCDROMControlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCDROMControlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCDROMControlDlg)
m_nIconPos = 0; //托盘区动画图标从m_hIconArray[0]开始显示
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//加载托盘区动画图标
m_hIconArray[0] = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hIconArray[1] = AfxGetApp()->LoadIcon(IDI_ICON1);
m_hIconArray[2] = AfxGetApp()->LoadIcon(IDI_ICON2);
m_hIconArray[3] = AfxGetApp()->LoadIcon(IDI_ICON3);
}
//定时器消息处理函数,用来实现动画图标
void CCDROMControlDlg::OnTimer(UINT nIDEvent)
{
NOTIFYICONDATA nc;
nc.cbSize = sizeof(NOTIFYICONDATA);
if(m_nIconPos==3)
m_nIconPos=0;
nc.hIcon = m_hIconArray[m_nIconPos++];
nc.hWnd = m_hWnd;
lstrcpy(nc.szTip,"动画效果托盘图标");
nc.uCallbackMessage = WM_NOTIFYICON; //自定义最小化托盘消息
nc.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nc.uID = IDC_NOTIFYICON;
Shell_NotifyIcon(NIM_MODIFY, &nc);
CDialog::OnTimer(nIDEvent);
}
3在最小化函数中加入设置定时: SetTimer(1,200,NULL);//设置定时器
在销毁窗口加入关闭定时器: KillTimer(1);
至此您就可以加入有动画效果的托盘图标了