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