如何在C++中實現MFC應用程序中的2D圖形?如果有任何類或庫,請給我參考MSDN中適當的文章。我可以在MFC應用程序中使用Visual C++中的GDI +嗎?我可以在MFC應用程序中使用Visual C++中的Direct2D嗎?我在MS VS 2013 Ultimate工作。任何幫助將非常感激。如何在Visual C++中的MFC應用程序中實現2D圖形?
-1
A
回答
1
是,的Direct2D通過MFC框架,CHwndRenderTarget
類原生支持:
下面是關於如何使用它的一個例子:
class CDemoView : public CScrollView
{
CHwndRenderTarget m_renderTarget;
std::shared_ptr<CD2DBitmap> m_spBitmap;
// ...
};
int CDemoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
HRESULT hr = m_renderTarget.Create(m_hWnd);
return SUCCEEDED(hr) ? 0 : -1;
}
void CDemoView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
if(m_renderTarget.IsValid())
{
m_renderTarget.Resize(CD2DSizeU(cx, cy));
}
}
void CDemoView::OnDraw(CDC* pDC)
{
if(m_renderTarget.IsValid())
{
// initiate drawing on render target
m_renderTarget.BeginDraw();
// clear background using white color
D2D1_COLOR_F color = {1.f, 1.f, 1.f, 1.f}; // r, g, b, a
m_renderTarget.Clear(color);
if((nullptr != m_spBitmap) && m_spBitmap->IsValid())
{
// apply translation transform according to view's scroll position
CPoint point = GetScrollPosition();
D2D1_MATRIX_3X2_F matrix = D2D1::Matrix3x2F::Translation((float)-point.x, (float)-point.y);
m_renderTarget.SetTransform(matrix);
// draw the bitmap
CD2DSizeF size = m_spBitmap->GetSize();
m_renderTarget.DrawBitmap(m_spBitmap.get(), CD2DRectF(0, 0, size.width, size.height));
}
// ends drawing operations
HRESULT hr = m_renderTarget.EndDraw();
// if the render target has been lost, then recreate it
if(D2DERR_RECREATE_TARGET == hr)
{
m_renderTarget.ReCreate(m_hWnd);
}
}
}
的GDI +也支持:
// init GDI+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
這是與GDI設備上下文中使用它的方式:
CPaintDC dc(this);
Graphics graphics(dc.hdc);
Pen MyPen(Color(255, 0, 255,)); // A green pen, with full alpha
graphics.DrawLine(&pen, 0, 0, 200, 100);
0
除了什麼安德魯已經建議:
MFC更是把內置支持的Direct2D庫(也爲相關DirectWrite的 )。
呼叫的CWnd :: EnableD2DSupport,例如在WM_CREATE消息處理程序,那不更需要創造渲染目標自己,調整其大小,調用
- BeginDraw
- EndDraw
如果渲染目標已丟失,則重新創建渲染目標等。
查看此文章的詳細信息:MFC Support for Direct2D – Part 2
相關問題
- 1. 如何在android中實現2D圖形?
- 2. C++ MFC如何在C++ MFC應用程序中繪製Alpha透明矩形
- 3. 在C中的2D圖形的地鐵應用程序#
- 4. 在C++ MFC應用程序中繪製圖形
- 5. 使用tinyxml2與Visual Studio中的Visual C++ MFC應用程序
- 6. MFC應用程序中的C#控件
- 7. C++ Visual Studio 6 MFC應用程序
- 8. 如何在C#應用程序中實現谷歌地圖API?
- 9. Qt - C++在visual studio中的圖形應用程序
- 10. 如何保存到MFC C++應用程序中的位圖?
- 11. C應用程序的實時圖形
- 12. 在visual C++窗體應用程序中實現bonjour sdk
- 13. 如何在Windows上使用Visual Studio和MFC C++實現預覽
- 14. MFC/C++應用程序中的Rich gui
- 15. C++中的圖形實現
- 16. MFC應用程序中的XY位圖
- 17. 如何啓動C++ mfc應用程序
- 18. 如何在java小應用程序中創建圖形實例
- 19. MFC應用程序不Visual Studio的
- 20. 如何在Java/C應用程序中實現鎖定
- 21. 如何在C#桌面應用程序中實現Push方法?
- 22. 如何在C#asp.net中實現推拉式Web應用程序
- 23. iPhone應用程序中的2D圖形元素編輯器
- 24. 在C++/MFC和C#中使用插件擴展C++/MFC應用程序
- 25. 如何填充MFC C++應用程序中的Windows菜單
- 26. 如何測量C++(MFC)應用程序中的性能?
- 27. 如何在MFC VC++ Visual Studio 2008中繪製圖形控件?
- 28. 如何在iOS應用程序中實現圖表?
- 29. 如何在Mac OS X應用程序中實現UITabBar視圖?
- 30. 如何在N層圖層應用程序中實現IDependencyResolver?