用VC++在窗口的标题栏中增加动画图标
2010-06-23 20:40:44 来源:WEB开发网1.用AppWizard创建一个SDI空工程WndStyle;
2.在窗口的标题栏增加动画图标;
(1)创建位图资源,并按序放置所有位图文件(16*16);
(2)在工程工作区选择ResourceView面板,右击任一资源项。在弹出的快捷菜单中选择“Insert……”命令,打开“Insert Source”对话框。
(3)在“Resurece Type”列表框中选择“Bitmap”项,然后单击右边的“Import”按钮。
(4)打开“Import Resource”对话框,在文件列表框中选择要插入的位图文件,单击“Improt”按钮,插入选定的位图,然后将位图的ID值修改为需要的值“IDB_ANIM_IMGLIST”。
3.增加管理位图动画的文件;这里采用CImageList管理动画需要的多幅位图,因此需将AnimateIcon.cpp和AnimateIcon.h添加到工程文件中,步骤如下:
(1)将这两个文件复制到工程所在的文件夹中。
(2)在工程工作区选择“FileView”面板,右击“WndStyle files”。在弹出的快捷菜单中选择“Add Files to Project……”命令,然后在打开的“Add Files to Project”对话框双击要增加的文件。
清单 AnimateIcon.cpp和AnimateIcon.h
(AnimateIcon.cpp)
#include "stdafx.h"
#include "AnimateIcon.h"
// default constructor
CAnimateIcon::CAnimateIcon()
{
m_iImageCounter = -1;
m_iMaxNoOfImages = -99;
m_imgList.m_hImageList = NULL;
}
// default do nothing destructor
CAnimateIcon::~CAnimateIcon()
{
if (hPrevIcon)
DestroyIcon(hPrevIcon);
}
// This is the first function which needs to be called in order
// to fill the image list
// Parameters :
// ------------
// int IDOfImgListResource - pass the Resource ID of a toolbar resource
// containing the image list
// int numberOfImages - Number of images (16x16) in the toolbar resource
// transparentColor - RGB value of color you want to be transparent
BOOL CAnimateIcon::SetImageList(int IDOfImgListResource,int numberOfImages,COLORREF transparentColor)
{
if(numberOfImages <= 0)
return FALSE;
m_iMaxNoOfImages = numberOfImages;
VERIFY(m_imgList.Create(IDOfImgListResource,16,1,transparentColor));
return TRUE;
}
// This function needs to be called repetatively to show next image
// Parameters :
// ------------
// NONE
BOOL CAnimateIcon::ShowNextImage()
{
if(m_imgList.m_hImageList == NULL)
return FALSE;
m_iImageCounter++;
if(m_iImageCounter >= m_iMaxNoOfImages)
m_iImageCounter =0;
// extract the icon from imagelist
hIcon = m_imgList.ExtractIcon(m_iImageCounter);
// send the message to frame to update icon
HICON hPrevIcon = (HICON) AfxGetMainWnd()->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);
// Free the previous icon resource
if (hPrevIcon)
DestroyIcon(hPrevIcon);
return TRUE;
}
(AnimateIcon.h)
#if !defined(AFX_ANIMATEICON_H__47E058AD_6F69_11D2_B59C_
86DD54033006__INCLUDED_)
#define AFX_ANIMATEICON_H__47E058AD_6F69_11D2_B59C_
86DD54033006__INCLUDED_
class CAnimateIcon
{
protected :
// variable to hold the image list containing a series
// of icons
CImageList m_imgList;
// keep track of which image is current
int m_iImageCounter;
// store the max nos of images
int m_iMaxNoOfImages;
HICON hIcon;
HICON hPrevIcon ;
public:
CAnimateIcon();
~CAnimateIcon();
BOOL SetImageList(int IDOfImgListResource,int numberOfImages,COLORREF transparentColor);
BOOL ShowNextImage();
};
#endif //#define AFX_ANIMATEICON_H__47E058AD_6F69_11D2_B59C_
86DD54033006__INCLUDED_
更多精彩
赞助商链接