试试看,是不是你要的功能。
添加头文件vector和atlimage.h
std::vectorvecFileName;
CFileDialog *lpszOpenFile;
lpszOpenFile = new CFileDialog(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_PATHMUSTEXIST, NULL, NULL);//生成一个对话框
if (lpszOpenFile->DoModal() == IDOK)
{
POSITION pos = lpszOpenFile->GetStartPosition();
while (pos != NULL)
{
vecFileName.push_back(lpszOpenFile->GetNextPathName(pos));
}
}
delete lpszOpenFile;
CImage img;
CRect rcClient;
GetClientRect(rcClient);
CDC* pDC = GetDC();
::SetStretchBltMode(pDC->m_hDC, HALFTONE);
::SetBrushOrgEx(pDC->m_hDC, 0, 0, NULL);
for (size_t i = 0; i < vecFileName.size(); i++)
{
if (!img.IsNull())
{
img.Destroy();
}
img.Load(vecFileName.at(i));
if (img)
{
//将客户区分成16块
CRect rcTemp(rcClient.Width() / 4 * (i % 4), rcClient.Height() / 4 * (i / 4),
rcClient.Width() / 4 * ((i % 4) + 1), rcClient.Height() / 4 * ((i / 4) + 1));
img.Draw(pDC->m_hDC, rcTemp);
}
}
img.Destroy();
pDC->DeleteDC();
vecFileName.clear();
需要使用打开文件对话框来获取打开的文件,之后可以使用相关方法(比如GDI+)显示图片