简体   繁体   中英

How to draw/create GDI+ on MFC Dialog

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM