2
votes

I have a MFC Application with Dialog Based. I created a GDI+ Object from resource by using this.

MyDlg.cpp:

BOOL CSetupDlg::OnInitDialog()
{
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        ...
}

void MyFunction():

CGdiPlusBitmapResource* pBitmap = new CGdiPlusBitmapResource;
if (pBitmap->Load(ID_SPL_LG))
{
    CPaintDC dc(this);
    Gdiplus::Graphics graphics(dc);
    graphics.DrawImage(*pBitmap, 0, 0);
    //It is loaded . I checked with messagebox and its in here.
}
Invalidate(); //Not sure if necessary.

Now, Form/Dialog shows nothing. No image inserted nor attached.

Now, i tried few things to add this image to the dialog but i am unable to do it.

What i tried is GDIObject.Create(), CStatic.Create() and PictureControl.Create()

All i want to do is insert this image to the dialog.

Any idea or showing path is appreciated.

1
You should only create a CPaintDC in response to a WM_PAINT message, otherwise it won't work.Mark Ransom

1 Answers

5
votes

You will need to override the OnPaint method that responds to the WM_PAINT message in your dialog. Normally you don't need to do this because the dialog doesn't need to paint anything, it just lets the controls that are contained on it paint themselves.

Move the code you show into the OnPaint handler.

Do not call the default OnPaint from your own handler.

Do not call Invalidate from within the OnPaint handler or you will get an infinite loop.