本文整理汇总了C++中Bitmap::GetHICON方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitmap::GetHICON方法的具体用法?C++ Bitmap::GetHICON怎么用?C++ Bitmap::GetHICON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitmap
的用法示例。
在下文中一共展示了Bitmap::GetHICON方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadImageFromFile
STDMETHODIMP CTaskbar7::SetTabsIcon(BSTR icon)
{
// Remove icon if icon path is empty
if (CComBSTR(icon) == CComBSTR(""))
{
if (m_isWindows7)
SetClassLong(m_hwnd, GCL_HICON, NULL);
return S_OK;
}
USES_CONVERSION;
Bitmap* bitmap = NULL;
HRESULT hr = LoadImageFromFile(OLE2W(icon), &bitmap);
// return a proper error
if (!SUCCEEDED(hr))
return hr;
// Do nothing on XP & Vista
if (!m_isWindows7) {
delete bitmap;
return S_OK;
}
HICON hIcon;
bitmap->GetHICON(&hIcon);
SetClassLong(m_hwnd, GCL_HICON, (LONG)hIcon);
// Cleanup the HICON & Bitmap
DestroyIcon(hIcon);
delete bitmap;
return S_OK;
}
示例2: LoadIconFromMem
// 读取图标(从内存中加载)
BOOL LoadIconFromMem(BYTE* pByte, DWORD dwSize, HICON &hIcon)
{
// 根据文件大小分配HGLOBAL内存
HGLOBAL hGlobal = GlobalAlloc( GMEM_MOVEABLE | GMEM_NODISCARD, dwSize );
if ( !hGlobal )
{
TRACE( _T( "Load (file): Error allocating memory\n" ) );
return FALSE;
};
char *pData = reinterpret_cast<char*>(GlobalLock(hGlobal));
if ( !pData )
{
TRACE( _T( "Load (file): Error locking memory\n" ) );
GlobalFree( hGlobal );
return FALSE;
};
// 将文件内容读到HGLOBAL内存中
memcpy(pData, pByte, dwSize);
GlobalUnlock( hGlobal );
// 利用hGlobal内存中的数据创建stream
IStream *pStream = NULL;
if ( CreateStreamOnHGlobal( hGlobal, TRUE, &pStream ) != S_OK )
{
return FALSE;
}
Bitmap* pBitmap = Gdiplus::Bitmap::FromStream(pStream);
// 要加上这一句,否则由GlobalAlloc得来的hGlobal内存没有被释放,导致内存泄露,由于
// CreateStreamOnHGlobal第二个参数被设置为TRUE,所以调用pStream->Release()会自动
// 将hGlobal内存(参见msdn对CreateStreamOnHGlobal的说明)
pStream->Release();
HBITMAP hBitmap = NULL;
Status status = pBitmap->GetLastStatus();
if(Ok == status)
{
status = pBitmap->GetHICON(&hIcon);
delete pBitmap;
if(Ok == status)
{
return TRUE;
}
}
return FALSE;
}
示例3: image
/*************************************
* Overlay
*************************************/
STDMETHODIMP CTaskbar7::SetOverlayIcon(BSTR path, BSTR description)
{
if (!m_pTaskbarList || m_parentHwnd == NULL)
return S_OK;
USES_CONVERSION;
wstring image(OLE2W(path));
wstring desc(OLE2W(description));
// if no path is given, we remove the overlay
if (image.empty())
{
if (m_isWindows7)
return m_pTaskbarList->SetOverlayIcon(m_parentHwnd, NULL, L"");
return S_OK;
}
Bitmap* bitmap = NULL;
HRESULT hr = LoadImageFromFile(image, &bitmap);
if (!SUCCEEDED(hr))
return hr;
// Do nothing on XP & Vista
if (!m_isWindows7)
{
delete bitmap;
return S_OK;
}
HICON pIcon;
bitmap->GetHICON(&pIcon);
// Sets the overlay icon
hr = m_pTaskbarList->SetOverlayIcon(m_parentHwnd, pIcon, desc.c_str());
DestroyIcon(pIcon);
delete bitmap;
return hr;
}
示例4: do_image_list
//----------------------------------------------------------------------------------------------------------------------
// DO IMAGE LIST
//----------------------------------------------------------------------------------------------------------------------
void cListView :: do_image_list ( const cFigViewItemList * pList )
{
mojo::cPtI IconSize = get_icon_size ();
int iDimX = IconSize.x;
int iDimY = IconSize.y;
HIMAGELIST hIL = ImageList_Create ( iDimX, iDimY, LR_CREATEDIBSECTION | ILC_COLOR32, pList->qty(), 1 );
//------------------------------------------
// LOAD DEFAULT IMAGES
//------------------------------------------
const int * aiBitmap = default_bitmap_ids ();
for ( int i = 0; aiBitmap[i]; i++ )
{
HANDLE hBitmap = LoadImage ( g_hInstance, MAKEINTRESOURCE ( aiBitmap[i] ), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
ImageList_Add ( hIL, (HBITMAP) hBitmap, NULL );
}
int iItemIndex = 0;
for ( cFigViewItem * p = pList->pHead; p; p = p->pNext, iItemIndex++ )
{
bool bLoadedFromFile = false;
int iImageIndex = 0;
//-------------------------------
// TRY TO LOAD IMAGE FROM FILE
//-------------------------------
if ( p->sIconPath.len() )
{
if ( ! file_exists ( p->sIconPath.cstr() ) )
{
mojo::put_ad_lib_memo ( mojo::cMemo::error, L"Image file not found", L"%s", p->sIconPath.cstr() );
cStrW s;
s.f ( L"Image file not found: %s", p->sIconPath.cstr() );
LOG ( s.cstr() );
}
else
{
HICON hIcon;
Bitmap bm ( p->sIconPath.cstr() );
if ( ! ( Ok == bm.GetLastStatus() ) )
LOG_V ( L"Bitmap constructor failed with %s.", p->sIconPath.cstr() );
else
{
bm.GetHICON(&hIcon);
if ( Ok != bm.GetLastStatus() )
LOG_V ( L"Bitmap::GetHICON() failed with %s", p->sIconPath.cstr() );
else
{
iImageIndex = ImageList_AddIcon( hIL, hIcon );
bLoadedFromFile = true;
}
}
if ( ! bLoadedFromFile)
mojo::put_ad_lib_memo ( mojo::cMemo::error, L"Unable to display image file", L"%s", p->sIconPath.cstr() );
}
}
if ( ! bLoadedFromFile )
{
iImageIndex = 0;;
}
#if 0
LVITEM lvi;
ZeroMemory ( &lvi, sizeof(lvi) );
lvi.mask = LVIF_IMAGE;
lvi.iItem = iItemIndex;
lvi.iImage = iImageIndex;
ListView_SetItem ( hwnd, &lvi );
#endif
}
HIMAGELIST hResult = ListView_SetImageList ( hwnd, hIL, LVSIL_NORMAL );
hResult;
}