如何在对话框中预览位图


在开发应用程序中,有时需要定制通用对话框,比如需要预览位图的文件对话框

Windows界面开发

slllll 12 years, 6 months ago

这个比较简单吧,先通过文件创建位图,然后把位图画到想显示该位图的窗口上就行了,实例代码如下:
BOOL LoadMyBitmap( CString strPath, CBitmap *pBitmap )
{
HBITMAP hb = (HBITMAP)LoadImage(::AfxGetApp()->m_hInstance, strPath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );

if (pBitmap->GetSafeHandle())
{
HGDIOBJ tdb = pBitmap->Detach();
::DeleteObject( tdb );
}
if (NULL != hb)
{
BOOL b = pBitmap->Attach( hb );
return TRUE;
}

return FALSE;
}

if (NULL != m_Bmp.m_hObject)
{
m_HeadLeftBmp.GetBitmap(&bmpHeaderLeft);
mem.SelectObject(&m_HeadLeftBmp);
pDC->StretchBlt(0, 0, bmpHeaderLeft.bmWidth, iHeadHeight,
&mem, 0, 0, bmpHeaderLeft.bmWidth, bmpHeaderLeft.bmHeight, SRCCOPY);
pDC->SetBkMode(TRANSPARENT);
}

哔哔———— answered 12 years, 6 months ago

Your Answer