--- /dev/null
+//////////////////////////////////////////////\r
+// GDIPlusView.cpp\r
+// Definitions for the CGDIPlusView class\r
+\r
+#include "stdafx.h"\r
+#include "GDIPlusView.h"\r
+using namespace Gdiplus;\r
+\r
+CGDIPlusView::CGDIPlusView()\r
+{\r
+ // Initialize GDI+.\r
+ GdiplusStartupInput gdiplusStartupInput;\r
+ GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);\r
+}\r
+\r
+CGDIPlusView::~CGDIPlusView()\r
+{\r
+ // Shutdown GDI+\r
+ GdiplusShutdown(m_gdiplusToken);\r
+}\r
+\r
+void CGDIPlusView::DrawCappedLine(CDC* pDC) \r
+{\r
+ Graphics graphics(*pDC);\r
+ // Draw capped line, width 8\r
+ Pen penCapped(Color(255, 0, 0, 255), 8);\r
+ Status stat = penCapped.SetStartCap(LineCapArrowAnchor);\r
+ stat = penCapped.SetEndCap(LineCapRoundAnchor);\r
+ stat = graphics.DrawLine(&penCapped, 10, 175, 300, 175);\r
+}\r
+\r
+void CGDIPlusView::DrawGamaShapes(CDC* pDC)\r
+{\r
+ Graphics graphics(*pDC);\r
+\r
+ // Draw Plygons with Gama Corrections\r
+ // Put the points of a polygon in an array.\r
+ GraphicsPath pathGama;\r
+ int yOffset = 200;\r
+ Point points[] = {Point(75, 0 +yOffset), Point(100, 50+yOffset), \r
+ Point(150, 50 +yOffset), Point(112, 75+yOffset),\r
+ Point(150, 150+yOffset), Point(75, 100+yOffset), \r
+ Point(0, 150+yOffset), Point(37, 75+yOffset), \r
+ Point(0, 50 +yOffset), Point(50, 50+yOffset)};\r
+\r
+ // Use the array of points to construct a path.\r
+ pathGama.AddLines(points, 10);\r
+\r
+ // Use the path to construct a path gradient brush.\r
+ PathGradientBrush pthGrBrushGama(&pathGama);\r
+\r
+ // Set the color at the center of the path to red.\r
+ pthGrBrushGama.SetCenterColor(Color(255, 255, 0, 0));\r
+\r
+ // Set the colors of the points in the array.\r
+ Color colorsGama[] = {Color(255, 0, 0, 0), Color(255, 0, 255, 0),\r
+ Color(255, 0, 0, 255), Color(255, 255, 255, 255), \r
+ Color(255, 0, 0, 0), Color(255, 0, 255, 0), \r
+ Color(255, 0, 0, 255), Color(255, 255, 255, 255),\r
+ Color(255, 0, 0, 0), Color(255, 0, 255, 0)};\r
+\r
+ int count = 10;\r
+ pthGrBrushGama.SetSurroundColors(colorsGama, &count);\r
+\r
+ // Fill the path with the path gradient brush.\r
+ graphics.FillPath(&pthGrBrushGama, &pathGama);\r
+ pthGrBrushGama.SetGammaCorrection(TRUE);\r
+ graphics.TranslateTransform(200.0f, 0.0f);\r
+ graphics.FillPath(&pthGrBrushGama, &pathGama);\r
+}\r
+\r
+void CGDIPlusView::DrawGradientElipse(CDC* pDC)\r
+{\r
+ Graphics graphics(*pDC);\r
+\r
+ // Create a path that consists of a single ellipse.\r
+ GraphicsPath path;\r
+ path.AddEllipse(0, 80, 140, 70);\r
+\r
+ // Use the path to construct a brush.\r
+ PathGradientBrush pthGrBrush(&path);\r
+\r
+ // Set the color at the center of the path to blue.\r
+ pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));\r
+\r
+ // Set the color along the entire boundary of the path to aqua.\r
+ Color colors[] = {Color(255, 0, 255, 255)};\r
+ int count = 1;\r
+ pthGrBrush.SetSurroundColors(colors, &count);\r
+\r
+ graphics.FillEllipse(&pthGrBrush, 0, 80, 140, 70);\r
+}\r
+\r
+void CGDIPlusView::DrawSolidElipse(CDC* pDC)\r
+{\r
+ Graphics graphics(*pDC);\r
+\r
+ SolidBrush solidBrush(Color(255, 255, 0, 0));\r
+ graphics.FillEllipse(&solidBrush, 160, 84, 100, 60);\r
+}\r
+\r
+void CGDIPlusView::DrawSolidLine(CDC* pDC) \r
+{\r
+ Graphics graphics(*pDC);\r
+ \r
+ // Draw solid line\r
+ Pen penLine(Color(255, 0, 0, 255));\r
+ graphics.DrawLine(&penLine, 10, 70, 200, 70);\r
+}\r
+\r
+void CGDIPlusView::DrawText(CDC* pDC) \r
+{\r
+ Graphics graphics(*pDC);\r
+\r
+ // Draw some text\r
+ SolidBrush brush(Color(255, 0, 0, 255));\r
+ FontFamily fontFamily(L"Times New Roman");\r
+ Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);\r
+ PointF pointF(10.0f, 20.0f);\r
+ \r
+ graphics.DrawString(L"GDI+ Example", -1, &font, pointF, &brush);\r
+}\r
+\r
+void CGDIPlusView::OnDraw(CDC* pDC)\r
+{\r
+ DrawSolidLine(pDC);\r
+ DrawText(pDC);\r
+ DrawCappedLine(pDC);\r
+ DrawGradientElipse(pDC);\r
+ DrawSolidElipse(pDC);\r
+ DrawGamaShapes(pDC); \r
+}\r
+\r
+void CGDIPlusView::OnInitialUpdate()\r
+{\r
+ // OnInitialUpdate is called immediately after the window is created\r
+ TRACE(_T("View window created\n"));\r
+}\r
+\r
+void CGDIPlusView::PreCreate(CREATESTRUCT &cs)\r
+{\r
+ // Here we set the defaults used by the create function for the view window\r
+ // Preforming this is optional, but doing so allows us to\r
+ // take more precise control over the window we create.\r
+\r
+ // Set the extended style\r
+ cs.dwExStyle = WS_EX_CLIENTEDGE;\r
+}\r
+\r
+void CGDIPlusView::RegisterClass(WNDCLASS &wc)\r
+{\r
+ // Here we set the Window class parameters.\r
+ // Preforming this is optional, but doing so allows us to\r
+ // take more precise control over the type of window we create.\r
+\r
+ // Set the Window Class name\r
+ wc.lpszClassName = _T("View");\r
+\r
+ // Set the class style (not to be confused with the window styles set in PreCreate)\r
+ wc.style = CS_DBLCLKS; // Generate left button double click messages\r
+}\r
+\r
+LRESULT CGDIPlusView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+// switch (uMsg)\r
+// {\r
+\r
+// }\r
+\r
+ // pass unhandled messages on for default processing\r
+ return WndProcDefault(uMsg, wParam, lParam);\r
+}\r
+\r