包含ATL头文件
在stdafx.h 添加
#include <atlimage.h>
在本地加载图片。
m_Image.Load(L"D:\\我的文档\\Visual Studio 2005\\Projects\\20100115\\CCImageTestDlg\\CCImageTestDlg\\res\\my.png");
CClientDC dc(this);
m_Image.Draw(dc, 0, 0, m_Image.GetWidth(), m_Image.GetHeight(), 0, 0, m_Image.GetWidth(), m_Image.GetHeight());
资源中文件的显示:
bool ImageFromIDResource(void)
{
UINT nID = IDR_PNG1;
LPCTSTR sTR = _T("PNG");
//UINT nID = IDB_BITMAP1;
//LPCTSTR sTR = RT_BITMAP;
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
if (!hRsrc)
return FALSE;
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return FALSE;
// Allocate global memory on which to create stream
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
memcpy(pmem,lpRsrc,len);
IStream* pstm;
CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
// load from stream
m_Image.Load(pstm);
CClientDC dc(this);
m_Image.Draw(dc, 0, 0, m_Image.GetWidth(), m_Image.GetHeight(), 0, 0, m_Image.GetWidth(), m_Image.GetHeight());
// free/release stuff
GlobalUnlock(m_hMem);
pstm->Release();
FreeResource(lpRsrc);
return false;
}
posted on 2010-03-22 16:37
漂漂 阅读(1044)
评论(2) 编辑 收藏 引用