I need to draw an image each on two dialogue boxes of my application. I chose to use a memory dc. Unfortunately, instead of drawing the image, it drew a black box. What could be wrong? The relevant codes are shown below.
static HDC hmemDC = nullptr;
static HBITMAP hbitmap = nullptr;
static HBITMAP hOldbitmap = nullptr;
case WM_INITDIALOG:
HDC hdc = GetDC(hDlg);
hmemDC = CreateCompatibleDC(hdc);
hbitmap = CreateCompatibleBitmap(hmemDC,iPicWidth,iPicHeight);
hOldbitmap = (HBITMAP)SelectObject(hmemDC, hbitmap);
ReleaseDC(hDlg, hdc);
std::string stPicPath;
if (UpdateStudentInfoControls(hDlg, llSessionID, llArmID, eUseMode, stPicPath))
{
DrawAppImage(hmemDC, iPicLeft,iPicTop,iPicWidth, iPicHeight, stPicPath);
}
else
{
HPEN hPen = (HPEN)GetStockObject(BLACK_PEN);
HPEN hOldPen = (HPEN)SelectObject(hmemDC, hPen);
MoveToEx(hmemDC, 0, 0, NULL);
LineTo(hmemDC,iPicWidth, 0);
LineTo(hmemDC, iPicWidth,iPicHeight);
LineTo(hmemDC,0,iPicHeight);
LineTo(hmemDC,0,0);
SelectObject(hmemDC, hOldPen);
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hDlg, &ps);
BitBlt(hdc, iPicLeft, iPicTop, iPicWidth, iPicHeight, hmemDC, 0, 0, SRCCOPY);
EndPaint(hDlg, &ps);
}
return (INT_PTR)TRUE;
<
void DrawAppImage(HDC hdc, int iLeft, int iTop, int iWidth, int iHeight, string stImagePath)
{
string stImageFullPath = stDBImageDirectory;
stImageFullPath += '\\';
stImageFullPath += stImagePath;
wstring wstImagePath = utf8_decode(stImageFullPath);
Gdiplus::Image image(wstImagePath.c_str());
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(&image, iLeft, iTop, iWidth, iHeight);
}
/pre>
What I have tried:
I have spent sustantial time debugging the code.