步骤简要如下:
1.创建ClmageList对象,指定图片的宽度和高度
2.将CImageList对象传递给CListCtrl对象
3.ClistCtrl增加item时,将图片ID和文字一起传入
具体代码如下:
ListImage.cpp代码如下
// ListImage.cpp : implementation file
//
#include "stdafx.h"
#include "practise.h"
#include "ListImage.h"
#define THUMWIDTH 75
#define THUMHEIGHT 55
// ListImage dialog
IMPLEMENT_DYNAMIC(ListImage, CDialog)
ListImage::ListImage(CWnd* pParent /*=NULL*/)
: CDialog(ListImage::IDD, pParent)
{
}
ListImage::~ListImage()
{
}
void ListImage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
}
BEGIN_MESSAGE_MAP(ListImage, CDialog)
ON_BN_CLICKED(IDC_BUTTON1, &ListImage::OnBnClickedButton1)
ON_BN_CLICKED(IDOK, &ListImage::OnBnClickedOk)
END_MESSAGE_MAP()
// ListImage message handlers
BOOL ListImage::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void ListImage::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
//文件对话框
CString FilePath;
CFileDialog FileDialog(true, _T(""), _T(""), OFN_EXPLORER,
_T("所有文件(*.*)|*.*||"), this);
//显示对话框
if(FileDialog.DoModal() == IDOK)
{
FilePath = FileDialo