简体   繁体   English

如何在MFC对话框上绘制/创建GDI +

[英]How to draw/create GDI+ on MFC Dialog

I have a MFC Application with Dialog Based. 我有一个基于对话框的MFC应用程序。 I created a GDI+ Object from resource by using this . 我使用this从资源创建了一个GDI +对象。

MyDlg.cpp: MyDlg.cpp:

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

void MyFunction(): 无效的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() 我试过的是GDIObject.Create()CStatic.Create()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. 您将需要重写响应对话框中WM_PAINT消息的OnPaint方法。 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. 将您显示的代码移到OnPaint处理程序中。

Do not call the default OnPaint from your own handler. 不要从自己的处理程序调用默认的OnPaint。

Do not call Invalidate from within the OnPaint handler or you will get an infinite loop. 不要调用Invalidate从OnPaint处理中,否则你会得到一个无限循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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