-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.cpp
138 lines (112 loc) · 3.2 KB
/
hello.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <windows.h>
#include <tchar.h>
#include <gdiplus.h>
using namespace Gdiplus;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void OnPaint(HDC hdc);
void DrawTriangle(HDC hdc);
GdiplusStartupInput gdiSI;
ULONG_PTR gdiToken;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wcex;
HWND hwnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
GdiplusStartup(&gdiToken, &gdiSI, NULL);
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_OWNDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = _T("WindowClass");
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
return 0;
hwnd = CreateWindowEx(0,
_T("WindowClass"),
_T("Hello, World!"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
while (!bQuit)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
DestroyWindow(hwnd);
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hdc);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
void OnPaint(HDC hdc)
{
DrawTriangle(hdc);
}
void DrawTriangle(HDC hdc)
{
int WIDTH = 640;
int HEIGHT = 480;
Graphics graphics(hdc);
Point points[] = {
Point(WIDTH * 1 / 2, HEIGHT * 1 / 4),
Point(WIDTH * 3 / 4, HEIGHT * 3 / 4),
Point(WIDTH * 1 / 4, HEIGHT * 3 / 4)
};
GraphicsPath path;
path.AddLines(points, 3);
PathGradientBrush pthGrBrush(&path);
Color centercolor = Color(255, 255/3, 255/3, 255/3);
pthGrBrush.SetCenterColor(centercolor);
Color colors[] = {
Color(255, 255, 0, 0), // red
Color(255, 0, 255, 0), // green
Color(255, 0, 0, 255) // blue
};
int count = 3;
pthGrBrush.SetSurroundColors(colors, &count);
graphics.FillPath(&pthGrBrush, &path);
}