|
|
1.1 root 1: /**************************************************************************\
2: * ntfonts.c -- Font enumeration and manipulation program for Win32/NT.
3: *
1.1.1.2 ! root 4: *
! 5: * Steve Firebaugh
! 6: * Microsoft Developer Support
! 7: * Copyright (c) 1992 Microsoft Corporation
! 8: *
1.1 root 9: *
10: * design: There is a main frame window (hwndMain) with a child toolbar,
11: * two child dialogs, and a child demonstration window. All window handles
12: * are global and are accesible to all modules. There is a module for each
13: * of the classes of windows. Each module contains an initialization routine
14: * to register the class and create the window(s). Each module also contains
15: * a window procedure for that class. The two windows which list all of the
16: * fonts are also children of the main window, and they are hidden and shown
17: * as needed.
18: *
19: * Communication between windows is via message passing. The toolbar passes
20: * all of its command messages back to the main window. Other windows pass
21: * information back and forth with the following USER defined messages:
1.1.1.2 ! root 22: * WMU_LFTODEMO, WMU_DEMOTOLF, WMU_DEMOTOTM... Rectangles fly on the screen
1.1 root 23: * (c.f. flyWinWin) to mirror message trafic, i.e. data flow.
24: *
25: \**************************************************************************/
1.1.1.2 ! root 26: #define UNICODE
1.1 root 27:
28: #include <windows.h>
29: #include "ntfonts.h"
30:
31:
32: /* Misc. defines for size, color, and appearance of drawing. */
33: #define GRIDCOLOR PALETTEINDEX (6)
34: #define TICKSPACE 20
35: #define FWW_STEPS 40
36:
37:
38:
1.1.1.2 ! root 39: TCHAR initString[] = TEXT("Please wait. Initializing data structures.");
! 40: TCHAR szHelpPathName[] = TEXT("NTFONTS.HLP");
! 41:
1.1 root 42:
43:
44: /**************************************************************************\
45: *
46: * function: WinMain()
47: *
48: * input parameters: c.f. generic sample
49: *
50: \**************************************************************************/
51: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
52: LPSTR lpCmdLine, int nCmdShow)
53: {
54: MSG msg;
55: HWND hwndInfo;
1.1.1.2 ! root 56: CLIENTCREATESTRUCT clientcreate;
1.1 root 57:
58:
59: UNREFERENCED_PARAMETER( lpCmdLine );
60: UNREFERENCED_PARAMETER( nCmdShow );
61: hInst = hInstance;
62:
63:
64: /* Check for previous instance. If none, then register class. */
65: if (!hPrevInstance) {
66: WNDCLASS wc;
67:
68: wc.style = NULL;
69: wc.lpfnWndProc = (WNDPROC)MainWndProc;
70:
71: wc.cbClsExtra = 0;
72: wc.cbWndExtra = 0;
73: wc.hInstance = hInstance;
1.1.1.2 ! root 74: wc.hIcon = LoadIcon(hInstance, TEXT("ntfontsIcon"));
1.1 root 75: wc.hCursor = LoadCursor(NULL, IDC_ARROW);
76: wc.hbrBackground = NULL;
1.1.1.2 ! root 77: wc.lpszMenuName = TEXT("ntfontsMenu");
! 78: wc.lpszClassName = TEXT("ntfonts");
1.1 root 79:
80: if (!RegisterClass(&wc)) return (FALSE);
81:
82: } /* class registered o.k. */
83:
84:
85: /* Create the main window. Return false if CreateWindow() fails */
86: hwndMain = CreateWindow(
1.1.1.2 ! root 87: TEXT("ntfonts"),
! 88: TEXT("NT Fonts"),
1.1 root 89: WS_OVERLAPPEDWINDOW,
90: CW_USEDEFAULT,
91: CW_USEDEFAULT,
92: CW_USEDEFAULT,
93: CW_USEDEFAULT,
94: NULL, NULL, hInst, NULL);
95:
96: if (!hwndMain) return (FALSE);
97:
98:
1.1.1.2 ! root 99: /* create the MDI "client" window. */
! 100: clientcreate.hWindowMenu = NULL; /* don't add window names to menu */
! 101: clientcreate.idFirstChild = 1;
! 102: hwndClient = CreateWindow(
! 103: TEXT("MDICLIENT"),
! 104: NULL,
! 105: WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
! 106: 0,0,0,0,
! 107: hwndMain, NULL, hInst, (LPVOID)&clientcreate);
! 108: if (!hwndClient) return (FALSE);
! 109:
! 110:
1.1 root 111: /* create temporary window to display while initialization completes */
112: hwndInfo = CreateWindow(
1.1.1.2 ! root 113: TEXT("EDIT"),
1.1 root 114: initString,
115: WS_CHILD | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_CENTER,
116: 0,0,
117: GetSystemMetrics (SM_CXFULLSCREEN),
118: GetSystemMetrics (SM_CYFULLSCREEN),
119: hwndMain, NULL, hInst, NULL);
120:
1.1.1.2 ! root 121: SetWindowPos (hwndInfo, HWND_TOP, 0,0,0,0, SWP_NOSIZE);
! 122: UpdateWindow(hwndInfo);
1.1 root 123:
124: /* perform initialization for other windows...allfont is SLOW */
1.1.1.2 ! root 125: if (!initTB(hwndMain)) return FALSE;
! 126: if (!initDisplay(hwndClient)) return FALSE;
! 127: if (!initDlg(hwndClient)) return FALSE;
! 128: if (!initAllFont(hwndClient)) return FALSE;
1.1 root 129:
130:
131:
132: /* get rid of the temporary "please wait..." window. */
133: DestroyWindow (hwndInfo);
1.1.1.2 ! root 134: ShowWindow(hwndMain, SW_SHOWMAXIMIZED);
! 135:
! 136:
! 137: ShowWindow(hwndMain, SW_SHOWMAXIMIZED);
! 138: SendMessage (hwndMain, WM_COMMAND, IDM_ARRANGE,0);
1.1 root 139:
140: /* Loop getting messages and dispatching them. */
141: while (GetMessage(&msg,NULL, NULL, NULL)) {
142: if (!IsDialogMessage (hwndDlgTM, &msg))
1.1.1.2 ! root 143: if (!IsDialogMessage (hwndDlgOLTM, &msg))
! 144: if (!IsDialogMessage (hwndDlgLF, &msg))
! 145: if (!IsDialogMessage (hwndDlgFD, &msg)){
1.1 root 146: TranslateMessage(&msg);
147: DispatchMessage(&msg);
148: }
149: }
150:
151: return (msg.wParam);
152: }
153:
154:
155:
156: /**************************************************************************\
157: *
158: * function: MainWndProc()
159: *
160: * input parameters: normal window procedure parameters.
161: *
162: \**************************************************************************/
1.1.1.2 ! root 163: LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1.1 root 164: {
165: static HANDLE hPenGrid;
166: static LOGFONT lf;
167: static TEXTMETRIC tm;
168:
169: switch (message) {
170:
171:
172: /**********************************************************************\
173: * WM_COMMAND
174: *
175: * The WM_COMMAND messages here are passed up from the toolbar.
176: * Take whatever action is necesarry for the various buttons.
177: * (Either showing/hiding enumeration windows, or moving information
178: * in structures between different windows.)
179: \**********************************************************************/
180: case WM_COMMAND: {
181:
182: switch (LOWORD(wParam)) {
1.1.1.2 ! root 183: HDC hdcDemo;
1.1 root 184:
185: case TBID_ENUM:
1.1.1.2 ! root 186: ShowWindow(hwndDisplayFonts, SW_SHOWMAXIMIZED);
1.1 root 187: break;
188:
189: case TBID_PRINT:
1.1.1.2 ! root 190: ShowWindow(hwndPrinterFonts, SW_SHOWMAXIMIZED);
1.1 root 191: break;
192:
1.1.1.2 ! root 193: /* Send the LOGFONT dialog a message to fill in a LOGFONT structure,
! 194: * then pass that structure along to the DEMO window.
! 195: */
1.1 root 196: case TBID_CREATE:
197: SendMessage (hwndDlgLF, WMU_LFTODEMO, 0, (LONG) &lf);
1.1.1.2 ! root 198: flyWinWin (hwndMain, hwndDlgLF, hwndDisplay, FWW_STEPS);
! 199: SendMessage (hwndDisplay , WMU_NEWFONT, 0, (LONG) &lf);
1.1 root 200: break;
201:
1.1.1.2 ! root 202:
! 203: /* Same exchange as LOGFONT for the TEXTMETRIC structure.
! 204: * However, for the OUTLINETEXTMETRIC stucture,
! 205: * send the DEMO window a message asking for an HDC with the
! 206: * current font selected into it. Pass that HDC along to the
! 207: * OUTLINETEXTMETRIC dialog so that it can query the structure,
! 208: * and display the values.
! 209: */
1.1 root 210: case TBID_GETTM:
1.1.1.2 ! root 211:
! 212: SendMessage (hwndDisplay , WMU_DEMOTOTM, 0, (LONG) &tm);
! 213: flyWinWin (hwndMain, hwndDisplay, hwndDlgTM, FWW_STEPS);
1.1 root 214: SendMessage (hwndDlgTM, WMU_DEMOTOTM, 0, (LONG) &tm);
1.1.1.2 ! root 215:
! 216: hdcDemo = (HDC) SendMessage (hwndDisplay , WMU_DEMOGETDC, 0, 0);
! 217: flyWinWin (hwndMain, hwndDisplay, hwndDlgOLTM, FWW_STEPS);
! 218: SendMessage (hwndDlgOLTM, WMU_DEMOTOOLTM, 0, (LPARAM) hdcDemo);
! 219: SendMessage (hwndDisplay , WMU_DEMORELEASEDC, 0, (LPARAM) hdcDemo);
! 220:
1.1 root 221: break;
222:
223:
1.1.1.2 ! root 224: /* Send message down to hwndDlgFD w/ HDC from hwndDisplay.
! 225: * hwndDlgFD will parse its params, and call GetFontData().
! 226: */
! 227: case TBID_GETFONTDATA:
! 228:
! 229: hdcDemo = (HDC) SendMessage (hwndDisplay , WMU_DEMOGETDC, 0, 0);
! 230: flyWinWin (hwndMain, hwndDisplay, hwndDlgFD, FWW_STEPS);
! 231: SendMessage (hwndDlgFD, WMU_GETFONTDATA, 0, (LPARAM) hdcDemo);
! 232: SendMessage (hwndDisplay , WMU_DEMORELEASEDC, 0, (LPARAM) hdcDemo);
! 233:
1.1 root 234: break;
235:
1.1.1.2 ! root 236:
! 237: /* Simply send message to display window, and it does all work. */
! 238: case IDM_PRINT:
! 239: SendMessage (hwndDisplay , WMU_PRINT, 0, 0);
! 240: break;
! 241:
! 242:
! 243: case IDM_HELP:
! 244: WinHelp( hwnd, szHelpPathName, HELP_INDEX, (DWORD) NULL );
1.1 root 245: break;
246:
1.1.1.2 ! root 247:
! 248: case IDM_ABOUT:
! 249: DialogBox (hInst, TEXT("aboutBox"), hwnd, (DLGPROC) About);
! 250: break;
! 251:
! 252:
! 253:
! 254: /******************************************************************\
! 255: * WM_COMMAND, IDM_FLYWINWIN
! 256: *
! 257: * Check menu on and off. Query state in FlyWinWin() function.
! 258: \******************************************************************/
! 259: case IDM_FLYWINWIN:
! 260: if (GetMenuState (GetMenu (hwnd),IDM_FLYWINWIN, MF_BYCOMMAND)
! 261: == MF_CHECKED) {
! 262: CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED);
! 263: } else {
! 264: CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED);
! 265: }
! 266: break;
! 267:
! 268:
! 269: /******************************************************************\
! 270: * WM_COMMAND, IDM_MODE*
! 271: *
! 272: * manage mutually exclusive menu.
! 273: * inform the window that it has a new mode.
! 274: * invalidate window to force repaint.
! 275: * Special case MODEALL to check that it is o.k. first.
! 276: \******************************************************************/
! 277: case IDM_MODEALL :
! 278: if (!SendMessage (hwndDisplay, WMU_NEWMODEALL, 0,0)) {
! 279: return 0;
! 280: }
! 281: CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_UNCHECKED);
! 282: CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_UNCHECKED);
! 283: CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_CHECKED);
! 284: InvalidateRect (hwndDisplay, NULL, TRUE);
! 285: return 0;
! 286:
! 287: case IDM_MODEHELLO :
! 288: CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_CHECKED);
! 289: CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_UNCHECKED);
! 290: CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_UNCHECKED);
! 291: SendMessage (hwndDisplay, WMU_NEWMODEHELLO, 0,0);
! 292: InvalidateRect (hwndDisplay, NULL, TRUE);
! 293: return 0;
! 294:
! 295: case IDM_MODETMRANGE:
! 296: CheckMenuItem(GetMenu (hwnd), IDM_MODEHELLO , MF_UNCHECKED);
! 297: CheckMenuItem(GetMenu (hwnd), IDM_MODETMRANGE, MF_CHECKED);
! 298: CheckMenuItem(GetMenu (hwnd), IDM_MODEALL , MF_UNCHECKED);
! 299: SendMessage (hwndDisplay, WMU_NEWMODETMRANGE, 0,0);
! 300: InvalidateRect (hwndDisplay, NULL, TRUE);
! 301: return 0;
! 302:
! 303:
! 304:
! 305: /******************************************************************\
! 306: * WM_COMMAND, IDM_*
! 307: *
! 308: * misc. MDI responsibilities. hwndClient does real work.
! 309: \******************************************************************/
! 310: case IDM_CASCADE: SendMessage (hwndClient, WM_MDICASCADE, 0,0); break;
! 311: case IDM_TILE: SendMessage (hwndClient, WM_MDITILE, 0,0); break;
! 312: case IDM_ARRANGE:
! 313: ShowWindow(hwndDisplayFonts, SW_SHOWMINIMIZED);
! 314: ShowWindow(hwndPrinterFonts, SW_SHOWMINIMIZED);
! 315: ShowWindow(hwndDlgOLTM, SW_SHOWMINIMIZED);
! 316: ShowWindow(hwndDlgFD, SW_SHOWMINIMIZED);
! 317: ShowWindow(hwndDlgTM, SW_RESTORE);
! 318: SetWindowPos (hwndDlgTM, HWND_TOP,
! 319: CHILDLEFT(0), CHILDTOP, 0,0, SWP_NOSIZE);
! 320: ShowWindow(hwndDlgLF, SW_RESTORE);
! 321: SetWindowPos (hwndDlgLF, HWND_TOP,
! 322: CHILDLEFT(1), CHILDTOP, 0,0, SWP_NOSIZE);
! 323: ShowWindow(hwndDisplay, SW_RESTORE);
! 324: SetWindowPos (hwndDisplay, HWND_TOP,
! 325: CHILDLEFT(2), CHILDTOP,
! 326: GetSystemMetrics (SM_CXFULLSCREEN)/3 - 10,
! 327: GetSystemMetrics (SM_CYFULLSCREEN)/3, 0);
! 328: SendMessage (hwndClient, WM_MDIICONARRANGE, 0,0);
! 329: break;
! 330:
! 331:
! 332:
! 333:
1.1 root 334: } /* end switch */
335: } break; /* end WM_COMMAND */
336:
337:
338:
339:
340:
341: /**********************************************************************\
342: * WM_CREATE
343: *
344: * Create pens for drawing with later.
345: \**********************************************************************/
346: case WM_CREATE:
1.1.1.2 ! root 347: hPenGrid = CreatePen (PS_SOLID, 1, GRIDCOLOR);
! 348: CheckMenuItem (GetMenu (hwnd), IDM_FLYWINWIN, MF_BYCOMMAND | MF_CHECKED);
! 349: CheckMenuItem (GetMenu (hwnd), IDM_MODEHELLO, MF_BYCOMMAND | MF_CHECKED);
! 350: gDisplaymode = IDM_MODEHELLO;
1.1 root 351: break;
352:
353:
354: /**********************************************************************\
355: * WM_DESTROY
356: *
357: * Complement of the WM_CREATE message. Delete the pens that were
358: * created and then call postquitmessage.
359: \**********************************************************************/
360: case WM_DESTROY:
361: DeleteObject (hPenGrid);
1.1.1.2 ! root 362: WinHelp( hwnd, szHelpPathName, (UINT) HELP_QUIT, (DWORD) NULL );
1.1 root 363: PostQuitMessage(0);
364: break;
365:
366:
367:
368: /**********************************************************************\
1.1.1.2 ! root 369: * WM_SIZE
! 370: *
! 371: * When the frame is sized, then change the size of the MDI client.
! 372: \**********************************************************************/
! 373: case WM_SIZE: {
! 374:
! 375: RECT r;
! 376: GetClientRect (hwnd, &r);
! 377: r.top += TOOLBARHEIGHT;
! 378: r.bottom -= TOOLBARHEIGHT;
! 379: SetWindowPos (hwndClient, HWND_BOTTOM,
! 380: r.left, r.top, r.right, r.bottom, 0);
! 381: return TRUE;
! 382:
! 383: } break;
! 384:
! 385:
! 386: //HACK. This code not used because of new MDI.
! 387: // move to subclassed client window.
! 388: /**********************************************************************\
1.1 root 389: * WM_ERASEBKGND
390: *
391: \**********************************************************************/
392: case WM_ERASEBKGND: {
393: HDC hdc;
394: RECT rect;
395: int i;
396:
397: hdc = (HDC)wParam;
398:
399: SetViewportOrgEx (hdc, 0, TOOLBARHEIGHT, NULL);
400: GetClientRect (hwndMain, &rect);
401: FillRect (hdc, &rect, GetStockObject (BLACK_BRUSH));
402:
403: SelectObject(hdc, hPenGrid);
404: /* Draw vertical lines. */
405: for (i = 0; i<= rect.right; i+=TICKSPACE){
406: MoveToEx (hdc, i, rect.top, NULL);
407: LineTo (hdc, i, rect.bottom);
408: }
409:
410: /* Draw horizontal lines. */
411: for (i = 0; i<= rect.bottom; i+=TICKSPACE){
412: MoveToEx (hdc, rect.left,i, NULL);
413: LineTo (hdc, rect.right,i);
414: }
415: } return TRUE;
416:
417:
1.1.1.2 ! root 418: default: break;
! 419: } /* end switch */
! 420:
! 421: return (DefFrameProc(hwnd, hwndClient, message, wParam, lParam));
1.1 root 422: }
423:
424:
425:
1.1.1.2 ! root 426: /***************************************************************************\
! 427: * FUNCTION: About
! 428: \***************************************************************************/
! 429: LRESULT CALLBACK About(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
! 430: {
! 431: if ((message == WM_COMMAND) && (LOWORD(wParam) == IDOK)) {
! 432: EndDialog (hwnd, TRUE);
! 433: return TRUE;
! 434: }
! 435: if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) {
! 436: EndDialog (hwnd, TRUE);
! 437: return TRUE;
! 438: }
! 439: return FALSE;
! 440: }
! 441:
! 442:
1.1 root 443:
444:
445:
446: /**************************************************************************\
447: * function: flyWinWin
448: *
449: * Send rectangles flying on the screen to indicate data flow.
450: *
451: * input parameters:
1.1.1.2 ! root 452: * handParent - parent window in which other two exist (grandchildren o.k.)
1.1 root 453: * hwndFrom - rectangles originate here.
454: * hwndTo - and travel here.
455: * steps - number of steps to take. Fewer is faster.
456: *
457: \**************************************************************************/
1.1.1.2 ! root 458: VOID flyWinWin(HWND handParent, HWND hwndFrom, HWND hwndTo, int steps)
1.1 root 459: {
460: RECT rectFrom, rectTo;
461: RECT rectI;
462: HDC hdc;
463: int i, iLeft, iTop, iRight, iBottom;
464:
1.1.1.2 ! root 465: /* The menu bar contains a checked/unchecked item which stores the
! 466: * state of the user's preference on whether this "information flow"
! 467: * should be done or not. If unchecked, then return before doing
! 468: * anything.
! 469: */
! 470: if (GetMenuState (GetMenu (hwndMain),IDM_FLYWINWIN, MF_BYCOMMAND)
! 471: != MF_CHECKED) return;
! 472:
! 473:
1.1 root 474: /* retrieve the window rects in screen coordinates. */
475: GetWindowRect (hwndFrom, &rectFrom);
476: GetWindowRect (hwndTo, &rectTo);
477:
478: /* convert them to be relative to the parent window. */
1.1.1.2 ! root 479: ScreenToClient (handParent,(LPPOINT)&rectFrom.left);
! 480: ScreenToClient (handParent,(LPPOINT)&rectFrom.right);
! 481: ScreenToClient (handParent,(LPPOINT)&rectTo.left);
! 482: ScreenToClient (handParent,(LPPOINT)&rectTo.right);
1.1 root 483:
484: /* Get an HDC, set the ROP so that painting twice will restore to the
485: * same state. Then select in the NULL brush so that the Rectangle()
486: * call will not fill in the interior.
487: */
1.1.1.2 ! root 488: hdc = GetDC (handParent);
1.1 root 489: SetROP2(hdc, R2_NOT);
490: SelectObject (hdc, GetStockObject (NULL_BRUSH));
491:
492: /* Compute the increment to change on each step. Notice that round
493: * off loss will cause the target window (hwndTo) to be "missed" if
494: * the windows nearly allign on some edge, and there are a large number
495: * of steps.
496: */
497: iLeft = (rectTo.left - rectFrom.left) /steps;
498: iTop = (rectTo.top - rectFrom.top) /steps;
499: iRight = (rectTo.right - rectFrom.right) /steps;
500: iBottom = (rectTo.bottom - rectFrom.bottom) /steps;
501:
502: /* Draw the series of rectangles the first time. */
503: rectI = rectFrom;
504: for (i= 0; i<steps; i++) {
505: rectI.left += iLeft;
506: rectI.top += iTop;
507: rectI.right += iRight;
508: rectI.bottom += iBottom;
509:
510: Rectangle (hdc, rectI.left, rectI.top , rectI.right, rectI.bottom);
511: }
512:
513: /* start from the same place, and draw them again... this time erases. */
514: rectI = rectFrom;
515: for (i= 0; i< steps; i++) {
516: rectI.left += iLeft;
517: rectI.top += iTop;
518: rectI.right += iRight;
519: rectI.bottom += iBottom;
520:
521: Rectangle (hdc, rectI.left, rectI.top , rectI.right, rectI.bottom);
522: }
523:
1.1.1.2 ! root 524: ReleaseDC (handParent,hdc);
1.1 root 525: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.