-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
153 lines (127 loc) · 4.26 KB
/
main.cpp
File metadata and controls
153 lines (127 loc) · 4.26 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
int windowWidth = 1000;
int windowHeight = 50;
int fontSize = 40;
#include <Windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
int CenterWindowOnScreen_Y(int windowHeight);
int CenterWindowOnScreen_X(int windowWidth);
void DrawLineString(HWND hWnd, TCHAR* string, Color boderColor, Color fillColor, int flag); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
ATOM registeWndClass(HINSTANCE hInstance, LPCWSTR lpClassName, WNDPROC wndProc, DWORD dwColor);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
{
HWND hWnd;
MSG msg;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
registeWndClass(hInstance, TEXT("GettingStarted"), WndProc, WHITE_BRUSH);
hWnd = CreateWindowEx(
WS_EX_LAYERED,
TEXT("GettingStarted"), // window class name
TEXT("Getting Started"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CenterWindowOnScreen_X(windowWidth), // initial x position
CenterWindowOnScreen_Y(windowHeight), // initial y position
windowWidth, // initial x size
windowHeight, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow(hWnd, iCmdShow);
TCHAR string[] = { 0 };
wcscpy(string, L"ÕâÊÇÒ»¸öÖÐÎij¤ÎÄ");
DrawLineString(hWnd, string, Color(255, 0, 255, 0), Color(255, 0, 255, 0),0);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
} // WinMain
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int count = 0;
TCHAR count_str[256];
HDC hdc = GetDC(hWnd);
Graphics g(hdc);
switch (message)
{
case WM_CREATE:
return 0;
case WM_DESTROY:
wsprintf(count_str, L"%d", count);
MessageBox(0, count_str, 0, 0);
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
ATOM registeWndClass(HINSTANCE hInstance, LPCWSTR lpClassName, WNDPROC wndProc, DWORD dwColor)
{
WNDCLASS wnd;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hbrBackground = (HBRUSH)(GetStockObject(dwColor));
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.lpfnWndProc = wndProc;
wnd.lpszClassName = lpClassName;
wnd.lpszMenuName = NULL;
wnd.style = CS_HREDRAW;
wnd.hInstance = hInstance;
return RegisterClass(&wnd);
}
void DrawLineString(HWND hWnd, TCHAR* string, Color boderColor, Color fillColor,int flag)
{
int string_length = lstrlen(string);
int newWindowWidth = ((fontSize + 10) * string_length) * 2;
int newWindowHeight = fontSize + 10;
int x = 0;
int y = 0;
HDC hdc = GetDC(hWnd);
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP bmp = CreateCompatibleBitmap(hdc, newWindowWidth, newWindowHeight);
FontFamily fontFamily(L"ºÚÌå");
RectF rectF(0, 0, newWindowWidth, newWindowHeight);
StringFormat stringFormat;
GraphicsPath strPath;
Pen pen(boderColor, 2);
POINT p2 = { 0,0 };
SIZE size = { newWindowWidth,newWindowHeight };
BLENDFUNCTION _blend;
LinearGradientBrush LGBrush(Point(0, 10), Point(0, 0), fillColor, fillColor);
SelectObject(memDC, bmp);
Graphics g(memDC);
if (flag == 0)
{
stringFormat.SetAlignment(StringAlignmentCenter);
strPath.AddString(string, string_length, &fontFamily, FontStyleBold, fontSize, rectF, &stringFormat);
x = CenterWindowOnScreen_X(newWindowWidth);
y = CenterWindowOnScreen_Y(newWindowHeight);
}
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.DrawPath(&pen, &strPath);
g.FillPath(&LGBrush, &strPath);
_blend.BlendFlags = 0;
_blend.BlendOp = AC_SRC_OVER;
_blend.SourceConstantAlpha = 255;
_blend.AlphaFormat = AC_SRC_ALPHA;
UpdateLayeredWindow(hWnd, hdc, NULL, &size, memDC, &p2, NULL, &_blend, ULW_ALPHA);
SetWindowPos(hWnd, NULL, x, y, newWindowWidth, newWindowHeight, SWP_NOZORDER);
}
int CenterWindowOnScreen_X(int windowWidth)
{
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
return (screenWidth - windowWidth) / 2;
}
int CenterWindowOnScreen_Y(int windowHeight)
{
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
return (screenHeight - windowHeight) / 2;
}