1 //////////////////////////////////////////////
\r
3 // Definitions for the CGDIPlusView class
\r
6 #include "GDIPlusView.h"
\r
7 using namespace Gdiplus;
\r
9 CGDIPlusView::CGDIPlusView()
\r
12 GdiplusStartupInput gdiplusStartupInput;
\r
13 GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
\r
16 CGDIPlusView::~CGDIPlusView()
\r
19 GdiplusShutdown(m_gdiplusToken);
\r
22 void CGDIPlusView::DrawCappedLine(CDC* pDC)
\r
24 Graphics graphics(*pDC);
\r
25 // Draw capped line, width 8
\r
26 Pen penCapped(Color(255, 0, 0, 255), 8);
\r
27 Status stat = penCapped.SetStartCap(LineCapArrowAnchor);
\r
28 stat = penCapped.SetEndCap(LineCapRoundAnchor);
\r
29 stat = graphics.DrawLine(&penCapped, 10, 175, 300, 175);
\r
32 void CGDIPlusView::DrawGamaShapes(CDC* pDC)
\r
34 Graphics graphics(*pDC);
\r
36 // Draw Plygons with Gama Corrections
\r
37 // Put the points of a polygon in an array.
\r
38 GraphicsPath pathGama;
\r
40 Point points[] = {Point(75, 0 +yOffset), Point(100, 50+yOffset),
\r
41 Point(150, 50 +yOffset), Point(112, 75+yOffset),
\r
42 Point(150, 150+yOffset), Point(75, 100+yOffset),
\r
43 Point(0, 150+yOffset), Point(37, 75+yOffset),
\r
44 Point(0, 50 +yOffset), Point(50, 50+yOffset)};
\r
46 // Use the array of points to construct a path.
\r
47 pathGama.AddLines(points, 10);
\r
49 // Use the path to construct a path gradient brush.
\r
50 PathGradientBrush pthGrBrushGama(&pathGama);
\r
52 // Set the color at the center of the path to red.
\r
53 pthGrBrushGama.SetCenterColor(Color(255, 255, 0, 0));
\r
55 // Set the colors of the points in the array.
\r
56 Color colorsGama[] = {Color(255, 0, 0, 0), Color(255, 0, 255, 0),
\r
57 Color(255, 0, 0, 255), Color(255, 255, 255, 255),
\r
58 Color(255, 0, 0, 0), Color(255, 0, 255, 0),
\r
59 Color(255, 0, 0, 255), Color(255, 255, 255, 255),
\r
60 Color(255, 0, 0, 0), Color(255, 0, 255, 0)};
\r
63 pthGrBrushGama.SetSurroundColors(colorsGama, &count);
\r
65 // Fill the path with the path gradient brush.
\r
66 graphics.FillPath(&pthGrBrushGama, &pathGama);
\r
67 pthGrBrushGama.SetGammaCorrection(TRUE);
\r
68 graphics.TranslateTransform(200.0f, 0.0f);
\r
69 graphics.FillPath(&pthGrBrushGama, &pathGama);
\r
72 void CGDIPlusView::DrawGradientElipse(CDC* pDC)
\r
74 Graphics graphics(*pDC);
\r
76 // Create a path that consists of a single ellipse.
\r
78 path.AddEllipse(0, 80, 140, 70);
\r
80 // Use the path to construct a brush.
\r
81 PathGradientBrush pthGrBrush(&path);
\r
83 // Set the color at the center of the path to blue.
\r
84 pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));
\r
86 // Set the color along the entire boundary of the path to aqua.
\r
87 Color colors[] = {Color(255, 0, 255, 255)};
\r
89 pthGrBrush.SetSurroundColors(colors, &count);
\r
91 graphics.FillEllipse(&pthGrBrush, 0, 80, 140, 70);
\r
94 void CGDIPlusView::DrawSolidElipse(CDC* pDC)
\r
96 Graphics graphics(*pDC);
\r
98 SolidBrush solidBrush(Color(255, 255, 0, 0));
\r
99 graphics.FillEllipse(&solidBrush, 160, 84, 100, 60);
\r
102 void CGDIPlusView::DrawSolidLine(CDC* pDC)
\r
104 Graphics graphics(*pDC);
\r
107 Pen penLine(Color(255, 0, 0, 255));
\r
108 graphics.DrawLine(&penLine, 10, 70, 200, 70);
\r
111 void CGDIPlusView::DrawText(CDC* pDC)
\r
113 Graphics graphics(*pDC);
\r
116 SolidBrush brush(Color(255, 0, 0, 255));
\r
117 FontFamily fontFamily(L"Times New Roman");
\r
118 Font font(&fontFamily, 24, FontStyleRegular, UnitPixel);
\r
119 PointF pointF(10.0f, 20.0f);
\r
121 graphics.DrawString(L"GDI+ Example", -1, &font, pointF, &brush);
\r
124 void CGDIPlusView::OnDraw(CDC* pDC)
\r
126 DrawSolidLine(pDC);
\r
128 DrawCappedLine(pDC);
\r
129 DrawGradientElipse(pDC);
\r
130 DrawSolidElipse(pDC);
\r
131 DrawGamaShapes(pDC);
\r
134 void CGDIPlusView::OnInitialUpdate()
\r
136 // OnInitialUpdate is called immediately after the window is created
\r
137 TRACE(_T("View window created\n"));
\r
140 void CGDIPlusView::PreCreate(CREATESTRUCT &cs)
\r
142 // Here we set the defaults used by the create function for the view window
\r
143 // Preforming this is optional, but doing so allows us to
\r
144 // take more precise control over the window we create.
\r
146 // Set the extended style
\r
147 cs.dwExStyle = WS_EX_CLIENTEDGE;
\r
150 void CGDIPlusView::RegisterClass(WNDCLASS &wc)
\r
152 // Here we set the Window class parameters.
\r
153 // Preforming this is optional, but doing so allows us to
\r
154 // take more precise control over the type of window we create.
\r
156 // Set the Window Class name
\r
157 wc.lpszClassName = _T("View");
\r
159 // Set the class style (not to be confused with the window styles set in PreCreate)
\r
160 wc.style = CS_DBLCLKS; // Generate left button double click messages
\r
163 LRESULT CGDIPlusView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
170 // pass unhandled messages on for default processing
\r
171 return WndProcDefault(uMsg, wParam, lParam);
\r