void CCreateList::paintRowList(CDialogEx* CCurent, int wBeginX, int wBeginY)
{
CPaintDC dc(CCurent);
CDC *cdc,cc;
cdc=CCurent->GetDC();
HANDLE hbitmap;
hbitmap = LoadImage(0,L"C:\\PIC.png",IMAGE_BITMAP,100,100,0x00000010);
cc.CreateCompatibleDC(cdc);
cc.SelectObject(hbitmap);
dc.BitBlt(100,100,100,100,&cc,0,0,SRCCOPY);
}
我想用对话框中的图像绘制标题。请勿使用优化校准帮助我。
答案 0 :(得分:5)
这是我用于加载其他图像格式的代码。它依赖于GDI +,因此您需要初始化&关闭,使用之前和之后(每个程序就足够了)
加载例程:
// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
HBITMAP result=NULL;
Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
bitmap->GetHBITMAP(NULL, &result);
delete bitmap;
return result;
}
<强>初始化/关闭强>
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
static ULONG_PTR gdiplusToken;
// so we can load all the image formats that windows supports natively - (I'm using a transparent PNG on the main dialog)
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// make things look pretty
InitCommonControls();
// run the app
//DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
//
//
//
// clean-up stuff
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}
当然,这适用于基于对话框的应用程序(对话框在resource.rc中定义) - 而不是基于框架的应用程序或MFC版本。关键是,您只需要在使用之前进行初始化,然后关闭。
答案 1 :(得分:0)
我是这样做的:
CString strFileName;
strFileName="C:\\PIC.bmp";
BITMAP bmpPro;
HBITMAP bmpHandle=(HBITMAP)LoadImage(NULL,strFileName,IMAGE_BITMAP,0,0, LR_LOADFROMFILE| LR_CREATEDIBSECTION);
CBitmap bmpPicture;
CDC mdcPicture;
bmpPicture.Attach(bmpHandle);
bmpPicture.GetBitmap(&bmpPro);
mdcPicture.CreateCompatibleDC( &dc);
CBitmap * bmpPrevious =
mdcPicture.SelectObject(&bmpPicture);
dc.BitBlt(wCurrent, wBeginY,
header[i].getWidthOfHeader(), wHeight,
&mdcPicture, 0, 0, SRCCOPY);
我成功了:X 感谢:X