C++列表视图控件怎样添加图片
1个回答
展开全部
ATLINLINE HBITMAP AtlLoadGdiplusImage(ATL::_U_STRINGorID bitmap, ATL::_U_STRINGorID type = (UINT) 0)
{
USES_CONVERSION;
static bool s_bInitied = false;
if( !s_bInitied ) {
s_bInitied = true;
Gdiplus::GdiplusStartupInput gsi;
Gdiplus::GdiplusStartupOutput gso;
ULONG uToken = 0;
Gdiplus::GdiplusStartup(&uToken, &gsi, &gso);
}
Gdiplus::Bitmap* pBitmap = NULL;
if( HIWORD(bitmap.m_lpstr) != NULL ) {
// Load from filename
pBitmap = new Gdiplus::Bitmap(T2CW(bitmap.m_lpstr));
}
else if( type.m_lpstr != NULL && type.m_lpstr != RT_BITMAP ) {
// Loading PNG, JPG resources etc
WTL::CResource res;
if( !res.Load(type, bitmap) ) return NULL;
DWORD dwSize = res.GetSize();
HANDLE hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
if( hMemory == NULL ) return NULL;
::memcpy(::GlobalLock(hMemory), res.Lock(), dwSize);
::GlobalUnlock(hMemory);
IStream* pStream = NULL;
if( FAILED( ::CreateStreamOnHGlobal(hMemory, TRUE, &pStream) ) ) {
::GlobalFree(hMemory);
return FALSE;
}
pBitmap = new Gdiplus::Bitmap(pStream);
pStream->Release();
}
else {
// This only loads BMP resources
pBitmap = new Gdiplus::Bitmap(_Module.GetResourceInstance(), (LPCWSTR) (UINT) bitmap.m_lpstr);
}
if( pBitmap == NULL ) return NULL;
HBITMAP hBitmap = NULL;
pBitmap->GetHBITMAP(NULL, &hBitmap);
delete pBitmap;
return hBitmap;
}
{
USES_CONVERSION;
static bool s_bInitied = false;
if( !s_bInitied ) {
s_bInitied = true;
Gdiplus::GdiplusStartupInput gsi;
Gdiplus::GdiplusStartupOutput gso;
ULONG uToken = 0;
Gdiplus::GdiplusStartup(&uToken, &gsi, &gso);
}
Gdiplus::Bitmap* pBitmap = NULL;
if( HIWORD(bitmap.m_lpstr) != NULL ) {
// Load from filename
pBitmap = new Gdiplus::Bitmap(T2CW(bitmap.m_lpstr));
}
else if( type.m_lpstr != NULL && type.m_lpstr != RT_BITMAP ) {
// Loading PNG, JPG resources etc
WTL::CResource res;
if( !res.Load(type, bitmap) ) return NULL;
DWORD dwSize = res.GetSize();
HANDLE hMemory = ::GlobalAlloc(GMEM_MOVEABLE, dwSize);
if( hMemory == NULL ) return NULL;
::memcpy(::GlobalLock(hMemory), res.Lock(), dwSize);
::GlobalUnlock(hMemory);
IStream* pStream = NULL;
if( FAILED( ::CreateStreamOnHGlobal(hMemory, TRUE, &pStream) ) ) {
::GlobalFree(hMemory);
return FALSE;
}
pBitmap = new Gdiplus::Bitmap(pStream);
pStream->Release();
}
else {
// This only loads BMP resources
pBitmap = new Gdiplus::Bitmap(_Module.GetResourceInstance(), (LPCWSTR) (UINT) bitmap.m_lpstr);
}
if( pBitmap == NULL ) return NULL;
HBITMAP hBitmap = NULL;
pBitmap->GetHBITMAP(NULL, &hBitmap);
delete pBitmap;
return hBitmap;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |