Bitmap::FromResource(HINSTANCE, WCHAR) , problem
-
I use the code "Bitmap::FromResource(HINSTANCE, WCHAR)" to load the bmp pic form res and then to fill a rectangle.but can not get a bitmap. My project is mfc project. so my first question is how to get hte handle of the HINSTANTCE and the second is the wchar parameter, I use "MAKEINTRESOURCE(pResId)" to get he pic name, but get a blank. and why? whether the gdi+ need more configuration or any other reason. below is my the whole code
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(pResId), RT_BITMAP);
CString src = MAKEINTRESOURCE(pResId);
int strLen = 0;
strLen =src.GetLength();
WCHAR* ch = new WCHAR[strLen];
wcscpy(ch, CT2CW(src));
Bitmap* pBitmap = Bitmap::FromResource(hInstResource, ch);
if(!FindResource(hInstResource, src, RT_BITMAP))
{
AfxMessageBox("Fail load pic!", MB_OK, 0);
}graphics.DrawImage(pBitmap, 75,35);
TextureBrush* pTextureBrush = new TextureBrush(pBitmap, WrapModeTileFlipY);
graphics.FillRectangle(pTextureBrush, 50,300,200,80);
Color m_penColor(233,100,54);
Pen pen1(m_penColor, 1);
graphics.DrawRectangle(&pen1, 50,300,200,80);
-
I use the code "Bitmap::FromResource(HINSTANCE, WCHAR)" to load the bmp pic form res and then to fill a rectangle.but can not get a bitmap. My project is mfc project. so my first question is how to get hte handle of the HINSTANTCE and the second is the wchar parameter, I use "MAKEINTRESOURCE(pResId)" to get he pic name, but get a blank. and why? whether the gdi+ need more configuration or any other reason. below is my the whole code
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(pResId), RT_BITMAP);
CString src = MAKEINTRESOURCE(pResId);
int strLen = 0;
strLen =src.GetLength();
WCHAR* ch = new WCHAR[strLen];
wcscpy(ch, CT2CW(src));
Bitmap* pBitmap = Bitmap::FromResource(hInstResource, ch);
if(!FindResource(hInstResource, src, RT_BITMAP))
{
AfxMessageBox("Fail load pic!", MB_OK, 0);
}graphics.DrawImage(pBitmap, 75,35);
TextureBrush* pTextureBrush = new TextureBrush(pBitmap, WrapModeTileFlipY);
graphics.FillRectangle(pTextureBrush, 50,300,200,80);
Color m_penColor(233,100,54);
Pen pen1(m_penColor, 1);
graphics.DrawRectangle(&pen1, 50,300,200,80);
-
I have already resolved it first: hinstance = AfxGetInstanceHandle(); second: FromResource(hInstResource, (LPCWSTR)MAKEINTRESOURCE(pResId));
how did you do that? please help