Reputation: 57
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);
}
i want draw a title with a image in dialog. Don't use Picture Control please help me.
Upvotes: 0
Views: 2188
Reputation: 13089
Here's the code I use for loading other image formats. It relies on GDI+, so you need to initialize & shutdown, before and after it's been used (once per program is enough)
Load Routine:
// 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;
}
Init/shutdown
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;
}
Naturally, this is for a dialog-based app (dialog is defined in resource.rc) - rather than a frame-based one, or an MFC one. The point is, you just need to initialize before you use it, and shutdown afterwards.
Upvotes: 5
Reputation: 57
i were do it with :
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);
and i were successful :X thanks:X
Upvotes: 0