📄 demo3_1.c
字号:
1 /****************************************************************/
2 /* Demo3_1 --- Mapping Mode */
3 /****************************************************************/
4
5 #include <windows.h>
6 #include "demo3_1.h"
7
8 int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
9 long FAR PASCAL MainWndProc(HWND, unsigned, WORD, LONG);
10
11 void ShowMapModeDemo(HWND, HDC, int);
12
13
14 /****************************************************************/
15 /* WinMain() */
16 /****************************************************************/
17
18 int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
19 LPSTR lpszCmdLine, int nCmdShow)
20 {
21 WNDCLASS wclass;
22 MSG msg;
23 HWND hWnd;
24 char szName[] = "Demo3_1";
25
26 if (!hPrevInstance)
27 {
28 wclass.style = CS_HREDRAW | CS_VREDRAW;
29 wclass.lpfnWndProc = MainWndProc;
30 wclass.cbClsExtra = 0;
31 wclass.cbWndExtra = 0;
32 wclass.hInstance = hInstance;
33 wclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
34 wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
35 wclass.hbrBackground = GetStockObject(WHITE_BRUSH);
36 wclass.lpszMenuName = szName;
37 wclass.lpszClassName = szName;
38
39 if (!RegisterClass (&wclass))
40 return (FALSE);
41 }
42
43 hWnd = CreateWindow(
44 szName,
45 "Mapping Mode",
46 WS_OVERLAPPEDWINDOW,
47 CW_USEDEFAULT,
48 CW_USEDEFAULT,
49 CW_USEDEFAULT,
50 CW_USEDEFAULT,
51 NULL,
52 NULL,
53 hInstance,
54 NULL );
55
56 if (!hWnd)
57 return (FALSE);
58
59 ShowWindow(hWnd, nCmdShow);
60 UpdateWindow(hWnd);
61
62 while (GetMessage(&msg, NULL, NULL,NULL))
63 {
64 TranslateMessage(&msg);
65 DispatchMessage(&msg);
66 }
67 return (msg.wParam);
68 }
69
70
71
72 /****************************************************************/
73 /* MainWndProc() */
74 /****************************************************************/
75
76 long FAR PASCAL MainWndProc(HWND hWnd, unsigned message,
77 WORD wParam, LONG lParam)
78 {
79 PAINTSTRUCT ps;
80 HDC hDC;
81 HMENU hMenu;
82 static int MapModeID = IDM_TEXT;
83
84 switch (message)
85 {
86 case WM_COMMAND :
87 switch(wParam)
88 {
89 case IDM_TEXT :
90 case IDM_LOMET :
91 case IDM_HIMET :
92 case IDM_LOENG :
93 case IDM_HIENG :
94 case IDM_TWIPS :
95
96 if (MapModeID != wParam)
97 {
98 hMenu = GetMenu(hWnd);
99 CheckMenuItem(hMenu, MapModeID,
100 MF_UNCHECKED);
101 MapModeID = wParam;
102 CheckMenuItem(hMenu, wParam,
103 MF_CHECKED);
104 InvalidateRect(hWnd, NULL, TRUE);
105 }
106 break;
107 }
108 return (0);
109
110 case WM_PAINT :
111 hDC = BeginPaint(hWnd, &ps);
112
113 ShowMapModeDemo(hWnd, hDC, MapModeID);
114
115 EndPaint(hWnd, &ps);
116 break;
117
118
119 case WM_DESTROY :
120 PostQuitMessage(0);
121 break ;
122
123 default :
124 return (DefWindowProc(hWnd, message, wParam, lParam));
125 }
126 return (NULL);
127 }
128
129
130 void ShowMapModeDemo(HWND hWnd, HDC hDC, int MapModeID)
131 {
132 POINT Screen;
133 RECT ClientRect;
134 TEXTMETRIC tm;
135 int CharY;
136 char szString1[50], szString2[50];
137 char szString3[50], szString4[50];
138
139 switch (MapModeID)
140 {
141 case IDM_TEXT :
142 SetMapMode(hDC, MM_TEXT);
143 break;
144
145 case IDM_LOMET :
146 SetMapMode(hDC, MM_LOMETRIC);
147 break;
148
149 case IDM_HIMET :
150 SetMapMode(hDC, MM_HIMETRIC);
151 break;
152
153 case IDM_LOENG :
154 SetMapMode(hDC, MM_LOENGLISH);
155 break;
156
157 case IDM_HIENG :
158 SetMapMode(hDC, MM_HIENGLISH);
159 break;
160
161 case IDM_TWIPS :
162 SetMapMode(hDC, MM_TWIPS);
163 break;
164 }
165
166 Screen.x = GetSystemMetrics(SM_CXSCREEN);
167 Screen.y = GetSystemMetrics(SM_CYSCREEN);
168 DPtoLP(hDC, &Screen, 1);
169 Screen.x = abs(Screen.x);
170 Screen.y = abs(Screen.y);
171
172 GetClientRect(hWnd, &ClientRect);
173 DPtoLP(hDC, (LPPOINT) &ClientRect, 2);
174
175 SaveDC(hDC);
176
177 SetMapMode(hDC, MM_TEXT);
178 SelectObject(hDC, GetStockObject(SYSTEM_FIXED_FONT));
179
180 GetTextMetrics(hDC, &tm);
181 CharY = tm.tmHeight + tm.tmExternalLeading;
182
183 sprintf(szString1, "Screen Width : %d", Screen.x);
184 sprintf(szString2, "Screen Height : %d", Screen.y);
185 sprintf(szString3, " Left-Top Point : (%d , %d)",
186 ClientRect.left, ClientRect.top);
187 sprintf(szString4, "Right-Bottom Point : (%d , %d)",
188 ClientRect.right, ClientRect.bottom);
189
190 TextOut(hDC, 10, 10, szString1, strlen(szString1));
191 TextOut(hDC, 10, 10+CharY, szString2, strlen(szString2));
192 TextOut(hDC, 10, 10+CharY*3, szString3, strlen(szString3));
193 TextOut(hDC, 10, 10+CharY*4, szString4, strlen(szString4));
194
195 RestoreDC(hDC, -1);
196
197 SelectObject(hDC, GetStockObject(NULL_BRUSH));
198 if (MapModeID == IDM_TEXT)
199 Ellipse(hDC, 100, 100, 600, 400);
200 else
201 Ellipse(hDC, 100, -100, 600, -400);
202 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -