-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19__字体.cpp
More file actions
68 lines (58 loc) · 1.91 KB
/
Copy path19__字体.cpp
File metadata and controls
68 lines (58 loc) · 1.91 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
#include <windows.h>
#include "resource.h"
HINSTANCE appInstance;
void OnPaint(HWND hwnd){
PAINTSTRUCT ps={0};
HDC hdc = BeginPaint(hwnd, &ps);// 获取绘图设备句柄
HFONT hFont = CreateFont(100, 0, 0, 0, 900,0, 0, 0, GB2312_CHARSET,0,0,0,0,"黑体");
HGDIOBJ hOldFont= SelectObject(hdc,hFont);
char szText[]="中华人民共和国";
//TextOut(hdc,100,100,szText,strlen(szText));
RECT rect={0,0,600,100};
DrawText(hdc,szText,strlen(szText),&rect, DT_LEFT|DT_TOP);
SelectObject(hdc, hOldFont);
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;
}