添加了一个菜单项,“显示”可以工作,是在C……View类中添加的消息响应
菜单项的消息响应函数是:
void C……View()
{
Graphics graphics(m_hWnd);
Bitmap bg(L"gril1.jpg");
int bgWidth = bg.GetWidth();
int bgHeight = bg.GetHeight();
graphics.DrawImage(&bg, 10, 10, 1000, 1000);
}图片bitmapVCGdiplus
菜单项的消息响应函数是:
void C……View()
{
Graphics graphics(m_hWnd);
Bitmap bg(L"gril1.jpg");
int bgWidth = bg.GetWidth();
int bgHeight = bg.GetHeight();
graphics.DrawImage(&bg, 10, 10, 1000, 1000);
}图片bitmapVCGdiplus
Graphics graphicsCDC(pDC->m_hDC);我跟你的Graphics graphics(m_hWnd); 不一样我的是用CDC的
找个地方(程序开始)加上
UINT_PTR uiToken = 0;
GdiplusStartupInput input;
GdiplusStartup(&m_uiToken, &input, nullptr);
再找个地方(程序结束)加上
GdiplusShutdown(uiToken);
也不用过多地去追究初始化的原因,SDK里已经说明得很清楚了,在调用任何的GDI+API的时候如果还没有初始化GDI+,那么所有调用将会失败,但不会抛出异常,返回Status的函数都会返回GdiplusNotInitialized,内部有m_status的类(Brush、Pen、Image等)m_status也都会是GdiplusNotInitialized,告诉你还没有初始化GDI+。
很抱歉,我也没有更多的学习资料,多用用就熟练了。
//加载
if (!bkImg.IsNull())
{
bkImg.Destroy();
}
CString FilePath = FileDialog.GetPathName();
bkImg.Load(LPCSTR(FilePath));
this->Invalidate(FALSE);//画图
if (!bkImg.IsNull())
{
bkImg.Draw(pDC->GetSafeHdc(),0,0);
}