-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18__绘制字符串.cpp
More file actions
66 lines (57 loc) · 1.9 KB
/
Copy path18__绘制字符串.cpp
File metadata and controls
66 lines (57 loc) · 1.9 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
#include <windows.h>
#include "resource.h"
HINSTANCE appInstance;
void OnPaint(HWND hwnd){
PAINTSTRUCT ps={0};
HDC hdc = BeginPaint(hwnd, &ps);// 获取绘图设备句柄
SetTextColor(hdc, RGB(255,0,0));// 字符颜色
SetBkColor(hdc,RGB(200,200,0)); // 背景色
SetBkMode(hdc, OPAQUE);//背景:OPAQUE(不透明)/TRANSPARENT(透明)
//TextOutW(hdc,100,100,L"中国",wcslen(L"中国"));
RECT rect={100,100,300,200};
DrawText(hdc,"中华人民共和国",strlen("中华人民共和国"),&rect, DT_LEFT|DT_TOP);
EndPaint(hwnd,&ps); //结束绘图,释放句柄
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch (Message) {
case WM_PAINT:
OnPaint(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
break;
}
return 0;
}
/* Win32 GUI程序的“main”函数:程序从这里开始执行 */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
appInstance = hInstance;
WNDCLASSEX wc; HWND hwnd; MSG msg;
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszClassName = "WindowClass";
if (!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!",
"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "WindowClass", "Caption",
WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
640, 480, NULL, NULL, hInstance, NULL);
if (hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}