C++ Code_ImageList

本博客介绍了如何在对话框中创建图像列表,并通过该列表绘制图像。具体步骤包括在资源编辑器中添加图标资源,然后在对话框类中初始化图像列表并添加这些图标。此外,展示了如何在绘图过程中利用图像列表进行绘图操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主题

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);
// }
// }
 

效果图:

011928021495359.png

  

完成 CImageList的类 高级空间
 




转载于:https://www.cnblogs.com/xe2011/p/3885722.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值