C++ Code_ImageList

主题

1.  创建图像列表

2.  使用图像列表绘图

3.  

4.  

5.  

 
 

代码::创建图像列表

  

双击 Cproject03Dlg在
    下面添加 1 句
/////////////////////////////////////////////////////////////////////////////
// CProject01Dlg dialog
// class CProject01Dlg : public CDialog
// {
// Construction
// public:
// CProject01Dlg(CWnd* pParent = NULL); // standard constructor
    CImageList m_ImgLst;
 
手动在资源编辑器中添加 3 个Icon资源
 
双击 OnInitDialog()在  
// TODO: Add extra initialization here
添加如下代码
 
// TODO: Add extra initialization here
m_ImgLst.Create( 32 , 32 ,ILC_COLOR24 | ILC_MASK, 1 , 0 );
m_ImgLst.Add( LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1)) );
m_ImgLst.Add( LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2)) );
m_ImgLst.Add( LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3)) );
 
 
使用图像列表绘图
 
CImageList m_ImgLst;
双击OnPaint()添加如下代码
 
//void CProject01Dlg::OnPaint()
//{
// if (IsIconic())
// {
// CPaintDC dc(this); // device context for painting
//
// SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
//
// // Center icon in client rectangle
// int cxIcon = GetSystemMetrics(SM_CXICON);
// int cyIcon = GetSystemMetrics(SM_CYICON);
// CRect rect;
// GetClientRect(&rect);
// int x = (rect.Width() - cxIcon + 1) / 2;
// int y = (rect.Height() - cyIcon + 1) / 2;
//
// // Draw the icon
// dc.DrawIcon(x, y, m_hIcon);
// }
// else
// {
// CDialog::OnPaint();
        CDC * pDC = GetDC();
        CPoint pt;
        pt.x = 30 ;
        pt.y = 50 ;
        for ( int i = 0 ;i < 3 ;i ++ )
        {
            pt.x += 60 ;
            m_ImgLst.Draw(pDC,i,pt,ILD_NORMAL);
        }
        ReleaseDC(pDC);
// }
// }
 

效果图:

  

完成 CImageList的类 高级空间
 




posted @ 2014-08-01 19:28  XE2011  阅读(594)  评论(0编辑  收藏  举报