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);
}
Run Code Online (Sandbox Code Playgroud)
我想用对话框中的图像绘制标题.不要使用优化校准请帮帮我.
这是我用于加载其他图像格式的代码.它依赖于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;
}
Run Code Online (Sandbox Code Playgroud)
初始化/关机
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;
}
Run Code Online (Sandbox Code Playgroud)
当然,这适用于基于对话框的应用程序(对话框在resource.rc中定义) - 而不是基于框架的应用程序或MFC框架.关键是,您只需在使用之前进行初始化,然后关闭.