|
|
1.1 root 1: /**************************************************************************\
2: * ntfonts.c -- Font enumeration and manipulation program for Win32/NT.
3: *
4: * version 1.0
5: *
6: * design: There is a main frame window (hwndMain) with a child toolbar,
7: * two child dialogs, and a child demonstration window. All window handles
8: * are global and are accesible to all modules. There is a module for each
9: * of the classes of windows. Each module contains an initialization routine
10: * to register the class and create the window(s). Each module also contains
11: * a window procedure for that class. The two windows which list all of the
12: * fonts are also children of the main window, and they are hidden and shown
13: * as needed.
14: *
15: * Communication between windows is via message passing. The toolbar passes
16: * all of its command messages back to the main window. Other windows pass
17: * information back and forth with the following USER defined messages:
18: * WMU_LFTODEMO, WMU_DEMOTOLF, & WMU_DEMOTOTM. Rectangles fly on the screen
19: * (c.f. flyWinWin) to mirror message trafic, i.e. data flow.
20: *
21: \**************************************************************************/
22:
23: #include <windows.h>
24: #include "ntfonts.h"
25:
26:
27: /* Misc. defines for size, color, and appearance of drawing. */
28: #define GRIDCOLOR PALETTEINDEX (6)
29: #define TICKSPACE 20
30: #define FWW_STEPS 40
31:
32:
33:
34: char initString[] = "Please wait. Initializing data structures.";
35:
36:
37: /**************************************************************************\
38: *
39: * function: WinMain()
40: *
41: * input parameters: c.f. generic sample
42: *
43: \**************************************************************************/
44: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
45: LPSTR lpCmdLine, int nCmdShow)
46: {
47: MSG msg;
48: HANDLE haccel;
49: HWND hwndInfo;
50:
51:
52: UNREFERENCED_PARAMETER( lpCmdLine );
53: UNREFERENCED_PARAMETER( nCmdShow );
54: hInst = hInstance;
55:
56:
57: /* Check for previous instance. If none, then register class. */
58: if (!hPrevInstance) {
59: WNDCLASS wc;
60:
61: wc.style = NULL;
62: wc.lpfnWndProc = (WNDPROC)MainWndProc;
63:
64: wc.cbClsExtra = 0;
65: wc.cbWndExtra = 0;
66: wc.hInstance = hInstance;
67: wc.hIcon = LoadIcon(hInstance, "ntfontsIcon");
68: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
69: wc.hbrBackground = NULL;
70: wc.lpszMenuName = NULL;
71: wc.lpszClassName = "ntfonts";
72:
73: if (!RegisterClass(&wc)) return (FALSE);
74:
75: } /* class registered o.k. */
76:
77:
78: /* Create the main window. Return false if CreateWindow() fails */
79: hwndMain = CreateWindow(
80: "ntfonts",
81: "NT Fonts",
82: WS_OVERLAPPEDWINDOW,
83: CW_USEDEFAULT,
84: CW_USEDEFAULT,
85: CW_USEDEFAULT,
86: CW_USEDEFAULT,
87: NULL, NULL, hInst, NULL);
88:
89: if (!hwndMain) return (FALSE);
90:
91:
92: /* create temporary window to display while initialization completes */
93: hwndInfo = CreateWindow(
94: "EDIT",
95: initString,
96: WS_CHILD | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_CENTER,
97: 0,0,
98: GetSystemMetrics (SM_CXFULLSCREEN),
99: GetSystemMetrics (SM_CYFULLSCREEN),
100: hwndMain, NULL, hInst, NULL);
101:
102: /* make the main window visible to show the "please wait..." screen. */
103: ShowWindow(hwndMain, SW_SHOWMAXIMIZED);
104: UpdateWindow (hwndMain);
105:
106:
107: /* perform initialization for other windows...allfont is SLOW */
108: if (!initTB(hwndMain)) return FALSE;
109: if (!initDemo(hwndMain)) return FALSE;
110: if (!initDlg(hwndMain)) return FALSE;
111: if (!initAllFont(hwndMain)) return FALSE;
112:
113:
114: haccel = LoadAccelerators (hInst, "TBAccel");
115:
116:
117: /* get rid of the temporary "please wait..." window. */
118: DestroyWindow (hwndInfo);
119:
120: /* Loop getting messages and dispatching them. */
121: while (GetMessage(&msg,NULL, NULL, NULL)) {
122: if (!TranslateAccelerator(hwndMain, haccel, &msg))
123: if (!IsDialogMessage (hwndDlgTM, &msg))
124: if (!IsDialogMessage (hwndDlgLF, &msg)){
125: TranslateMessage(&msg);
126: DispatchMessage(&msg);
127: }
128: }
129:
130: return (msg.wParam);
131: }
132:
133:
134:
135: /**************************************************************************\
136: *
137: * function: MainWndProc()
138: *
139: * input parameters: normal window procedure parameters.
140: *
141: \**************************************************************************/
142: LRESULT MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
143: {
144: static HANDLE hPenGrid;
145: static LOGFONT lf;
146: static TEXTMETRIC tm;
147:
148: switch (message) {
149:
150:
151: /**********************************************************************\
152: * WM_COMMAND
153: *
154: * The WM_COMMAND messages here are passed up from the toolbar.
155: * Take whatever action is necesarry for the various buttons.
156: * (Either showing/hiding enumeration windows, or moving information
157: * in structures between different windows.)
158: \**********************************************************************/
159: case WM_COMMAND: {
160:
161: switch (LOWORD(wParam)) {
162: HWND hwndButton;
163:
164: case TBID_ENUM:
165: SetWindowPos (hwndDisplayFonts, NULL, 0,0,0,0,
166: SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
167: SetFocus (hwndDisplayFonts);
168: break;
169:
170: case TBID_PRINT:
171: SetWindowPos (hwndPrinterFonts, NULL, 0,0,0,0,
172: SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
173: SetFocus (hwndPrinterFonts);
174: break;
175:
176: case TBID_CREATE:
177: SendMessage (hwndDlgLF, WMU_LFTODEMO, 0, (LONG) &lf);
178: flyWinWin (hwndMain, hwndDlgLF, hwndDemo, FWW_STEPS);
179: SendMessage (hwndDemo , WMU_LFTODEMO, 0, (LONG) &lf);
180: break;
181:
182: case TBID_GETTM:
183: SendMessage (hwndDemo , WMU_DEMOTOTM, 0, (LONG) &tm);
184: flyWinWin (hwndMain, hwndDemo, hwndDlgTM, FWW_STEPS);
185: SendMessage (hwndDlgTM, WMU_DEMOTOTM, 0, (LONG) &tm);
186: break;
187:
188:
189: /* two checkboxes. get new state and force repaint of demo window */
190: case TBID_CHKALLGLYPHS:
191: hwndButton = GetDlgItem(hwndTB, (int) LOWORD(wParam));
192: allglyphsGlobal = (BOOL) SendMessage (hwndButton, BM_GETCHECK, 0,0);
193: InvalidateRect (hwndDemo, NULL, TRUE);
194: break;
195:
196: case TBID_CHKMAPPERFLAGS:
197: hwndButton = GetDlgItem(hwndTB, (int) LOWORD(wParam));
198: mapperflagsGlobal = (BOOL) SendMessage (hwndButton, BM_GETCHECK, 0,0);
199: InvalidateRect (hwndDemo, NULL, TRUE);
200: break;
201:
202: } /* end switch */
203: } break; /* end WM_COMMAND */
204:
205:
206:
207:
208:
209: /**********************************************************************\
210: * WM_CREATE
211: *
212: * Create pens for drawing with later.
213: \**********************************************************************/
214: case WM_CREATE:
215: hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR);
216: break;
217:
218:
219: /**********************************************************************\
220: * WM_DESTROY
221: *
222: * Complement of the WM_CREATE message. Delete the pens that were
223: * created and then call postquitmessage.
224: \**********************************************************************/
225: case WM_DESTROY:
226: DeleteObject (hPenGrid);
227: PostQuitMessage(0);
228: break;
229:
230:
231:
232: /**********************************************************************\
233: * WM_ERASEBKGND
234: *
235: \**********************************************************************/
236: case WM_ERASEBKGND: {
237: HDC hdc;
238: RECT rect;
239: int i;
240:
241: hdc = (HDC)wParam;
242:
243: SetViewportOrgEx (hdc, 0, TOOLBARHEIGHT, NULL);
244: GetClientRect (hwndMain, &rect);
245: FillRect (hdc, &rect, GetStockObject (BLACK_BRUSH));
246:
247: SelectObject(hdc, hPenGrid);
248: /* Draw vertical lines. */
249: for (i = 0; i<= rect.right; i+=TICKSPACE){
250: MoveToEx (hdc, i, rect.top, NULL);
251: LineTo (hdc, i, rect.bottom);
252: }
253:
254: /* Draw horizontal lines. */
255: for (i = 0; i<= rect.bottom; i+=TICKSPACE){
256: MoveToEx (hdc, rect.left,i, NULL);
257: LineTo (hdc, rect.right,i);
258: }
259: } return TRUE;
260:
261:
262: default:
263: return (DefWindowProc(hwnd, message, wParam, lParam));
264: }
265: return (NULL);
266: }
267:
268:
269:
270:
271:
272:
273: /**************************************************************************\
274: * function: flyWinWin
275: *
276: * Send rectangles flying on the screen to indicate data flow.
277: *
278: * input parameters:
279: * hwndMain - parent window in which other two exist (grandchildren o.k.)
280: * hwndFrom - rectangles originate here.
281: * hwndTo - and travel here.
282: * steps - number of steps to take. Fewer is faster.
283: *
284: \**************************************************************************/
285: VOID flyWinWin(HWND hwndMain, HWND hwndFrom, HWND hwndTo, int steps)
286: {
287: RECT rectFrom, rectTo;
288: RECT rectI;
289: HDC hdc;
290: int i, iLeft, iTop, iRight, iBottom;
291:
292: /* retrieve the window rects in screen coordinates. */
293: GetWindowRect (hwndFrom, &rectFrom);
294: GetWindowRect (hwndTo, &rectTo);
295:
296: /* convert them to be relative to the parent window. */
297: ScreenToClient (hwndMain,(LPPOINT)&rectFrom.left);
298: ScreenToClient (hwndMain,(LPPOINT)&rectFrom.right);
299: ScreenToClient (hwndMain,(LPPOINT)&rectTo.left);
300: ScreenToClient (hwndMain,(LPPOINT)&rectTo.right);
301:
302: /* Get an HDC, set the ROP so that painting twice will restore to the
303: * same state. Then select in the NULL brush so that the Rectangle()
304: * call will not fill in the interior.
305: */
306: hdc = GetDC (hwndMain);
307: SetROP2(hdc, R2_NOT);
308: SelectObject (hdc, GetStockObject (NULL_BRUSH));
309:
310: /* Compute the increment to change on each step. Notice that round
311: * off loss will cause the target window (hwndTo) to be "missed" if
312: * the windows nearly allign on some edge, and there are a large number
313: * of steps.
314: */
315: iLeft = (rectTo.left - rectFrom.left) /steps;
316: iTop = (rectTo.top - rectFrom.top) /steps;
317: iRight = (rectTo.right - rectFrom.right) /steps;
318: iBottom = (rectTo.bottom - rectFrom.bottom) /steps;
319:
320: /* Draw the series of rectangles the first time. */
321: rectI = rectFrom;
322: for (i= 0; i<steps; i++) {
323: rectI.left += iLeft;
324: rectI.top += iTop;
325: rectI.right += iRight;
326: rectI.bottom += iBottom;
327:
328: Rectangle (hdc, rectI.left, rectI.top , rectI.right, rectI.bottom);
329: }
330:
331: /* start from the same place, and draw them again... this time erases. */
332: rectI = rectFrom;
333: for (i= 0; i< steps; i++) {
334: rectI.left += iLeft;
335: rectI.top += iTop;
336: rectI.right += iRight;
337: rectI.bottom += iBottom;
338:
339: Rectangle (hdc, rectI.left, rectI.top , rectI.right, rectI.bottom);
340: }
341:
342: ReleaseDC (hwndMain,hdc);
343: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.