Annotation of mstools/samples/mfedit/mfedit.c, revision 1.1.1.3

1.1       root        1: /******************************Module*Header*******************************\
                      2: * Module Name: mfedit.c
                      3: *
                      4: * Main module for the Enhanced Metafile Editor
                      5: *       contains everything
                      6: *
                      7: * Created: 28-May-1992 14:24:00
                      8: * Author: Petrus Wong
                      9: *
1.1.1.2   root       10: * Copyright (c) 1992 Microsoft Corporation
1.1       root       11: *
                     12: * The Enhanced Metafile Editor serves to demonstrate the enhanced metafile
                     13: * APIs in Windows NT.
                     14: *
                     15: * The Editor provides the following functions:
                     16: *       1.  Playback and recording of GDI calls
                     17: *       2.  Embedding bitmap and enhanced metafile into another enhanced
                     18: *           metafile with transformation
                     19: *       3.  Hit-testing against enhanced metafile records
                     20: *       4.  Random access playback
                     21: *       5.  Playback metafile records one-by-one
                     22: *       6.  Selective recording of existing enhanced metafile records into
                     23: *           a new enhanced metafile
                     24: *       7.  drawing with pen, text, bezier, line, ellipse, rectangle and
                     25: *           embedding bitmap and enhanced metafile tools
                     26: *
                     27: * Dependencies:
                     28: *
                     29: *   metadef.h   - contains definition for enhanced metafile records
                     30: *
                     31: \**************************************************************************/
                     32: #include <stdlib.h>
                     33: #include "mfedit.h"
                     34: #include <stdarg.h>
                     35: #include <string.h>
                     36: #include <stdio.h>
                     37: #include <commdlg.h>
1.1.1.3 ! root       38: #include <shellapi.h>
        !            39: #include <math.h>
1.1.1.2   root       40: 
1.1       root       41: //
                     42: // Forward declarations.
                     43: //
                     44: BOOL InitializeApp   (void);
1.1.1.2   root       45: LONG APIENTRY MainWndProc     (HWND, UINT, DWORD, LONG);
                     46: LONG APIENTRY DrawSurfWndProc (HWND, UINT, DWORD, LONG);
1.1.1.3 ! root       47: BOOL CALLBACK About           (HWND, UINT, DWORD, LONG);
1.1.1.2   root       48: LONG APIENTRY TextWndProc     (HWND, UINT, DWORD, LONG);
                     49: LONG APIENTRY CtrlPanelDlgProc(HWND, UINT, DWORD, LONG);
1.1       root       50: BOOL bDrawStuff      (HDC, INT, INT, INT, INT, BOOL, BOOL, BOOL, LPSTR);
                     51: HENHMETAFILE hemfLoadMetafile(HWND);
                     52: HDC  hDCRecordMetafileAs(HWND, LPSTR);
                     53: BOOL APIENTRY bPlayRecord(HDC, LPHANDLETABLE, LPENHMETARECORD, UINT, LPVOID);
                     54: BOOL APIENTRY bDoHitTest(HDC, LPHANDLETABLE, LPENHMETARECORD, UINT, LPVOID);
                     55: BOOL bHitTest(HDC, INT, INT);
                     56: HBITMAP hBmpLoadBitmapFile(HDC, PSTR);
                     57: BOOL bGetBMP(HWND, BOOL);
                     58: BOOL bChooseNewFont(HWND, PLOGFONT, COLORREF * );
                     59: BOOL bChooseNewColor(HWND, LPDWORD);
1.1.1.3 ! root       60: BOOL bPrintMf(PPRTDATA);
1.1       root       61: HBRUSH hBrCreateBrush(HDC, DWORD);
1.1.1.3 ! root       62: BOOL bSelectDIBPal(HDC, LPBITMAPINFO, BOOL);
        !            63: BOOL bFreeDibFile(PDIBDATA);
        !            64: BOOL bPlgBlt(HDC, LPPOINT);
        !            65: HPALETTE CopyPalette(HPALETTE hPalSrc);
        !            66: int CALLBACK iTT(LPLOGFONT, LPTEXTMETRIC, DWORD, LPARAM);
1.1       root       67: 
                     68: /***************************************************************************\
                     69: * WinMain
                     70: *
                     71: * History:
                     72: * 11-Feb-1992   Petrus Wong
                     73: \***************************************************************************/
1.1.1.3 ! root       74: int WINAPI WinMain(
        !            75: #if 0
1.1.1.2   root       76:            HANDLE hInstance,
                     77:            HANDLE hPrevInstance,
1.1.1.3 ! root       78: #endif
        !            79:            HINSTANCE hInstance,
        !            80:            HINSTANCE hPrevInstance,
1.1.1.2   root       81:            LPSTR lpCmdLine,
                     82:            int nShowCmd)
1.1       root       83: {
                     84:     MSG    msg;
                     85:     HANDLE hAccel;
                     86: 
                     87:     ghModule = GetModuleHandle(NULL);
                     88:     if (!InitializeApp()) {
                     89:        MessageBox(ghwndMain, "MfEdit: InitializeApp failure!", "Error", MB_OK);
                     90:         return 0;
                     91:     }
                     92: 
                     93:     if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
                     94:        MessageBox(ghwndMain, "MfEdit: Load Accel failure!", "Error", MB_OK);
                     95: 
                     96: 
                     97:     while (GetMessage(&msg, NULL, 0, 0)) {
                     98:         if (!TranslateAccelerator( ghwndMain, hAccel, &msg) ) {
                     99:             TranslateMessage(&msg);
                    100:             DispatchMessage(&msg);
                    101:         }
                    102:     }
                    103: 
                    104:     return 1;
                    105: 
                    106:     UNREFERENCED_PARAMETER(lpCmdLine);
                    107:     UNREFERENCED_PARAMETER(nShowCmd);
                    108:     UNREFERENCED_PARAMETER(hInstance);
                    109:     UNREFERENCED_PARAMETER(hPrevInstance);
                    110: }
                    111: 
                    112: 
                    113: /***************************************************************************\
                    114: * InitializeApp
                    115: *
                    116: * History:
                    117: * 11-Feb-1992   Petrus Wong
                    118: *   Name changes.
                    119: * 09-09-91      Petrus Wong    Created.
                    120: \***************************************************************************/
                    121: 
                    122: BOOL InitializeApp(void)
                    123: {
                    124:     WNDCLASS wc;
                    125:     int index;
1.1.1.3 ! root      126:     HDC hDC;
1.1       root      127: 
                    128:     wc.style            = CS_DBLCLKS;
                    129:     wc.lpfnWndProc      = (WNDPROC)MainWndProc;
                    130:     wc.cbClsExtra       = 0;
                    131:     wc.cbWndExtra      = sizeof(DWORD);
                    132:     wc.hInstance        = ghModule;
1.1.1.3 ! root      133:     wc.hIcon            = LoadIcon(ghModule, MAKEINTRESOURCE(APP_ICON));
1.1       root      134:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
                    135:     wc.hbrBackground   = (HBRUSH)(COLOR_APPWORKSPACE + 1);
                    136:     wc.lpszMenuName     = "MainMenu";
                    137:     wc.lpszClassName   = "MetafDemoClass";
                    138: 
                    139:     if (!RegisterClass(&wc))
                    140:        return FALSE;
                    141: 
                    142:     wc.style            = CS_OWNDC | CS_SAVEBITS;
                    143:     wc.lpfnWndProc      = (WNDPROC)DrawSurfWndProc;
                    144:     wc.hIcon            = NULL;
                    145:     wc.hCursor          = NULL;
                    146:     wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);
                    147:     wc.lpszMenuName     = NULL;
                    148:     wc.lpszClassName    = "DrawSurfClass";
                    149: 
                    150:     if (!RegisterClass(&wc))
                    151:        return FALSE;
                    152: 
                    153:     wc.style           = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
                    154:     wc.lpfnWndProc     = (WNDPROC)TextWndProc;
                    155:     wc.hIcon           = NULL;
                    156:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
                    157:     wc.hbrBackground   = (HBRUSH)(COLOR_BTNFACE + 1);
                    158:     wc.lpszMenuName    = NULL;
                    159:     wc.lpszClassName   = "Text";
                    160: 
                    161:     if (!RegisterClass(&wc))
                    162:             return FALSE;
                    163: 
                    164: 
                    165: 
                    166:     hMenu      = LoadMenu(ghModule, "MainMenu");
                    167: 
                    168:     for (index = 0; index < OD_BTN_CNT; index++) {
                    169:         ghBmpDn[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_BASED+index));
                    170:         ghBmpUp[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_BASEU+index));
                    171:     }
                    172:     for (index = 0; index < OD_TOOL_CNT; index++) {
                    173:         ghToolBmpDn[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_TOOLBASED+index));
                    174:         ghToolBmpUp[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_TOOLBASEU+index));
                    175: 
                    176:     }
                    177: 
                    178:     ghwndMain = CreateWindowEx(0L, "MetafDemoClass", "Enhanced Metafile Editor",
                    179:            WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
                    180:            WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
                    181:            WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
                    182:             80, 70, 600, 300,
                    183:            NULL, hMenu, ghModule, NULL);
                    184: 
                    185:     if (ghwndMain == NULL)
                    186:        return FALSE;
                    187: 
                    188:     SetWindowLong(ghwndMain, GWL_USERDATA, 0L);
1.1.1.2   root      189:     ghwndNext = SetClipboardViewer(ghwndMain);
1.1       root      190: 
1.1.1.3 ! root      191:     if (gbFit2Wnd)
        !           192:         CheckMenuItem(hMenu, MM_FIT2WND, MF_CHECKED);
        !           193:     else
        !           194:         CheckMenuItem(hMenu, MM_FIT2WND, MF_UNCHECKED);
        !           195: 
        !           196:     if (gbImport3X)
        !           197:         CheckMenuItem(hMenu, MM_IMPORT_3X, MF_CHECKED);
        !           198:     else
        !           199:         CheckMenuItem(hMenu, MM_IMPORT_3X, MF_UNCHECKED);
        !           200: 
        !           201:     if (gbExport3X)
        !           202:         CheckMenuItem(hMenu, MM_EXPORT_3X, MF_CHECKED);
        !           203:     else
        !           204:         CheckMenuItem(hMenu, MM_EXPORT_3X, MF_UNCHECKED);
        !           205: 
1.1       root      206:     SetFocus(ghwndMain);    /* set initial focus */
                    207: 
1.1.1.3 ! root      208:     gDib.ulFiles = gDib.ulFrames = 0;
        !           209:     hDC = GetDC(NULL);
        !           210:     ghHT = CreateHalftonePalette(hDC);
        !           211:     ReleaseDC(NULL, hDC);
        !           212: 
1.1       root      213:     return TRUE;
                    214: }
                    215: 
                    216: 
                    217: /***************************************************************************\
                    218: * MainWndProc
                    219: *
                    220: * History:
                    221: * 11-Feb-1992   Petrus Wong
                    222: *   Name changes.  Added comments.
                    223: * 09-09-91      Petrus Wong    Created.
                    224: \***************************************************************************/
                    225: 
1.1.1.2   root      226: long APIENTRY MainWndProc(
1.1       root      227:     HWND hwnd,
                    228:     UINT message,
                    229:     DWORD wParam,
                    230:     LONG lParam)
                    231: {
                    232:     static int         iMetafCnt=0;
                    233:     static char        szFilename[256] = "c:\\metaf";
                    234:     static BOOL        bReset=FALSE;
1.1.1.3 ! root      235:     static char        szLoadedMetaf[256] = " ";
1.1       root      236: 
                    237:     switch (message) {
                    238: 
                    239:       case WM_CREATE: {
                    240: 
                    241:        SetWindowLong(hwnd, 0, (LONG)NULL);
                    242:         ghDCMem = CreateCompatibleDC(NULL);
                    243: 
                    244:         ghwndCtrlPanel = CreateDialog(ghModule, (LPCSTR)MAKEINTRESOURCE(DID_CTRLPANEL),
                    245:                      hwnd, (DLGPROC) CtrlPanelDlgProc);
                    246: 
                    247:         ghwndDrawSurf = CreateWindow("DrawSurfClass", NULL,
                    248:                                     WS_BORDER | WS_CHILD | WS_VISIBLE,
                    249:                                     0, 0, 0, 0,
                    250:                                     hwnd,
                    251:                                     NULL,
                    252:                                     ghModule,
                    253:                                     NULL);
                    254: 
                    255:         ghTextWnd = CreateWindow("Text", NULL,
                    256:                                 WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
                    257:                                 0, 0, 0, 0,
                    258:                                 hwnd,
                    259:                                 NULL,               //(HMENU) 2,
                    260:                                 ghModule,
                    261:                                 NULL);
                    262: 
                    263:         ghbrRed = CreateSolidBrush(RGB(255, 0, 0));
                    264:         ghbrAppBkgd = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
                    265:         ghpnWide = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                    266:         return 0L;
                    267:       }
1.1.1.2   root      268:       case WM_DRAWCLIPBOARD:
                    269:         if ((IsClipboardFormatAvailable(CF_METAFILEPICT)) ||
                    270:             (IsClipboardFormatAvailable(CF_ENHMETAFILE)) )
                    271:             EnableMenuItem(hMenu, MM_PASTE, MF_ENABLED);
                    272:         else
                    273:             EnableMenuItem(hMenu, MM_PASTE,  MF_GRAYED);
                    274: 
                    275:         if (ghwndNext)
                    276:             SendMessage(ghwndNext, message, wParam, lParam);
                    277:         return 0L;
1.1       root      278: 
                    279:       case WM_SIZE: {
                    280:           RECT        rc;
                    281:           LONG        lcyCtrlPanel, lcyDrawSurf;
                    282: 
                    283:           GetWindowRect(ghwndCtrlPanel, &rc);
                    284:           lcyCtrlPanel = rc.bottom-rc.top;
                    285:           lcyDrawSurf = HIWORD(lParam) - lcyCtrlPanel - glcyStatus;
                    286: 
                    287:           //
                    288:           // CR!! Alternatively, this window can be created with cy
                    289:           //      equals to cy of the screen and saving this call
                    290:           //      altogether.
                    291:           //
                    292:           MoveWindow(ghwndCtrlPanel,
                    293:                      0, 0, LOWORD(lParam), lcyCtrlPanel, TRUE);
                    294: 
                    295:           //
                    296:           // This ordering guarantees the text window paints correctly
                    297:           //
                    298:           MoveWindow(ghTextWnd,
                    299:                      0, lcyCtrlPanel + lcyDrawSurf,
                    300:                      LOWORD(lParam),                    // cx of hwnd
                    301:                      glcyStatus, TRUE);
                    302: 
                    303:           MoveWindow(ghwndDrawSurf,
                    304:                      0, lcyCtrlPanel,
                    305:                      LOWORD(lParam),                    // cx of hwnd
                    306:                      lcyDrawSurf, TRUE);
1.1.1.2   root      307:           //break;
                    308:           return DefWindowProc(hwnd, message, wParam, lParam);
1.1       root      309:       }
                    310: 
                    311:       case WM_DESTROY: {
                    312:         DeleteDC(ghDCMem);
                    313:         DeleteEnhMetaFile(ghMetaf);
                    314:         DestroyWindow(ghwndCtrlPanel);
                    315:         DeleteObject(ghbrRed);
                    316:         DeleteObject(ghbrCur);
                    317:         DeleteObject(ghpnCur);
                    318:         DeleteObject(ghbrAppBkgd);
                    319:         DeleteObject(ghpnWide);
1.1.1.3 ! root      320:         if (ghHT)
        !           321:             DeleteObject(ghHT);
1.1.1.2   root      322:         ChangeClipboardChain(ghwndMain, ghwndNext);
1.1.1.3 ! root      323:         bFreeDibFile(&gDib);
1.1       root      324:        PostQuitMessage(0);
                    325:        return 0L;
                    326:       }
                    327: 
                    328:       case WM_COMMAND: {
                    329:         static int     iPlus=0;
                    330: 
1.1.1.3 ! root      331: 
1.1       root      332:        switch (LOWORD(wParam)) {
                    333:             case DID_ZERO:
                    334:             case DID_ONE:
                    335:             case DID_TWO:
                    336:             case DID_THREE:
                    337:             case DID_FOUR:
                    338:             case DID_FIVE:
                    339:             case DID_SIX:
                    340:             case DID_SEVEN:
                    341:             case DID_EIGHT:
                    342:             case DID_NINE: {
                    343:                 HDC           hDCDrawSurf;
                    344:                 ENHMETAHEADER EnhMetaHdr;
1.1.1.3 ! root      345:                 RECT          rcClientDS;
1.1       root      346:                 int           iRecord;
                    347:                 PLAYINFO      PlayInfo;
                    348: 
                    349:                 if (ghMetaf == 0)
                    350:                     return 0L;
                    351: 
                    352:                 GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                    353:                 iRecord = LOWORD(wParam) - DID_ZERO + iPlus;
                    354:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iRecord, FALSE);
                    355:                 PlayInfo.iRecord = iRecord;
                    356:                 PlayInfo.bPlayContinuous = FALSE;
                    357:                 iPlus = 0;
                    358: 
                    359:                 if ((EnhMetaHdr.nRecords > 1) && (iRecord > 0) &&
                    360:                     (iRecord <= (INT) EnhMetaHdr.nRecords)) {
                    361:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
1.1.1.3 ! root      362:                     if (gbFit2Wnd) {
        !           363:                         GetClientRect(ghwndDrawSurf, &rcClientDS);
        !           364:                         EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, &rcClientDS);
        !           365:                     } else {
        !           366:                         EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
        !           367:                     }
1.1       root      368:                     //
                    369:                     // Enabling the user to record a metafile record selectively
                    370:                     //
1.1.1.2   root      371:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
                    372:                         EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
                    373:                     }
1.1       root      374:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                    375:                 }
                    376:                 return 0L;
                    377:             }
                    378:             case DID_TEN_PLUS: {
                    379:                 if (ghMetaf == 0)
                    380:                     return 0L;
                    381: 
                    382:                 iPlus += 10;
                    383:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iPlus, FALSE);
                    384:                 return 0L;
                    385:             }
                    386:             case MM_PAGESETUP:
                    387:             case MM_CUT:
                    388:                 return 0L;
1.1.1.2   root      389: 
                    390:             case MM_COPY:   {
1.1.1.3 ! root      391: 
        !           392:                 if ((ghMetaf == 0) && (ghmf == 0)) {
1.1.1.2   root      393:                     SetWindowText(ghTextWnd, "No Metafile for copying");
                    394:                     return 0L;
                    395:                 }
                    396: 
                    397:                 OpenClipboard(ghwndMain);
                    398:                 EmptyClipboard();
                    399: 
1.1.1.3 ! root      400:                 if (gbExport3X)
        !           401:                 {
        !           402:                     HGLOBAL          hmem;
        !           403:                     LPMETAFILEPICT  lpmfp;
        !           404:                     RECT            rcClientDS;
        !           405:                     DWORD           x, y, mm;
        !           406:                     HDC             hDCDrawSurf;
        !           407:                     LPBYTE          pjData;
        !           408:                     UINT            uiSize;
        !           409: 
        !           410:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
        !           411: 
        !           412:                     if (ghmf == 0) {
        !           413:                         SetWindowText(ghTextWnd, "Converting Enhanced Metafile to 3X format");
        !           414: 
        !           415:                         if (!(uiSize = GetWinMetaFileBits(ghMetaf, 0, NULL, MM_ANISOTROPIC, hDCDrawSurf))) {
        !           416:                             MessageBox(ghwndMain, "Fail in 1st GetWinMetaFileBits!", "Error", MB_OK);
        !           417:                             goto COPY_3X_EXIT;
        !           418:                         }
        !           419: 
        !           420:                         if ((pjData = (LPBYTE) LocalAlloc(LMEM_FIXED, uiSize)) == NULL) {
        !           421:                             MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
        !           422:                             goto COPY_3X_EXIT;
        !           423:                         }
        !           424: 
        !           425:                         if (!(uiSize = GetWinMetaFileBits(ghMetaf, uiSize, pjData, MM_ANISOTROPIC, hDCDrawSurf))) {
        !           426:                             MessageBox(ghwndMain, "Fail in 2nd GetWinMetaFileBits!", "Error", MB_OK);
        !           427:                             LocalFree(pjData);
        !           428:                             goto COPY_3X_EXIT;
        !           429:                         }
        !           430: 
        !           431:                         ghmf = SetMetaFileBitsEx(uiSize, (LPBYTE) pjData);
        !           432:                         LocalFree(pjData);
        !           433:                     }
        !           434: 
        !           435:                     if ((hmem = GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE,
        !           436:                                         sizeof(METAFILEPICT))) == NULL) {
        !           437: 
        !           438:                         SetWindowText(ghTextWnd, "Failed in allocating memory");
        !           439:                         goto COPY_3X_EXIT;
        !           440: 
        !           441:                     }
        !           442: 
        !           443:                     lpmfp = (LPMETAFILEPICT)GlobalLock(hmem);
        !           444:                     lpmfp->mm = mm = MM_ANISOTROPIC;
        !           445: 
        !           446:                     GetClientRect(ghwndDrawSurf, &rcClientDS);
        !           447:                     x = rcClientDS.right - rcClientDS.left;
        !           448:                     x *= 2540;
        !           449:                     x /= GetDeviceCaps(hDCDrawSurf, LOGPIXELSX);
        !           450:                     lpmfp->xExt = x;                                // ie. in 0.01mm
        !           451: 
        !           452:                     y = rcClientDS.bottom - rcClientDS.top;
        !           453:                     y *= 2540;
        !           454:                     y /= GetDeviceCaps(hDCDrawSurf, LOGPIXELSY);
        !           455:                     lpmfp->yExt = y;                                // ie. in 0.01mm
        !           456: 
        !           457:                     lpmfp->hMF = CopyMetaFile(ghmf, NULL);
        !           458: 
        !           459:                     GlobalUnlock(hmem);
        !           460:                     SetWindowText(ghTextWnd, "Copying 3X Metafile to Clipboard");
        !           461:                     SetClipboardData(CF_METAFILEPICT, hmem);
        !           462: 
        !           463: COPY_3X_EXIT:
        !           464:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
        !           465:                     goto COPY_EXIT;
        !           466: 
1.1.1.2   root      467:                 }
                    468: 
1.1.1.3 ! root      469:                 //
        !           470:                 // gbExport3X == FALSE
        !           471:                 //
        !           472:                 if (ghMetaf == 0)           // requires conversion
        !           473:                 {
        !           474:                     UINT            uiSize;
        !           475:                     LPVOID          pvData;
        !           476:                     HDC             hDCDrawSurf;
        !           477: 
        !           478:                     SetWindowText(ghTextWnd, "Converting 3X Metafile to Enhanced Metafile format");
        !           479:                     if (!(uiSize = GetMetaFileBitsEx(ghmf, 0, NULL))) {
        !           480:                         MessageBox(ghwndMain, "Fail in 1st GetMetaFileBitsEx!", "Error", MB_OK);
        !           481:                         SetWindowText(ghTextWnd, "Conversion Failed");
        !           482:                         goto COPY_EXIT;
        !           483:                     }
        !           484: 
        !           485:                     if ((pvData = (LPVOID) LocalAlloc(LMEM_FIXED, uiSize)) == NULL) {
        !           486:                         MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
        !           487:                         SetWindowText(ghTextWnd, "Conversion Failed");
        !           488:                         goto COPY_EXIT;
        !           489:                     }
        !           490: 
        !           491:                     if (!(uiSize = GetMetaFileBitsEx(ghmf, uiSize, pvData))) {
        !           492:                         MessageBox(ghwndMain, "Fail in 2nd GetMetaFileBitsEx!", "Error", MB_OK);
        !           493:                         goto COPY_ENH_EXIT;
        !           494:                     }
        !           495: 
        !           496:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
        !           497: 
        !           498:                     // !!! provide the correct picture extents in the METAFILEPICT structure
        !           499:                     // where possible
        !           500:                     ghMetaf = SetWinMetaFileBits(uiSize, (LPBYTE)pvData, hDCDrawSurf, NULL);
        !           501: 
        !           502: COPY_ENH_EXIT:
        !           503:                     LocalFree(pvData);
        !           504:                     ReleaseDC(ghwndDrawSurf ,hDCDrawSurf);
        !           505: 
        !           506:                     if (ghMetaf == 0) {
        !           507:                         SetWindowText(ghTextWnd, "Conversion Failed");
        !           508:                         goto COPY_EXIT;
        !           509:                     }
        !           510: 
        !           511:                 }
        !           512: 
        !           513:                 //
        !           514:                 // No Conversion required
        !           515:                 //
        !           516:                 {
        !           517: 
        !           518:                     HENHMETAFILE hEmfTmp;
        !           519: 
        !           520:                     hEmfTmp = CopyEnhMetaFile(ghMetaf, NULL);
        !           521: 
        !           522:                     if (hEmfTmp) {
        !           523:                         SetWindowText(ghTextWnd, "Copying Enhanced Metafile to Clipboard");
        !           524:                         SetClipboardData(CF_ENHMETAFILE, hEmfTmp);
        !           525:                         DeleteEnhMetaFile(hEmfTmp);
        !           526:                     }
        !           527: 
        !           528:                 }
        !           529: 
        !           530: COPY_EXIT:
        !           531: 
1.1.1.2   root      532:                 CloseClipboard();
                    533:                 return 0L;
                    534:             }
                    535: 
                    536:             case MM_PASTE:  {
                    537:                 OpenClipboard(ghwndMain);
                    538: 
1.1.1.3 ! root      539:                 if (gbImport3X)
        !           540:                 {
        !           541:                     HANDLE      hmem;
        !           542:                     DWORD       dwXSugExt, dwYSugExt, dwMM;
        !           543:                     HDC         hDCDrawSurf;
        !           544:                     RECT        rc;
        !           545:                     INT         iSavedDC;
        !           546: 
        !           547: 
        !           548:                     hmem = GetClipboardData(CF_METAFILEPICT);
        !           549: 
        !           550:                     if (hmem)
        !           551:                     {
        !           552:                         LPMETAFILEPICT lpmfp;
        !           553: 
        !           554:                         SetWindowText(ghTextWnd, "Pasting 3X Metafile");
        !           555:                         lpmfp = (LPMETAFILEPICT)GlobalLock(hmem);
        !           556:                         ghmf  = lpmfp->hMF;
        !           557:                         dwMM  = lpmfp->mm;
        !           558:                         dwXSugExt = lpmfp->xExt;        // in 0.01 mm
        !           559:                         dwYSugExt = lpmfp->yExt;
        !           560:                         GlobalUnlock(hmem);
        !           561: 
        !           562:                         hDCDrawSurf = GetDC(ghwndDrawSurf);
        !           563: 
        !           564:                         iSavedDC = SaveDC(hDCDrawSurf);
        !           565: 
        !           566:                         GetClientRect(ghwndDrawSurf, &rc);
        !           567: 
        !           568:                         SetMapMode(hDCDrawSurf, dwMM);
        !           569:                         if ((dwXSugExt > 0 )&& (dwYSugExt > 0))
        !           570:                         {                               // suggested width & height of image
        !           571:                             DWORD x;
        !           572:                             DWORD y;
        !           573: 
        !           574:                             // no. of pixels in x and y
        !           575:                             x = dwXSugExt;
        !           576:                             x *= GetDeviceCaps(hDCDrawSurf,LOGPIXELSX);
        !           577:                             x /= 2540;
        !           578: 
        !           579:                             y = dwYSugExt;
        !           580:                             y *= GetDeviceCaps(hDCDrawSurf,LOGPIXELSY);
        !           581:                             y /= 2540;
        !           582: 
        !           583:                             SetWindowExtEx(hDCDrawSurf, x, y, NULL);
        !           584: 
        !           585:                             if (gbFit2Wnd)
        !           586:                                 SetViewportExtEx(hDCDrawSurf, rc.right, rc.bottom, NULL);
        !           587:                             else
        !           588:                                 SetViewportExtEx(hDCDrawSurf, x, y, NULL);
        !           589: 
        !           590:                         } else {
        !           591:                             SetWindowText(ghTextWnd, "No information on 3X Metafile's extensions");
        !           592:                             SetWindowExtEx(hDCDrawSurf, rc.right, rc.bottom, NULL);
        !           593:                             SetViewportExtEx(hDCDrawSurf, rc.right, rc.bottom, NULL);
        !           594:                         }
        !           595: 
        !           596:                         SetViewportOrgEx(hDCDrawSurf, 0, 0, NULL);
        !           597:                         SetWindowOrgEx(hDCDrawSurf, 0, 0, NULL);
        !           598: 
        !           599:                         SetBoundsRect(hDCDrawSurf, NULL, DCB_ENABLE | DCB_SET);
        !           600:                         PlayMetaFile(hDCDrawSurf, ghmf);
        !           601:                         {
        !           602:                         UINT    uiRC;
        !           603:                         char    text[128];
        !           604: 
        !           605:                         wsprintf(text, "dwMM = %d\n", dwMM);
        !           606:                         OutputDebugString(text);
        !           607:                         wsprintf(text, "dwXSugExt = %d\n", dwXSugExt);
        !           608:                         OutputDebugString(text);
        !           609:                         wsprintf(text, "dwYSugExt = %d\n", dwYSugExt);
        !           610:                         OutputDebugString(text);
        !           611: 
        !           612:                         uiRC = GetBoundsRect(hDCDrawSurf, &rc, DCB_RESET); // in logical coordinates
        !           613:                         wsprintf(text, "GetBoundsRect = %d\n", uiRC);
        !           614:                         OutputDebugString(text);
        !           615:                         wsprintf(text, "left     = %d\n", rc.left);
        !           616:                         OutputDebugString(text);
        !           617:                         wsprintf(text, "right    = %d\n", rc.right);
        !           618:                         OutputDebugString(text);
        !           619:                         wsprintf(text, "top      = %d\n", rc.top);
        !           620:                         OutputDebugString(text);
        !           621:                         wsprintf(text, "bottom   = %d\n", rc.bottom);
        !           622:                         OutputDebugString(text);
        !           623:                         }
        !           624: 
        !           625: // !!!
        !           626: // saving the wmf as an Aldus mf
        !           627: //
        !           628: {
        !           629: OPENFILENAME    ofn;
        !           630: char            szFile[256], szFileTitle[256];
        !           631: static char     *szFilter;
        !           632: UINT            uiSize;
        !           633: HANDLE          hFile, hMapFile;
        !           634: LPVOID          pMapFile;
        !           635: DWORD           dwHigh, dwLow;
        !           636: 
        !           637: szFilter =
        !           638:   "EnhMeta files Windows Metafiles (*.wmf)\0*.wmf\0\0";
        !           639: 
        !           640: strcpy(szFile, "*.wmf\0");
        !           641: ofn.lStructSize = sizeof(OPENFILENAME);
        !           642: ofn.hwndOwner = hwnd;
        !           643: ofn.lpstrFilter = szFilter;
        !           644: ofn.lpstrCustomFilter = (LPSTR) NULL;
        !           645: ofn.nMaxCustFilter = 0L;
        !           646: ofn.nFilterIndex = 1;
        !           647: ofn.lpstrFile = szFile;
        !           648: ofn.nMaxFile = sizeof(szFile);
        !           649: ofn.lpstrFileTitle = szFileTitle;
        !           650: ofn.nMaxFileTitle = sizeof(szFileTitle);
        !           651: ofn.lpstrInitialDir = NULL;
        !           652: ofn.lpstrTitle = "Save Metafile";
        !           653: ofn.Flags = 0L;
        !           654: ofn.nFileOffset = 0;
        !           655: ofn.nFileExtension = 0;
        !           656: ofn.lpstrDefExt = "WMF";
        !           657: 
        !           658: if (!GetOpenFileName(&ofn))
        !           659:     return 0L;
        !           660: 
        !           661: uiSize = GetMetaFileBitsEx(ghmf, 0, NULL);
        !           662: dwHigh = 0;
        !           663: dwLow  = uiSize;
        !           664: 
        !           665: if ((hFile = CreateFile(szFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
        !           666:         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == (HANDLE)-1) {
        !           667:     MessageBox(ghwndMain, "Fail in file open!", "Error", MB_OK);
        !           668:     return 0L;
        !           669: }
        !           670: 
        !           671: //
        !           672: // Create a map file of the opened file
        !           673: //
        !           674: if ((hMapFile = CreateFileMapping(hFile, NULL,
        !           675:                          PAGE_READWRITE, dwHigh, dwLow, "MapF")) == NULL) {
        !           676:     MessageBox(ghwndMain, "Fail in creating map file!", "Error", MB_OK);
        !           677:     goto ErrorExit1;
        !           678: }
        !           679: 
        !           680: //
        !           681: // Map a view of the whole file
        !           682: //
        !           683: if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, uiSize)) == NULL) {
        !           684:     MessageBox(ghwndMain, "Fail in mapping view of the Map File object!", "Error", MB_OK);
        !           685:     goto ErrorExit2;
        !           686: }
        !           687: 
        !           688: if (uiSize) {
        !           689:     APMFILEHEADER   AldHdr;
        !           690:     PAPMFILEHEADER  pAldHdr;
        !           691:     PBYTE           pjTmp;
        !           692:     INT             iSize;
        !           693:     char            text[128];
        !           694: 
        !           695:     AldHdr.key = ALDUS_ID;
        !           696:     AldHdr.hmf = 0;                                 // Unused; must be zero
        !           697:     AldHdr.bbox.Left   = 0;                         // in metafile units
        !           698:     AldHdr.bbox.Top    = 0;
        !           699:     //AldHdr.bbox.Right  = rc.right - rc.left;        // in logical coordinates
        !           700:     //AldHdr.bbox.Bottom = rc.bottom - rc.top;
        !           701: 
        !           702:     switch (dwMM) {
        !           703:         case MM_HIENGLISH:
        !           704:             AldHdr.inch = 1000;
        !           705:             AldHdr.bbox.Right  = (SHORT)dwXSugExt;
        !           706:             AldHdr.bbox.Bottom = (SHORT)dwYSugExt;
        !           707:             break;
        !           708:         case MM_HIMETRIC:
        !           709:             AldHdr.inch = 1440;
        !           710:             AldHdr.bbox.Right  = (SHORT)(dwXSugExt / 2540 * 1440);
        !           711:             AldHdr.bbox.Bottom = (SHORT)(dwYSugExt / 2540 * 1440);
        !           712:             break;
        !           713:         case MM_LOENGLISH:
        !           714:             AldHdr.inch = 100;
        !           715:             AldHdr.bbox.Right  = (SHORT)dwXSugExt;
        !           716:             AldHdr.bbox.Bottom = (SHORT)dwYSugExt;
        !           717:             break;
        !           718:         case MM_LOMETRIC:
        !           719:             AldHdr.inch = 254;
        !           720:             AldHdr.bbox.Right  = (SHORT)dwXSugExt;
        !           721:             AldHdr.bbox.Bottom = (SHORT)dwYSugExt;
        !           722:             break;
        !           723:         case MM_TEXT:
        !           724:             AldHdr.inch = (WORD) (GetDeviceCaps(hDCDrawSurf, HORZRES) * 25.4 /
        !           725:                           GetDeviceCaps(hDCDrawSurf, HORZSIZE));
        !           726:             AldHdr.bbox.Right  = (SHORT)dwXSugExt;
        !           727:             AldHdr.bbox.Bottom = (SHORT)dwYSugExt;
        !           728:             break;
        !           729:         case MM_TWIPS:
        !           730:             AldHdr.inch = 1440;
        !           731:             AldHdr.bbox.Right  = (SHORT)dwXSugExt;
        !           732:             AldHdr.bbox.Bottom = (SHORT)dwYSugExt;
        !           733:             break;
        !           734:         default:
        !           735:             AldHdr.inch = 1440;
        !           736:             AldHdr.bbox.Right  = (SHORT)(dwXSugExt / 2540 * 1440);
        !           737:             AldHdr.bbox.Bottom = (SHORT)(dwYSugExt / 2540 * 1440);
        !           738:             break;
        !           739:     }
        !           740: 
        !           741:     wsprintf(text, "MM           = %d\n", dwMM);
        !           742:     OutputDebugString(text);
        !           743:     wsprintf(text, "AldHdr.inch  = %d\n", AldHdr.inch);
        !           744:     OutputDebugString(text);
        !           745: 
        !           746:     AldHdr.reserved = 0;
        !           747:     AldHdr.checksum = 0;
        !           748:     {
        !           749:     WORD    *p;
        !           750: 
        !           751:     for (p = (WORD *)&AldHdr, AldHdr.checksum = 0;
        !           752:             p < (WORD *)&(AldHdr.checksum); ++p)
        !           753:         AldHdr.checksum ^= *p;
        !           754:     }
        !           755: 
        !           756:     pAldHdr = &AldHdr;
        !           757:     pjTmp = (PBYTE)pMapFile;
        !           758: 
        !           759:     iSize = 22;
        !           760: 
        !           761:     //!!! use memcpy...
        !           762:     while (iSize--) {
        !           763:         *(((PBYTE)pjTmp)++) = *(((PBYTE)pAldHdr)++);
        !           764:     }
        !           765: 
        !           766:     pMapFile = (PBYTE)pMapFile + 22;
        !           767:     GetMetaFileBitsEx(ghmf, uiSize, pMapFile);
        !           768: }
        !           769: 
        !           770: 
        !           771: UnmapViewOfFile(pMapFile);
        !           772: 
        !           773: ErrorExit2:
        !           774:   CloseHandle(hMapFile);
        !           775: ErrorExit1:
        !           776:   CloseHandle(hFile);
        !           777: }
        !           778: 
        !           779:                         RestoreDC(hDCDrawSurf, iSavedDC);
        !           780:                         ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
        !           781: 
        !           782:                     } else {
        !           783:                         SetWindowText(ghTextWnd, "Cannot get 3X metafile from clipboard!");
        !           784:                     }
        !           785: 
        !           786:                     goto PASTE_EXIT;
        !           787: 
1.1.1.2   root      788:                 }
                    789: 
1.1.1.3 ! root      790:                 //
        !           791:                 // gbImport3X == FALSE
        !           792:                 //
        !           793:                 {
        !           794:                     HENHMETAFILE hEmfTmp;
        !           795:                     ENHMETAHEADER EnhMetaHdr;
        !           796: 
        !           797:                     hEmfTmp = GetClipboardData(CF_ENHMETAFILE);
        !           798:                     if (hEmfTmp) {
        !           799:                         SetWindowText(ghTextWnd, "Pasting Enhanced Metafile");
        !           800:                         DeleteEnhMetaFile(ghMetaf);
        !           801:                         ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL);
        !           802:                         DeleteEnhMetaFile(hEmfTmp);
        !           803:                         GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
        !           804:                         SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE);
        !           805:                         bReset = TRUE;
        !           806:                     } else {
        !           807:                         SetWindowText(ghTextWnd, "Cannot get Enhanced metafile from clipboard!");
        !           808:                     }
        !           809:                 }
        !           810: PASTE_EXIT:
        !           811: 
1.1.1.2   root      812:                 CloseClipboard();
                    813:                 EnableMenuItem(hMenu, MM_COPY,  MF_ENABLED);
                    814:                 return 0L;
                    815:             }
                    816: 
                    817:             case MM_DEL:    {
                    818:                 OpenClipboard(ghwndMain);
                    819:                 EmptyClipboard();
                    820:                 CloseClipboard();
                    821:                 return 0L;
                    822:             }
                    823: 
1.1       root      824:             case MM_PEN: {
                    825:                 HDC     hDC;
                    826:                 DWORD   dwRGB;
                    827: 
                    828:                 if (bChooseNewColor(hwnd, &dwRGB)) {
                    829:                     hDC = GetDC(ghwndDrawSurf);
                    830:                     if (ghpnCur != NULL)
                    831:                         DeleteObject(ghpnCur);
                    832:                     ghpnCur = CreatePen(PS_SOLID, 1, dwRGB);
                    833:                     SelectObject(hDC, ghpnCur);
                    834:                     if (ghDCMetaf != NULL)
                    835:                         SelectObject(ghDCMetaf, ghpnCur);
                    836:                     ReleaseDC(ghwndDrawSurf, hDC);
                    837:                 }
                    838:                 return 0L;
                    839:             }
                    840:             case MM_BRUSH: {
                    841:                 HDC     hDC;
                    842:                 static DWORD   dwRGB=RGB(255, 255, 255);
                    843: 
                    844:                 if (bChooseNewColor(hwnd, &dwRGB)) {
                    845:                     hDC = GetDC(ghwndDrawSurf);
                    846:                     if (ghbrCur != NULL)
                    847:                         DeleteObject(ghbrCur);
                    848:                     ghbrCur = hBrCreateBrush(hDC, dwRGB);
                    849:                     SelectObject(hDC, ghbrCur);
                    850:                     if (ghDCMetaf != NULL)
                    851:                         SelectObject(ghDCMetaf, ghbrCur);
                    852:                     ReleaseDC(ghwndDrawSurf, hDC);
                    853:                 }
                    854:                 return 0L;
                    855:             }
                    856:             case MM_FONT: {
1.1.1.3 ! root      857:                 HDC     hDC;
        !           858:                 char    text[128];
        !           859: 
1.1       root      860:                 if (bChooseNewFont(ghwndMain, &glf, &gCrText)) {
                    861:                     ghCurFont = CreateFontIndirect(&glf);
1.1.1.3 ! root      862: 
        !           863:                     hDC = GetDC(ghwndDrawSurf);
        !           864:                     EnumFonts(hDC, glf.lfFaceName, (FONTENUMPROC)iTT, (LPARAM)&gbTT);
        !           865:                     wsprintf(text, "gbTT = %d\n", gbTT);
        !           866:                     //OutputDebugString(text);
        !           867:                     ReleaseDC(ghwndDrawSurf, hDC);
        !           868: 
1.1       root      869:                     if (ghDCMetaf != NULL)
                    870:                         SelectObject(ghDCMetaf, ghCurFont);
                    871:                 }
                    872:                 return 0L;
                    873:             }
                    874: 
1.1.1.3 ! root      875:             case MM_TTOUTLN_STROKEFILL: {
        !           876:                 gbSFOutln = (gbSFOutln ? FALSE : TRUE);
        !           877:                 if (gbSFOutln) {
        !           878:                     CheckMenuItem(hMenu, MM_TTOUTLN_STROKEFILL, MF_CHECKED);
        !           879:                     CheckMenuItem(hMenu, MM_TTOUTLN_POLYDRAW, MF_UNCHECKED);
        !           880:                     gbPDOutln = FALSE;
        !           881:                 }
        !           882:                 return 0L;
        !           883:             }
        !           884: 
        !           885:             case MM_TTOUTLN_POLYDRAW: {
        !           886:                 gbPDOutln = (gbPDOutln ? FALSE : TRUE);
        !           887:                 if (gbPDOutln) {
        !           888:                     CheckMenuItem(hMenu, MM_TTOUTLN_STROKEFILL, MF_UNCHECKED);
        !           889:                     CheckMenuItem(hMenu, MM_TTOUTLN_POLYDRAW, MF_CHECKED);
        !           890:                     gbSFOutln = FALSE;
        !           891:                 }
        !           892:                 return 0L;
        !           893:             }
        !           894: 
1.1       root      895:             case MM_HITTEST: {
                    896:                 static BOOL bHitTest=FALSE;
                    897:                 HWND        hwndRecBtn;
                    898: 
                    899:                 bHitTest = (bHitTest ? FALSE : TRUE);
                    900:                 hwndRecBtn = GetDlgItem(ghwndCtrlPanel, DID_RECORD);
                    901:                 if (bHitTest) {
                    902:                     CheckMenuItem(hMenu, MM_HITTEST, MF_CHECKED);
                    903:                     EnableMenuItem(hMenu, MM_RECORD, MF_GRAYED);
                    904:                     EnableWindow(hwndRecBtn, FALSE);
                    905:                     gbHitTest = TRUE;
                    906:                 } else {
                    907:                     CheckMenuItem(hMenu, MM_HITTEST, MF_UNCHECKED);
                    908:                     EnableMenuItem(hMenu, MM_RECORD, MF_ENABLED);
                    909:                     EnableWindow(hwndRecBtn, TRUE);
                    910:                     gbHitTest = FALSE;
                    911:                     return 0L;
                    912:                 }
                    913: 
                    914:                 if (ghMetaf == 0) {
                    915:                     SetWindowText(ghTextWnd, "No Metafile loaded for hit-testing");
                    916:                     return 0L;
                    917:                 }
                    918:                 return 0L;
                    919:             }
1.1.1.2   root      920: 
                    921:            case MM_LEABOUT:
1.1       root      922:                if (DialogBox(ghModule, (LPCSTR)"AboutBox", ghwndMain, (DLGPROC)About) == -1)
                    923:                        MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
1.1.1.2   root      924:                 return 0L;
                    925: 
                    926:            case MM_ABOUT:
1.1.1.3 ! root      927:                if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
        !           928:                   MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
1.1       root      929:                return 0L;
                    930: 
                    931:             case MM_LOAD_MASKBMP:
                    932:                 SetWindowText(ghTextWnd, "Load Mask Bitmap");
                    933:                 bGetBMP(hwnd, TRUE);
                    934:                 return 0L;
                    935: 
                    936:             case MM_LOAD_BMP:
                    937:                 SetWindowText(ghTextWnd, "Load Bitmap");
                    938:                 bGetBMP(hwnd, FALSE);
                    939:                 return 0L;
                    940: 
                    941:             case MM_SAVE_BMP:
                    942:                 SetWindowText(ghTextWnd, "Save Drawing Surface as Bitmap");
                    943:                 return 0L;
                    944: 
                    945:             case MM_LOAD:
                    946:            case DID_OPEN: {
                    947:                 ENHMETAHEADER EnhMetaHdr;
1.1.1.2   root      948:                 HENHMETAFILE  hEmfTmp;
1.1       root      949: 
                    950:                 SetWindowText(ghTextWnd, "Load Metafile");
1.1.1.2   root      951:                 //
                    952:                 // If user hit cancel, we still have the original metafile
                    953:                 //
                    954:                 //DeleteEnhMetaFile(ghMetaf);
                    955:                 //ghMetaf = hemfLoadMetafile(hwnd);
                    956:                 hEmfTmp = hemfLoadMetafile(hwnd);
                    957:                 if (hEmfTmp != 0) {
1.1.1.3 ! root      958:                     char     szDesc[256];
        !           959: 
1.1.1.2   root      960:                     DeleteEnhMetaFile(ghMetaf);
                    961:                     ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL);
1.1       root      962:                     GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                    963:                     SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE);
1.1.1.2   root      964:                     DeleteEnhMetaFile(hEmfTmp);
                    965:                     EnableMenuItem(hMenu, MM_COPY,  MF_ENABLED);
1.1.1.3 ! root      966:                     if (GetEnhMetaFileDescription(ghMetaf, 256, szDesc) != 0) {
        !           967:                         char    szText[256];
        !           968:                         char    *szTmp, szSource[256];
        !           969: 
        !           970:                         szTmp = (char *)strtok(szDesc, "\\0");
        !           971:                         strcpy(szSource, szTmp);
        !           972:                         szTmp = (char *)strtok(NULL, "\\0\\0");
        !           973:                         wsprintf(szText, "Source: %s  Title: %s", szSource, szTmp);
        !           974:                         SetWindowText(ghTextWnd, szText);
        !           975:                         strcpy(szLoadedMetaf, szTmp);
        !           976:                     } else {
        !           977:                         strcpy(szLoadedMetaf, "");
        !           978:                     }
1.1.1.2   root      979:                 //} else {
                    980:                 //    SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE);
1.1       root      981:                 }
                    982:                 bReset = TRUE;
                    983:                 return 0L;
                    984:             }
                    985:             case MM_RECORD:
                    986:                 if (gbHitTest) {
                    987:                     SetWindowText(ghTextWnd, "Please CANCEL Hit Testing Mode First!");
                    988:                     return 0L;
                    989:                 }
                    990: 
                    991:                 SetWindowText(ghTextWnd, "Recording...");
                    992:                 if (!gbRecording) {
                    993:                     ghDCMetaf = hDCRecordMetafileAs(hwnd, szFilename);
                    994:                 }
                    995: 
                    996:                 if (ghDCMetaf == NULL) {
                    997:                    SetWindowText(ghTextWnd, "ERROR: Failed in creating the metafile DC!");
                    998:                    return 0L;
                    999:                 }
1.1.1.3 ! root     1000: 
        !          1001:                 // Parse the szFilename for the title and GdiComment the metafile with it.
        !          1002:                 {
        !          1003:                     char    szComment[256];
        !          1004:                     char    *szTmp, szTmp2[256];
        !          1005: 
        !          1006:                     szTmp = (char *)strtok(szFilename, "\\");
        !          1007:                     strcpy(szTmp2, szTmp);
        !          1008:                     while (szTmp != NULL) {
        !          1009:                         szTmp = (char *)strtok(NULL, "\\");
        !          1010:                         if (szTmp != NULL) {
        !          1011:                             strcpy(szTmp2, szTmp);
        !          1012:                         }
        !          1013:                     }
        !          1014:                     szTmp = (char *)strtok(szTmp2, ".");
        !          1015:                     wsprintf((LPSTR) szComment, "MfEdit:\\0%s\\0\\0", szTmp);
        !          1016:                     if (!GdiComment(ghDCMetaf, 256, szComment)) {
        !          1017:                         MessageBox(ghwndMain, "Fail in adding comment!", "Error", MB_OK);
        !          1018:                     }
        !          1019:                 }
        !          1020: 
1.1       root     1021:                 gbRecording = TRUE;
                   1022: 
                   1023:                 if (ghpnCur != NULL)
                   1024:                     SelectObject(ghDCMetaf, ghpnCur);
                   1025: 
                   1026:                 if (ghbrCur != NULL)
                   1027:                     SelectObject(ghDCMetaf, ghbrCur);
                   1028: 
                   1029:                 if (ghCurFont != NULL)
                   1030:                     SelectObject(ghDCMetaf, ghCurFont);
                   1031:                 return 0L;
                   1032: 
                   1033:            case DID_RECORD: {
1.1.1.3 ! root     1034:                 int  iWidthMM, iHeightMM, iWidthPels, iHeightPels, iMMPerPelX, iMMPerPelY;
        !          1035:                 char szComment[256];
        !          1036:                 char szTitle[256];
        !          1037:                 RECT rc;
        !          1038:                 HDC  hDC;
        !          1039: 
1.1       root     1040: 
                   1041:                 if (gbHitTest) {
                   1042:                     SetWindowText(ghTextWnd, "Please CANCEL Hit Testing Mode First!");
                   1043:                     return 0L;
                   1044:                 }
                   1045: 
                   1046:                 SetWindowText(ghTextWnd, "Recording...");
                   1047:                 if (!gbRecording) {
1.1.1.3 ! root     1048: 
        !          1049:                     hDC = GetDC(hwnd);
        !          1050:                     iWidthMM    = GetDeviceCaps(hDC, HORZSIZE);
        !          1051:                     iHeightMM   = GetDeviceCaps(hDC, VERTSIZE);
        !          1052:                     iWidthPels  = GetDeviceCaps(hDC, HORZRES);
        !          1053:                     iHeightPels = GetDeviceCaps(hDC, VERTRES);
        !          1054:                     ReleaseDC(hwnd, hDC);
        !          1055:                     iMMPerPelX  = (iWidthMM * 100)/iWidthPels;
        !          1056:                     iMMPerPelY  = (iHeightMM * 100)/iHeightPels;
        !          1057:                     GetClientRect(ghwndDrawSurf, &rc);
        !          1058:                     rc.left   = rc.left * iMMPerPelX;
        !          1059:                     rc.top    = rc.top * iMMPerPelY;
        !          1060:                     rc.right  = rc.right * iMMPerPelX;
        !          1061:                     rc.bottom = rc.bottom * iMMPerPelY;
        !          1062: 
        !          1063:                     {
        !          1064:                        char szFilenameWithExt[256];
        !          1065:                        char suffix[20];
        !          1066:                        char szDesc[256];
        !          1067:                        char *szTmp, szTmp2[256];
        !          1068: 
        !          1069:                        //
        !          1070:                        // assemble a new metafile name with the emf extension from
        !          1071:                        // the generic szFilename
        !          1072:                        //
        !          1073:                        wsprintf((LPSTR) suffix, "%d.emf", iMetafCnt);
        !          1074:                        iMetafCnt++;
        !          1075:                        strcpy(szFilenameWithExt, szFilename);
        !          1076:                        strcat(szFilenameWithExt, suffix);
        !          1077: 
        !          1078:                        //
        !          1079:                        // parse szFilename for the title for description
        !          1080:                        //
        !          1081:                        szTmp = (char *)strtok(szFilename, "\\");
        !          1082:                        strcpy(szTmp2, szTmp);
        !          1083:                        while (szTmp != NULL) {
        !          1084:                            szTmp = (char *)strtok(NULL, "\\");
        !          1085:                            if (szTmp != NULL) {
        !          1086:                                strcpy(szTmp2, szTmp);
        !          1087:                            }
        !          1088:                        }
        !          1089:                        szTmp = (char *)strtok(szTmp2, ".");
        !          1090:                        strcpy(szTitle, szTmp);
        !          1091:                        wsprintf(szDesc, "SDK Enhanced Metafile Editor\\0%s\\0\\0", szTitle);
        !          1092:                        ghDCMetaf = CreateEnhMetaFile((HDC)NULL, szFilenameWithExt, (LPRECT)&rc, (LPSTR)szDesc);
        !          1093:                     }
        !          1094: 
        !          1095:                     if ((SetGraphicsMode(ghDCMetaf, GM_ADVANCED)) == 0) {
        !          1096:                        MessageBox(ghwndMain, "Fail in setting Advanced Graphics Mode!", "Error", MB_OK);
        !          1097:                     }
1.1       root     1098:                 }
                   1099: 
                   1100:                 if (ghDCMetaf == NULL) {
                   1101:                    SetWindowText(ghTextWnd, "ERROR: Failed in creating the metafile DC!");
                   1102:                    return 0L;
                   1103:                 }
1.1.1.3 ! root     1104: 
        !          1105:                 wsprintf((LPSTR) szComment, "MfEdit:\\0%s\\0\\0", szTitle);
        !          1106:                 if (!GdiComment(ghDCMetaf, 256, szComment)) {
        !          1107:                     MessageBox(ghwndMain, "Fail in adding comment!", "Error", MB_OK);
        !          1108:                 }
        !          1109: 
1.1       root     1110:                 gbRecording = TRUE;
                   1111: 
                   1112:                 if (ghpnCur != NULL)
                   1113:                     SelectObject(ghDCMetaf, ghpnCur);
                   1114: 
                   1115:                 if (ghbrCur != NULL)
                   1116:                     SelectObject(ghDCMetaf, ghbrCur);
                   1117: 
                   1118:                 if (ghCurFont != NULL)
                   1119:                     SelectObject(ghDCMetaf, ghCurFont);
                   1120: 
                   1121:                 return 0L;
                   1122:             }
                   1123:            case DID_STOP:
                   1124:                 SetWindowText(ghTextWnd, "Stop");
                   1125:                 if (gbRecording) {
                   1126:                     ghMetaf = CloseEnhMetaFile(ghDCMetaf);
                   1127:                     gbRecording = FALSE;
                   1128:                 }
                   1129:                 return 0L;
1.1.1.2   root     1130: 
1.1       root     1131:            case DID_PLAY: {
                   1132:                 HDC hDCDrawSurf;
                   1133:                 ENHMETAHEADER EnhMetaHdr;
1.1.1.3 ! root     1134:                 RECT          rcClientDS;
        !          1135:                 int           iEntries;
        !          1136:                 PLOGPALETTE     plogPal;
        !          1137:                 PBYTE           pjTmp;
        !          1138:                 HPALETTE        hPal;
        !          1139:                 char            szTmp[256];
1.1       root     1140: 
1.1.1.3 ! root     1141:                 wsprintf(szTmp, "Playing Metafile: %s", szLoadedMetaf);
        !          1142:                 SetWindowText(ghTextWnd, szTmp);
1.1       root     1143:                 if (ghMetaf != NULL) {
                   1144:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
                   1145:                     GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                   1146: 
1.1.1.3 ! root     1147:                     iEntries = GetEnhMetaFilePaletteEntries(ghMetaf, 0, NULL);
        !          1148: 
        !          1149:                     if (iEntries) {
        !          1150:                         if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          1151:                                 sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) {
        !          1152:                             MessageBox(ghwndMain, "Failed in Creating Palette!", "Error", MB_OK);
        !          1153:                         }
        !          1154: 
        !          1155:                         plogPal->palVersion = 0x300;
        !          1156:                         plogPal->palNumEntries = (WORD) iEntries;
        !          1157:                         pjTmp = (PBYTE) plogPal;
        !          1158:                         pjTmp += 8;
        !          1159: 
        !          1160:                         GetEnhMetaFilePaletteEntries(ghMetaf, iEntries, (PPALETTEENTRY)pjTmp);
        !          1161:                         hPal = CreatePalette(plogPal);
        !          1162:                         GlobalFree(plogPal);
        !          1163: 
        !          1164:                         SelectPalette(hDCDrawSurf, hPal, FALSE);
        !          1165:                         RealizePalette(hDCDrawSurf);
        !          1166:                     }
        !          1167: 
        !          1168: 
        !          1169:                     if (gbFit2Wnd) {
        !          1170:                         GetClientRect(ghwndDrawSurf, &rcClientDS);
        !          1171:                         if (!PlayEnhMetaFile( hDCDrawSurf, ghMetaf, (LPRECT) &rcClientDS)) {
        !          1172:                             char    text[128];
        !          1173: 
        !          1174:                             wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          1175:                             OutputDebugString(text);
        !          1176:                         }
        !          1177:                     } else {
        !          1178:                         RECT rc;
        !          1179: 
        !          1180:                         rc.top = rc.left = 0;
        !          1181:                         rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          1182:                         rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          1183:                         if (!PlayEnhMetaFile( hDCDrawSurf, ghMetaf, (LPRECT) &rc)) {
        !          1184:                             char    text[128];
        !          1185: 
        !          1186:                             wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          1187:                             OutputDebugString(text);
        !          1188:                         }
        !          1189: 
        !          1190:                     }
1.1       root     1191:                     //
                   1192:                     // Enabling the user to embed another metafile
                   1193:                     //
1.1.1.2   root     1194:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
1.1.1.3 ! root     1195:                         if (hPal != (HPALETTE)NULL) {
        !          1196:                             SelectPalette(ghDCMetaf, hPal, FALSE);
        !          1197:                             RealizePalette(ghDCMetaf);
        !          1198:                         }
        !          1199:                         {
        !          1200:                         RECT rc;
        !          1201: 
        !          1202:                         rc.top = rc.left = 0;
        !          1203:                         rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          1204:                         rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          1205:                         if (!PlayEnhMetaFile( ghDCMetaf, ghMetaf, (LPRECT) &rc)) {
        !          1206:                             char    text[128];
        !          1207: 
        !          1208:                             wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          1209:                             OutputDebugString(text);
        !          1210:                         }
        !          1211: 
        !          1212:                         }
1.1.1.2   root     1213:                     }
1.1       root     1214: 
                   1215:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
1.1.1.2   root     1216:                 } else {
                   1217:                     SetWindowText(ghTextWnd, "No Metafile for Playing");
1.1       root     1218:                 }
1.1.1.2   root     1219: 
1.1       root     1220:                 return 0L;
                   1221:             }
                   1222:            case DID_FF: {
                   1223:                 HDC           hDCDrawSurf;
                   1224:                 ENHMETAHEADER EnhMetaHdr;
1.1.1.3 ! root     1225:                 RECT          rcClientDS;
1.1       root     1226:                 static int    iRecord = 0;
                   1227:                 PLAYINFO      PlayInfo;
1.1.1.3 ! root     1228:                 int           iEntries;
        !          1229:                 PLOGPALETTE     plogPal;
        !          1230:                 PBYTE           pjTmp;
        !          1231:                 HPALETTE        hPal;
        !          1232: 
1.1       root     1233: 
                   1234:                 if (ghMetaf == 0)
                   1235:                     return 0L;
                   1236: 
                   1237:                 PlayInfo.iRecord = ++iRecord;
                   1238:                 PlayInfo.bPlayContinuous = TRUE;
                   1239: 
                   1240:                 GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                   1241:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iRecord, FALSE);
                   1242:                 if ((EnhMetaHdr.nRecords > 1) && (iRecord <= (INT)EnhMetaHdr.nRecords)) {
                   1243:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
                   1244: 
1.1.1.3 ! root     1245:                     iEntries = GetEnhMetaFilePaletteEntries(ghMetaf, 0, NULL);
        !          1246: 
        !          1247:                     if (iEntries) {
        !          1248:                         if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          1249:                                 sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) {
        !          1250:                             MessageBox(ghwndMain, "Failed in Creating Palette!", "Error", MB_OK);
        !          1251:                         }
        !          1252: 
        !          1253:                         plogPal->palVersion = 0x300;
        !          1254:                         plogPal->palNumEntries = (WORD) iEntries;
        !          1255:                         pjTmp = (PBYTE) plogPal;
        !          1256:                         pjTmp += 8;
        !          1257: 
        !          1258:                         GetEnhMetaFilePaletteEntries(ghMetaf, iEntries, (PPALETTEENTRY)pjTmp);
        !          1259:                         hPal = CreatePalette(plogPal);
        !          1260:                         GlobalFree(plogPal);
        !          1261: 
        !          1262:                         SelectPalette(hDCDrawSurf, hPal, FALSE);
        !          1263:                         RealizePalette(hDCDrawSurf);
        !          1264:                     }
        !          1265: 
        !          1266:                     if (gbFit2Wnd) {
        !          1267:                         GetClientRect(ghwndDrawSurf, &rcClientDS);
        !          1268:                         EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &rcClientDS);
        !          1269:                     } else {
        !          1270:                         EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &EnhMetaHdr.rclBounds);
        !          1271:                     }
1.1       root     1272:                     //
                   1273:                     // Enabling the user to record a metafile records selectively
                   1274:                     //
1.1.1.2   root     1275:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
1.1.1.3 ! root     1276:                         SelectPalette(ghDCMetaf, hPal, FALSE);
        !          1277:                         RealizePalette(ghDCMetaf);
1.1.1.2   root     1278:                         EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
                   1279:                     }
1.1       root     1280: 
                   1281:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                   1282:                 }
                   1283: 
                   1284:                 if ((iRecord == (INT) EnhMetaHdr.nRecords) || bReset) {
                   1285:                     iRecord = 0;
                   1286:                     if (bReset)
                   1287:                         SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE);
                   1288:                     bReset = FALSE;
                   1289:                 }
                   1290:                 return 0L;
                   1291:             }
                   1292:            case DID_CLEAR: {
                   1293:                 HDC     hDCDrawSurf;
                   1294:                 HGDIOBJ hObjOld;
                   1295:                 RECT    rcDrawSurf;
                   1296: 
                   1297:                 SetWindowText(ghTextWnd, "Drawing Surface cleared");
                   1298:                 hDCDrawSurf = GetDC(ghwndDrawSurf);
                   1299:                 ghbrAppBkgd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
                   1300:                 hObjOld = SelectObject(hDCDrawSurf, ghbrAppBkgd);
                   1301:                 GetClientRect(ghwndDrawSurf, &rcDrawSurf);
                   1302:                 PatBlt(hDCDrawSurf, 0, 0, rcDrawSurf.right, rcDrawSurf.bottom, PATCOPY);
                   1303:                 ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                   1304:                 SelectObject(hDCDrawSurf, hObjOld);
                   1305:                 return 0L;
                   1306:             }
                   1307: 
                   1308:             case DID_PEN:
                   1309:                 SetWindowText(ghTextWnd, "Pen");
                   1310:                 return 0L;
                   1311:             case DID_TEXT:
                   1312:                 SetWindowText(ghTextWnd, "Text");
                   1313:                 return 0L;
                   1314:             case DID_RECT:
                   1315:                 SetWindowText(ghTextWnd, "Rectangle");
                   1316:                 return 0L;
                   1317:             case DID_FILLRECT:
                   1318:                 SetWindowText(ghTextWnd, "Filled Rectangle");
                   1319:                 return 0L;
                   1320:             case DID_ELLIPSE:
                   1321:                 SetWindowText(ghTextWnd, "Ellipse");
                   1322:                 return 0L;
                   1323:             case DID_FILLELLIPSE:
                   1324:                 SetWindowText(ghTextWnd, "Filled Ellipse");
                   1325:                 return 0L;
                   1326:             case DID_LINE:
                   1327:                 SetWindowText(ghTextWnd, "Line");
                   1328:                 return 0L;
                   1329:             case DID_BEZIER:
                   1330:                 SetWindowText(ghTextWnd,
                   1331:                     "Bezier: Click with Left button for placing control points");
                   1332:                 return 0L;
                   1333:             case DID_BMPOBJ:
                   1334:                 SetWindowText(ghTextWnd,
                   1335:                     "Bitmap: Click three points for the destination of the bitmap");
                   1336:                 return 0L;
                   1337:             case DID_METAF:
                   1338:                 SetWindowText(ghTextWnd,
                   1339:                     "External Metafile: Click three points for the destination of the Metafile");
                   1340:                 return 0L;
1.1.1.3 ! root     1341:             case MM_IMPORT_3X:
        !          1342:                 gbImport3X = (gbImport3X ? FALSE : TRUE);
        !          1343: 
        !          1344:                 if (gbImport3X)
        !          1345:                     CheckMenuItem(hMenu, MM_IMPORT_3X, MF_CHECKED);
        !          1346:                 else
        !          1347:                     CheckMenuItem(hMenu, MM_IMPORT_3X, MF_UNCHECKED);
        !          1348:                 return 0L;
        !          1349: 
        !          1350:             case MM_EXPORT_3X:
        !          1351:                 gbExport3X = (gbExport3X ? FALSE : TRUE);
        !          1352: 
        !          1353:                 if (gbExport3X)
        !          1354:                     CheckMenuItem(hMenu, MM_EXPORT_3X, MF_CHECKED);
        !          1355:                 else
        !          1356:                     CheckMenuItem(hMenu, MM_EXPORT_3X, MF_UNCHECKED);
        !          1357:                 return 0L;
        !          1358:             case MM_FIT2WND:
        !          1359:                 gbFit2Wnd = (gbFit2Wnd ? FALSE : TRUE);
        !          1360: 
        !          1361:                 if (gbFit2Wnd)
        !          1362:                     CheckMenuItem(hMenu, MM_FIT2WND, MF_CHECKED);
        !          1363:                 else
        !          1364:                     CheckMenuItem(hMenu, MM_FIT2WND, MF_UNCHECKED);
        !          1365:                 return 0L;
        !          1366: 
        !          1367:             case MM_PRINT: {
        !          1368:                 DWORD   dwThrdID;
        !          1369:                 HANDLE  hThrd;
        !          1370:                 PPRTDATA pPrtData;
        !          1371: 
        !          1372:                 if (ghMetaf == 0) {
        !          1373:                     SetWindowText(ghTextWnd, "NO Metafile to print");
        !          1374:                     return 0L;
        !          1375:                 }
        !          1376: 
        !          1377:                 //
        !          1378:                 // bPrintMf is supposed to free up the memory when done.
        !          1379:                 //
        !          1380:                 if ((pPrtData = (PPRTDATA) GlobalAlloc(GPTR, sizeof(PRTDATA))) == NULL) {
        !          1381:                     SetWindowText(ghTextWnd, "Failed in allocating memory");
        !          1382:                     return 0L;
        !          1383:                 }
        !          1384: 
        !          1385:                 pPrtData->hMetaf = ghMetaf;
        !          1386:                 pPrtData->bFit2Wnd = gbFit2Wnd;
        !          1387: 
        !          1388:                 hThrd = CreateThread(NULL, 0,
        !          1389:                              (LPTHREAD_START_ROUTINE)bPrintMf,
        !          1390:                              pPrtData, STANDARD_RIGHTS_REQUIRED,
        !          1391:                              &dwThrdID);
        !          1392: 
        !          1393:                 //
        !          1394:                 // Free the memory if CreateThread fails...
        !          1395:                 //
        !          1396:                 if (hThrd == NULL) {
        !          1397:                     SetWindowText(ghTextWnd, "Failed in creating printing thread");
        !          1398:                     GlobalFree(pPrtData);
        !          1399:                 }
        !          1400: 
        !          1401:                 return 0L;
        !          1402: 
        !          1403:             }
        !          1404: 
1.1       root     1405:            default:
                   1406:                 return DefWindowProc(hwnd, message, wParam, lParam);
                   1407:         }
                   1408:       }     // WM_COMMAND
                   1409:       default:
                   1410:         return DefWindowProc(hwnd, message, wParam, lParam);
                   1411:     }
                   1412: }
                   1413: 
                   1414: /******************************Public*Routine******************************\
                   1415: *
                   1416: * DrawSurfWndProc
                   1417: *       Drawing surface window procedure
                   1418: *
                   1419: * Effects:  Trapping all mouse messages and call the DrawStuff appropriately
                   1420: *           for drawing to the drawing surface DC and metafile DC as needed.
                   1421: *
                   1422: * Warnings:
                   1423: *
                   1424: * History:
                   1425: *  30-Apr-1992 -by- Petrus Wong
                   1426: * Wrote it.
                   1427: \**************************************************************************/
                   1428: 
1.1.1.2   root     1429: long APIENTRY DrawSurfWndProc(
1.1       root     1430:     HWND hwnd,
                   1431:     UINT message,
                   1432:     DWORD wParam,
                   1433:     LONG lParam)
                   1434: {
                   1435:     static BOOL    bTrack = FALSE;
                   1436:     static int     OrgX, OrgY;
                   1437:     static int     PrevX, PrevY;
                   1438:     static HDC     hDC;
                   1439:     static HCURSOR hCurArrow, hCurHT;
                   1440: 
                   1441:     switch (message) {
                   1442:       case WM_CREATE:
                   1443:           {
                   1444:               RECT       rect;
                   1445: 
1.1.1.3 ! root     1446:               hDC = GetDC(hwnd);
        !          1447:               if ((SetGraphicsMode(hDC, GM_ADVANCED)) == 0) {
        !          1448:                  MessageBox(ghwndMain, "Fail in setting Advanced Graphics Mode!", "Error", MB_OK);
        !          1449:               }
        !          1450:               ReleaseDC(hwnd, hDC);
        !          1451: 
1.1       root     1452:               GetClientRect(GetParent(hwnd), &rect);
                   1453: 
                   1454:               SetWindowPos(hwnd, NULL,
                   1455:                       0,
                   1456:                       30,
                   1457:                       rect.right-rect.left,
                   1458:                       rect.bottom-rect.top-30,
                   1459:                       SWP_NOZORDER | SWP_NOMOVE);
                   1460: 
                   1461:               CreateCaret(hwnd, NULL, 1, 12);
                   1462:               ghCurFont = GetStockObject(SYSTEM_FONT);
                   1463:               GetObject(ghCurFont, sizeof(LOGFONT), &glf);
                   1464:               hCurArrow = LoadCursor(NULL, IDC_ARROW);
                   1465:               hCurHT = LoadCursor(NULL, IDC_CROSS);
                   1466:               break;
                   1467:           }
                   1468: 
                   1469:       case WM_LBUTTONDOWN: {
                   1470:         int    x, y;
                   1471: 
                   1472:         x = (int) LOWORD(lParam);
                   1473:         y = (int) HIWORD(lParam);
                   1474: 
                   1475:         if (gbHitTest) {
                   1476:             hDC = GetDC(hwnd);
                   1477:             bHitTest(hDC, x, y);
                   1478:             ReleaseDC(hwnd, hDC);
                   1479:             break;
                   1480:         }
                   1481: 
                   1482:         bTrack = TRUE;
                   1483:         OrgX = PrevX = x;
                   1484:         OrgY = PrevY = y;
                   1485: 
                   1486:         hDC = GetDC(hwnd);
                   1487:         SetCapture(hwnd);
                   1488:         break;
                   1489:       }
                   1490: 
                   1491:       case WM_MOUSEMOVE: {
                   1492:         RECT rectClient;
                   1493:         int NextX;
                   1494:         int NextY;
                   1495: 
                   1496:         if (gbHitTest) {
                   1497:             SetCursor(hCurHT);
                   1498:         } else {
                   1499:             SetCursor(hCurArrow);
                   1500:         }
                   1501: 
                   1502:         // Update the selection region
                   1503:         if (bTrack) {
                   1504:             NextX = (SHORT) LOWORD(lParam);
                   1505:             NextY = (SHORT) HIWORD(lParam);
                   1506: 
                   1507:             // Do not draw outside the window's client area
                   1508: 
                   1509:             GetClientRect (hwnd, &rectClient);
                   1510:             if (NextX < rectClient.left) {
                   1511:                 NextX = rectClient.left;
                   1512:             } else if (NextX >= rectClient.right) {
                   1513:                 NextX = rectClient.right - 1;
                   1514:             }
                   1515:             if (NextY < rectClient.top) {
                   1516:                 NextY = rectClient.top;
                   1517:             } else if (NextY >= rectClient.bottom) {
                   1518:                 NextY = rectClient.bottom - 1;
                   1519:             }
                   1520:             if ((NextX != PrevX) || (NextY != PrevY)) {
                   1521:                SetROP2(hDC, R2_NOT);           // Erases the previous box
                   1522:                bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, TRUE, TRUE, FALSE, NULL);
                   1523: 
                   1524:                //
                   1525:                // Optimization.  Do not record in metafile DC if it is going
                   1526:                // to be erased.  So only call bDrawStuff with the PEN tool.
                   1527:                //
                   1528:                if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                   1529:                    bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, TRUE, TRUE, FALSE, NULL);
                   1530:                }
                   1531: 
                   1532: 
                   1533:             // Get the current mouse position
                   1534:                PrevX = NextX;
                   1535:                PrevY = NextY;
                   1536: 
                   1537:                //
                   1538:                // SetROP2(hDC, R2_COPYPEN);
                   1539:                //   This is commented out because we don't want to erase
                   1540:                //   the background as it sweeps.
                   1541:                //
                   1542:                bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, FALSE, TRUE, FALSE, NULL);
                   1543: 
                   1544:                if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                   1545:                    bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, FALSE, TRUE, FALSE, NULL);
                   1546:                }
                   1547: 
                   1548:             }
                   1549:         }
                   1550:         break;
                   1551: 
                   1552:       }
                   1553: 
                   1554:       case WM_LBUTTONUP: {
                   1555:         int NextX;
                   1556:         int NextY;
                   1557: 
                   1558:         if (!bTrack)
                   1559:            break;
                   1560: 
                   1561:         // End the selection
                   1562:            ReleaseCapture();
                   1563:            bTrack = FALSE;
                   1564: 
                   1565:         // Erases the box
                   1566:            //
                   1567:            // SetROP2(hDC, R2_NOT);
                   1568:            //   This is assumed to be R2_NOT, thus unnecessary
                   1569:            //
                   1570:            bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, TRUE, FALSE, FALSE, NULL);
                   1571: 
                   1572:            if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                   1573:                bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, TRUE, FALSE, FALSE, NULL);
                   1574:            }
                   1575: 
1.1.1.3 ! root     1576:            NextX = (SHORT) LOWORD(lParam);
        !          1577:            NextY = (SHORT) HIWORD(lParam);
1.1       root     1578: 
                   1579:         // Draws the new box
                   1580:            SetROP2(hDC, R2_COPYPEN);
                   1581:            bDrawStuff(hDC, OrgX, OrgY, NextX, NextY, FALSE, FALSE, TRUE, NULL);
                   1582: 
                   1583:            ReleaseDC(hwnd, hDC);
                   1584: 
                   1585:            if (gbRecording && (ghDCMetaf != NULL)) {
                   1586:                 bDrawStuff(ghDCMetaf, OrgX, OrgY, NextX, NextY, FALSE, FALSE, FALSE, NULL);
                   1587:            }
                   1588: 
                   1589:         break;
                   1590:       } // case WM_LBUTTONUP
                   1591: 
                   1592:       case WM_CHAR: {
                   1593: 
                   1594:         if (gdwCurTool != DID_TEXT)
                   1595:             break;
                   1596: 
                   1597:         hDC = GetDC(hwnd);
                   1598:         bDrawStuff(hDC, 0, 0, 0, 0, TRUE, FALSE, FALSE, (LPSTR)&wParam);
                   1599:         ReleaseDC(hwnd, hDC);
                   1600: 
                   1601:         if (gbRecording && (ghDCMetaf != NULL)) {
                   1602:             bDrawStuff(ghDCMetaf, 0, 0, 0, 0, TRUE, FALSE, FALSE, (LPSTR)&wParam);
                   1603:         }
                   1604: 
                   1605:         break;
                   1606:       }
                   1607: 
                   1608:       case WM_DESTROY: {
                   1609:         DestroyCaret();
                   1610:         DeleteObject(ghCurFont);
                   1611:        PostQuitMessage(0);
                   1612:        return 0L;
                   1613:       }
                   1614: 
                   1615:       default:
                   1616:        return DefWindowProc(hwnd, message, wParam, lParam);
                   1617:     }
                   1618: }
                   1619: 
                   1620: 
                   1621: /***************************************************************************\
                   1622: * About
                   1623: *
                   1624: * About dialog proc.
                   1625: *
                   1626: * History:
                   1627: * 09-09-91 Petrus Wong Rewrote.
                   1628: * 04-13-91 ????         Created.
                   1629: \***************************************************************************/
                   1630: 
1.1.1.3 ! root     1631: BOOL CALLBACK About (
1.1       root     1632:     HWND hDlg,
                   1633:     UINT message,
                   1634:     DWORD wParam,
                   1635:     LONG lParam)
                   1636: {
                   1637:     switch (message) {
                   1638:     case WM_INITDIALOG:
                   1639:         return TRUE;
                   1640: 
                   1641:     case WM_COMMAND:
                   1642:         if (wParam == IDOK)
                   1643:             EndDialog(hDlg, wParam);
                   1644:         break;
                   1645:     }
                   1646: 
                   1647:     return FALSE;
                   1648: 
                   1649:     UNREFERENCED_PARAMETER(lParam);
                   1650:     UNREFERENCED_PARAMETER(hDlg);
                   1651: }
                   1652: 
                   1653: /***************************************************************************\
                   1654: *
                   1655: * TextWndProc
                   1656: *
                   1657: * Text Window procedure for displaying miscellaneous messages to user.
                   1658: *
                   1659: * History:
                   1660: * 10-07-91  Petrus Wong
                   1661: *   3D text output
                   1662: *
                   1663: \***************************************************************************/
                   1664: 
1.1.1.2   root     1665: LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
1.1       root     1666: {
                   1667:     static HFONT hFont = (HFONT) NULL;
                   1668: 
                   1669:     switch (message)
                   1670:     {
                   1671:     case WM_CREATE:
                   1672:         {
                   1673:            LOGFONT    lf;
                   1674:            HDC        hDC;
                   1675:            HFONT      hOldFont;
                   1676:             TEXTMETRIC tm;
                   1677:            //RECT       rect;
                   1678: 
                   1679:             SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);
                   1680: 
                   1681:            hDC = GetDC(hwnd);
                   1682:            // this is the height for 8 point size font in pixels
                   1683:            lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
                   1684: 
                   1685:            hFont = CreateFontIndirect(&lf);
                   1686:            hOldFont = SelectObject(hDC, hFont);
                   1687:            GetTextMetrics(hDC, &tm);
                   1688: 
                   1689:            // base the height of the window on size of text
                   1690:            glcyStatus = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
                   1691:             ReleaseDC(hwnd, hDC);
                   1692:             break;
                   1693:         }
                   1694: 
                   1695:     case WM_DESTROY:
                   1696:            if (hFont)
                   1697:                DeleteObject(hFont);
                   1698:            break;
                   1699: 
                   1700:     case WM_SETTEXT:
                   1701:             DefWindowProc(hwnd, message, wParam, lParam);
                   1702:             InvalidateRect(hwnd,NULL,FALSE);
                   1703:             UpdateWindow(hwnd);
                   1704:             return 0L;
                   1705: 
                   1706:     case WM_PAINT:
                   1707:         {
                   1708:             PAINTSTRUCT ps;
                   1709:             RECT   rc;
                   1710:             char   ach[128];
                   1711:             int    len, nxBorder, nyBorder;
                   1712:             HFONT  hOldFont = NULL;
                   1713: 
                   1714:             BeginPaint(hwnd, &ps);
                   1715: 
                   1716:             GetClientRect(hwnd,&rc);
                   1717: 
                   1718:             nxBorder = GetSystemMetrics(SM_CXBORDER);
                   1719:            rc.left  += 9*nxBorder;
                   1720:             rc.right -= 9*nxBorder;
                   1721: 
                   1722:             nyBorder = GetSystemMetrics(SM_CYBORDER);
                   1723:            rc.top    += 3*nyBorder;
                   1724:            rc.bottom -= 3*nyBorder;
                   1725: 
                   1726:            // 3D Text
                   1727:             len = GetWindowText(hwnd, ach, sizeof(ach));
                   1728:            SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));
                   1729: 
                   1730:            SetBkMode(ps.hdc, TRANSPARENT);
                   1731:            SetTextColor(ps.hdc, RGB(64,96,96));
                   1732:            if (hFont)
                   1733:                hOldFont = SelectObject(ps.hdc, hFont);
                   1734:            ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
                   1735:                        &rc, ach, len, NULL);
                   1736: 
                   1737:            SetTextColor(ps.hdc, RGB(128,128,128));
                   1738:            if (hFont)
                   1739:                hOldFont = SelectObject(ps.hdc, hFont);
                   1740:            ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
                   1741:                        &rc, ach, len, NULL);
                   1742: 
                   1743:            SetTextColor(ps.hdc, RGB(255,255,255));
                   1744:            if (hFont)
                   1745:                hOldFont = SelectObject(ps.hdc, hFont);
                   1746:            ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
                   1747:                        &rc, ach, len, NULL);
                   1748: 
                   1749:            SetBkMode(ps.hdc, OPAQUE);
                   1750: 
                   1751:            if (hOldFont)
                   1752:                SelectObject(ps.hdc, hOldFont);
                   1753: 
                   1754:             EndPaint(hwnd, &ps);
                   1755:             return 0L;
                   1756:         }
                   1757:     }
                   1758:     return DefWindowProc(hwnd, message, wParam, lParam);
                   1759: }
                   1760: 
                   1761: /******************************Public*Routine******************************\
                   1762: *
                   1763: * CtrlPanelDlgProc
                   1764: *       The Control Panel dialog procedure
                   1765: *
                   1766: * Effects:  Responsible for drawing the owner draw buttons.  Notifying
                   1767: *           parent of user's action.
                   1768: *
                   1769: * Warnings:
                   1770: *
                   1771: * History:
                   1772: *  27-May-1992 -by- Petrus Wong
                   1773: * Wrote it.
                   1774: \**************************************************************************/
                   1775: 
1.1.1.2   root     1776: LONG APIENTRY CtrlPanelDlgProc(HWND hwnd, UINT msg, DWORD dwParam, LONG lParam)
1.1       root     1777: {
                   1778:     switch (msg) {
                   1779:         case WM_INITDIALOG: {
                   1780:             int index;
                   1781: 
                   1782:             for (index = 0; index < OD_BTN_CNT; index++) {
                   1783:                 grHwndCtrlBtn[index] = (PVOID)GetDlgItem(hwnd, (INT)(ID_OD_BTN_BASE+index));
                   1784:             }
                   1785:             for (index = 0; index < OD_TOOL_CNT; index++) {
                   1786:                 grHwndToolBtn[index] = (PVOID)GetDlgItem(hwnd, (INT)(ID_OD_TOOL_BASE+index));
                   1787:             }
                   1788:             return TRUE;
                   1789:         }
                   1790: 
                   1791:         case WM_DRAWITEM: {
                   1792:             PDRAWITEMSTRUCT pDIS = (PDRAWITEMSTRUCT) lParam;
                   1793:             HBITMAP hBmpOld;
                   1794:             BITMAP  bm;
                   1795:             HANDLE  hCtl;
                   1796:             HDC     hDCCtl;
                   1797: 
                   1798:             if (pDIS->CtlID == gdwCurCtrl) {
                   1799:                 GetObject((HBITMAP) ghBmpDn[pDIS->CtlID - ID_OD_BTN_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1800:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP) ghBmpDn[pDIS->CtlID - ID_OD_BTN_BASE]);
                   1801:             }
                   1802: 
                   1803:             if (pDIS->CtlID == gdwCurTool) {
                   1804:                 GetObject((HBITMAP)ghToolBmpDn[pDIS->CtlID - ID_OD_TOOL_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1805:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghToolBmpDn[pDIS->CtlID - ID_OD_TOOL_BASE]);
                   1806:             }
                   1807: 
                   1808:             if ((pDIS->CtlID < ID_OD_TOOL_BASE) && (pDIS->CtlID != gdwCurCtrl)) {
                   1809:                 GetObject((HBITMAP)ghBmpUp[pDIS->CtlID - ID_OD_BTN_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1810:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghBmpUp[pDIS->CtlID - ID_OD_BTN_BASE]);
                   1811:             }
                   1812: 
                   1813:             if ((pDIS->CtlID >= ID_OD_TOOL_BASE) && (pDIS->CtlID != gdwCurTool)) {
                   1814:                 GetObject((HBITMAP)ghToolBmpUp[pDIS->CtlID - ID_OD_TOOL_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1815:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghToolBmpUp[pDIS->CtlID - ID_OD_TOOL_BASE]);
                   1816:             }
                   1817: 
                   1818:             //
                   1819:             // pDIS->hDC is clipped to the update region but unfortunately
                   1820:             // that doesn't work well with StretchBlt.  StretchBlt is used
                   1821:             // because I don't have to make sure that the bitmap size is
                   1822:             // exactly the same as the size of the button.
                   1823:             //
                   1824:             hCtl   = GetDlgItem(hwnd, pDIS->CtlID);
                   1825:             hDCCtl = GetDC(hCtl);
                   1826:             StretchBlt(hDCCtl,                                //pDIS->hDC,
                   1827:                    pDIS->rcItem.left, pDIS->rcItem.top,
                   1828:                    pDIS->rcItem.right - pDIS->rcItem.left,
                   1829:                    pDIS->rcItem.bottom - pDIS->rcItem.top,
                   1830:                    ghDCMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
                   1831:             ReleaseDC(hCtl, hDCCtl);
                   1832:             SelectObject(ghDCMem, hBmpOld);
                   1833:             break;
                   1834:         }
                   1835: 
                   1836:         case WM_COMMAND: {
                   1837:             DWORD dwOldCtrl = gdwCurCtrl;
                   1838:             DWORD dwOldTool = gdwCurTool;
                   1839: 
                   1840:             switch (dwParam) {
                   1841:                 case DID_ONE:
                   1842:                 case DID_TWO:
                   1843:                 case DID_THREE:
                   1844:                 case DID_FOUR:
                   1845:                 case DID_FIVE:
                   1846:                 case DID_SIX:
                   1847:                 case DID_SEVEN:
                   1848:                 case DID_EIGHT:
                   1849:                 case DID_NINE:
                   1850:                 case DID_ZERO:
                   1851:                 case DID_TEN_PLUS:
                   1852:                     //SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, dwParam - DID_ZERO, FALSE);
                   1853:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1854:                     break;
                   1855:                 case DID_OPEN:
                   1856:                 case DID_RECORD:
                   1857:                 case DID_STOP:
                   1858:                 case DID_PLAY:
                   1859:                 case DID_FF:
                   1860:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1861:                     gdwCurCtrl = dwParam;
                   1862:                     InvalidateRect((HWND)grHwndCtrlBtn[dwOldCtrl - ID_OD_BTN_BASE], NULL, FALSE);
                   1863:                     InvalidateRect((HWND)grHwndCtrlBtn[gdwCurCtrl - ID_OD_BTN_BASE], NULL, FALSE);
                   1864:                     break;
                   1865:                 case DID_CLEAR:
                   1866:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1867:                     break;
                   1868:                 case DID_TEXT:
                   1869:                 case DID_PEN:
                   1870:                 case DID_RECT:
                   1871:                 case DID_FILLRECT:
                   1872:                 case DID_ELLIPSE:
                   1873:                 case DID_FILLELLIPSE:
                   1874:                 case DID_LINE:
                   1875:                 case DID_BEZIER:
                   1876:                 case DID_BMPOBJ:
                   1877:                 case DID_METAF:
                   1878:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1879:                     gdwCurTool = dwParam;
                   1880:                     InvalidateRect((HWND)grHwndToolBtn[dwOldTool - ID_OD_TOOL_BASE], NULL, FALSE);
                   1881:                     InvalidateRect((HWND)grHwndToolBtn[gdwCurTool - ID_OD_TOOL_BASE], NULL, FALSE);
                   1882:                     break;
                   1883:             }
                   1884:             break;
                   1885:         }
                   1886: 
                   1887: 
                   1888:         case WM_PAINT:
                   1889:             {
                   1890:                 HDC hdc;
                   1891:                 RECT rc, rcDlg;
                   1892:                 PAINTSTRUCT ps;
                   1893:                 HPEN hpenWindowFrame, hpenDarkGray;
                   1894:                 int  icyDlg;
                   1895:                 int  icyBorder;
                   1896: 
                   1897:                 icyBorder = GetSystemMetrics(SM_CYBORDER);
                   1898: 
                   1899:                 GetWindowRect(hwnd, &rcDlg);
                   1900:                 icyDlg = rcDlg.right - rcDlg.left;
                   1901: 
                   1902:                 /*
                   1903:                  * Draw our border lines.
                   1904:                  */
                   1905:                 GetClientRect(hwnd, &rc);
                   1906:                 hdc = BeginPaint(hwnd, &ps);
                   1907: 
                   1908:                 SelectObject(hdc, GetStockObject(WHITE_PEN));
                   1909:                 MoveToEx(hdc, rc.left, rc.top, NULL);
                   1910:                 LineTo(hdc, rc.right, rc.top);
                   1911: 
                   1912:                 hpenDarkGray = CreatePen(PS_SOLID, 1, DARKGRAY);
                   1913:                 SelectObject(hdc, hpenDarkGray);
                   1914:                 MoveToEx(hdc, rc.left, (rc.top + icyDlg) - icyBorder - 1, NULL);
                   1915:                 LineTo(hdc, rc.right, (rc.top + icyDlg) - icyBorder - 1);
                   1916: 
                   1917:                 hpenWindowFrame = CreatePen(PS_SOLID, icyBorder,
                   1918:                         GetSysColor(COLOR_WINDOWFRAME));
                   1919:                 SelectObject(hdc, hpenWindowFrame);
                   1920:                 MoveToEx(hdc, rc.left, (rc.top + icyDlg) - icyBorder, NULL);
                   1921:                 LineTo(hdc, rc.right, (rc.top + icyDlg) - icyBorder);
                   1922: 
                   1923:                 EndPaint(hwnd, &ps);
                   1924:                 DeleteObject(hpenWindowFrame);
                   1925:                 DeleteObject(hpenDarkGray);
                   1926:             }
                   1927: 
                   1928:             break;
                   1929: 
                   1930: 
                   1931:         //case WM_CTLCOLOR:
                   1932:         case WM_CTLCOLORDLG:
                   1933:         //case WM_CTLCOLORLISTBOX:
1.1.1.2   root     1934:         case WM_CTLCOLORSTATIC:
1.1       root     1935:             switch (GET_WM_CTLCOLOR_TYPE(dwParam, lParam, msg)) {
                   1936:                 case CTLCOLOR_DLG:
                   1937:                 //case CTLCOLOR_LISTBOX:
                   1938:                     return (BOOL)GetStockObject(LTGRAY_BRUSH);
                   1939: 
1.1.1.2   root     1940:                 case CTLCOLOR_STATIC:
                   1941:                     SetBkMode(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
                   1942:                               TRANSPARENT);
                   1943:                 //    SetTextColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
                   1944:                 //              RGB(255,0,0));
1.1       root     1945:                 //    SetBkColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
                   1946:                 //            LIGHTGRAY);
1.1.1.2   root     1947:                 //              RGB(255, 255,0));
                   1948:                     return (BOOL)GetStockObject(DKGRAY_BRUSH);
1.1       root     1949:             }
1.1.1.2   root     1950:             //return (BOOL)NULL;
                   1951:             return (BOOL)GetStockObject(LTGRAY_BRUSH);
1.1       root     1952: 
                   1953:         default:
                   1954:             return FALSE;
                   1955:     }
                   1956: 
                   1957:     return FALSE;
                   1958: }
                   1959: 
                   1960: 
                   1961: 
                   1962: /******************************Public*Routine******************************\
                   1963: *
                   1964: * bDrawStuff
                   1965: *
                   1966: * Effects:  The drawing routines are localized here.
                   1967: *           bErase is TRUE if this fcn is called for erasing previous object.
                   1968: *           (as in tracking objects.)  It is FALSE, otherwise.
                   1969: *
                   1970: *           bMove is TRUE if this fcn is called inside the WM_MOUSEMOVE (as
                   1971: *           in tracking objects.)  It is FALSE, otherwise.
                   1972: *
                   1973: *           bCntPt is TRUE if this fcn is to increment either the iCnt or
                   1974: *           iCntMF counter (used only in processing metafile or bezier.)
                   1975: *           It is FALSE, otherwise.
                   1976: *
                   1977: *           lpstr contains the character to be drawn by TextOut when it is
                   1978: *           not NULL.
                   1979: *
                   1980: * Warnings: Metafile and Bezier assume that the caller is calling this fcn
                   1981: *           to draw in the screen DC first. Then draw it to the metafile DC.
                   1982: *           Thus, when it is called to draw on the metafile DC, the points
                   1983: *           would have been set already.
                   1984: *
                   1985: * History:
                   1986: *  10-May-1992 -by- Petrus Wong
                   1987: * Wrote it.
                   1988: \**************************************************************************/
                   1989: 
                   1990: BOOL bDrawStuff(HDC hDC, INT OrgX, INT OrgY,
                   1991:                          INT NextX, INT NextY,
                   1992:                          BOOL bErase,
                   1993:                          BOOL bMove,
                   1994:                          BOOL bCntPt,
                   1995:                          LPSTR lpstr) {
                   1996:     BOOL bSuccess;
                   1997:     HGDIOBJ hObjOld;
                   1998:     static POINT rgPts[MAX_POINTS], rgPtsMF[MAX_POINTS_MF], rgPtsBMP[MAX_POINTS_BMP];
                   1999:     static int   iCnt=0, iCntMF=0, iCntBMP=0;
                   2000:     static BOOL  bCaretShown=FALSE;
                   2001: 
                   2002:     bSuccess = TRUE;
                   2003:     if (bCaretShown) {
                   2004:         HideCaret(ghwndDrawSurf);
                   2005:         bCaretShown = FALSE;
                   2006:     }
                   2007: 
                   2008:     switch (gdwCurTool) {
                   2009:         case DID_PEN:
                   2010:             if (bErase) {
                   2011:                 MoveToEx(hDC, NextX, NextY, NULL);
                   2012:             } else {
                   2013:                 //
                   2014:                 // Override the ROP2 st. the pen won't erase its track
                   2015:                 //
                   2016:                 SetROP2(hDC, R2_COPYPEN);
                   2017:                 LineTo(hDC, NextX, NextY);
                   2018:             }
                   2019:             break;
                   2020:         case DID_TEXT: {
                   2021:             POINT   Pt;
                   2022: 
                   2023:             if (lpstr == NULL) {
                   2024:                 ShowCaret(ghwndDrawSurf);
                   2025:                 bCaretShown = TRUE;
                   2026:                 SetCaretPos(NextX, NextY);
                   2027:                 MoveToEx(hDC, NextX, NextY, NULL);
                   2028:                 SetFocus(ghwndDrawSurf);
                   2029:                 break;
                   2030:             }
                   2031: 
1.1.1.2   root     2032:             SetTextAlign(hDC, TA_BASELINE | TA_LEFT | TA_UPDATECP);
1.1       root     2033:             hObjOld = SelectObject(hDC, ghCurFont);
                   2034:             SetTextColor(hDC, gCrText);
1.1.1.2   root     2035: 
1.1.1.3 ! root     2036:             if ((gbSFOutln || gbPDOutln) && gbTT) {
        !          2037:                 // get rid of the char box
        !          2038:                 SetBkMode(hDC, TRANSPARENT);
        !          2039:                 BeginPath(hDC);
        !          2040:                 TextOut(hDC, NextX,    NextY,    lpstr, 1);
        !          2041:                 EndPath(hDC);
        !          2042: 
        !          2043:                 if (gbSFOutln) {
        !          2044:                     StrokeAndFillPath(hDC);
        !          2045:                     goto DT_UPDATE;
        !          2046:                 }
        !          2047: 
        !          2048:                 //
        !          2049:                 // Get path and polydraw
        !          2050:                 //
        !          2051:                 {
        !          2052:                 int     iNumPt;
        !          2053:                 PBYTE   pjTypes;
        !          2054:                 PPOINT  pPts;
        !          2055: 
        !          2056:                 if (iNumPt = GetPath(hDC, NULL, NULL, 0)) {
        !          2057:                     if ((pPts = (PPOINT)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          2058:                                                 sizeof(POINT)*iNumPt )) == NULL) {
        !          2059:                         MessageBox(ghwndMain, "Failed in Creating POINT!", "Error", MB_OK);
        !          2060:                         break;
        !          2061:                     }
        !          2062: 
        !          2063:                     if ((pjTypes = (PBYTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          2064:                                                 sizeof(BYTE)*iNumPt )) == NULL) {
        !          2065:                         MessageBox(ghwndMain, "Failed in Creating PBYTE!", "Error", MB_OK);
        !          2066:                         goto GP_EXIT1;
        !          2067:                     }
        !          2068: 
        !          2069:                     GetPath(hDC, pPts, pjTypes, iNumPt);
        !          2070:                 }
        !          2071:                 PolyDraw(hDC, pPts, pjTypes, iNumPt);
        !          2072:                 LocalFree(pjTypes);
        !          2073: 
        !          2074: GP_EXIT1:
        !          2075:                 LocalFree(pPts);
        !          2076: 
        !          2077:                 }
1.1.1.2   root     2078: 
1.1.1.3 ! root     2079:             } else {
        !          2080:                 TextOut(hDC, NextX,    NextY,    lpstr, 1);
        !          2081:             }
        !          2082: DT_UPDATE:
        !          2083:             //
        !          2084:             // Updating current position
        !          2085:             //
1.1.1.2   root     2086:             {
                   2087:             LONG    lHeight;
                   2088:             LONG    lWidth;
                   2089:             TEXTMETRIC     tm;
                   2090: 
1.1.1.3 ! root     2091:                 if (GetTextMetrics(hDC, &tm)) {
        !          2092:                     lHeight = tm.tmHeight;
        !          2093:                     lWidth  = tm.tmMaxCharWidth;
        !          2094:                 }
1.1.1.2   root     2095: 
1.1.1.3 ! root     2096:                 GetCurrentPositionEx(hDC, (LPPOINT) &Pt);
        !          2097:                 SetCaretPos(Pt.x+lWidth, Pt.y);
1.1.1.2   root     2098: 
                   2099:             }
1.1       root     2100:             ShowCaret(ghwndDrawSurf);
                   2101:             bCaretShown = TRUE;
                   2102: 
                   2103:             break;
1.1.1.3 ! root     2104: 
        !          2105: #if 0
        !          2106: 
        !          2107: #define PT_LINECLOSE     (PT_LINETO | PT_CLOSEFIGURE)
        !          2108: #define PT_BEZIERCLOSE (PT_BEZIERTO | PT_CLOSEFIGURE)
        !          2109: 
        !          2110:             hpnRed = CreatePen(PS_SOLID, 0, RGB(255,0,0));
        !          2111:             SelectObject(hDC, hpnRed);
        !          2112: 
        !          2113:             while (iNumPt--) {
        !          2114:                 static POINT pPnt[3];
        !          2115:                 static int   iCnt=0;
        !          2116: 
        !          2117:                 switch (*pjTypes++) {
        !          2118:                     case PT_MOVETO: {
        !          2119:                         MoveToEx(hDC, pPts->x, pPts->y, NULL);
        !          2120:                         pPts++;
        !          2121:                         break;
        !          2122:                     }
        !          2123:                     case PT_LINETO: {
        !          2124:                         LineTo(hDC, pPts->x, pPts->y);
        !          2125:                         pPts++;
        !          2126:                         break;
        !          2127: 
        !          2128:                     }
        !          2129:                     case PT_LINECLOSE: {
        !          2130:                         LineTo(hDC, pPts->x, pPts->y);
        !          2131:                         pPts++;
        !          2132:                         goto GP_EXIT2;
        !          2133:                     }
        !          2134:                     case PT_BEZIERTO: {
        !          2135:                         pPnt[iCnt].x = pPts->x;
        !          2136:                         pPnt[iCnt].y = pPts->y;
        !          2137:                         pPts++;
        !          2138: 
        !          2139:                         if (iCnt < 2) {
        !          2140:                             iCnt++;
        !          2141:                         } else {
        !          2142:                             PolyBezierTo(hDC, pPnt, 3);
        !          2143:                             iCnt = 0;
        !          2144:                         }
        !          2145:                         break;
        !          2146:                     }
        !          2147:                     case PT_BEZIERCLOSE: {
        !          2148:                         pPnt[iCnt].x = pPts->x;
        !          2149:                         pPnt[iCnt].y = pPts->y;
        !          2150:                         pPts++;
        !          2151: 
        !          2152:                         if (iCnt < 2) {
        !          2153:                             iCnt++;
        !          2154:                         } else {
        !          2155:                             PolyBezierTo(hDC, pPnt, 3);
        !          2156:                             iCnt = 0;
        !          2157:                         }
        !          2158:                         goto GP_EXIT2;
        !          2159:                     }
        !          2160: 
        !          2161:                     default:
        !          2162:                         break;
        !          2163:                 }
        !          2164: 
        !          2165:             }
        !          2166: 
        !          2167: #endif
1.1       root     2168:         }
                   2169:         case DID_RECT:
                   2170:             hObjOld = SelectObject(hDC, GetStockObject(NULL_BRUSH));
                   2171:             Rectangle(hDC, OrgX, OrgY, NextX, NextY);
                   2172:             SelectObject(hDC, hObjOld);
                   2173:             break;
                   2174:         case DID_FILLRECT:
                   2175:             Rectangle(hDC, OrgX, OrgY, NextX, NextY);
                   2176:             break;
                   2177:         case DID_ELLIPSE:
                   2178:             hObjOld = SelectObject(hDC, GetStockObject(NULL_BRUSH));
                   2179:             Ellipse(hDC, OrgX, OrgY, NextX, NextY);
                   2180:             SelectObject(hDC, hObjOld);
                   2181:             break;
                   2182:         case DID_FILLELLIPSE:
                   2183:             Ellipse(hDC, OrgX, OrgY, NextX, NextY);
                   2184:             break;
                   2185:         case DID_LINE:
                   2186:             MoveToEx(hDC, OrgX, OrgY, NULL);
                   2187:             LineTo(hDC, NextX, NextY);
                   2188:             break;
                   2189:         case DID_BEZIER:
                   2190:             if (bErase || bMove)
                   2191:                 return bSuccess;
                   2192: 
                   2193:             if (bCntPt) {
                   2194:                 rgPts[iCnt].x = NextX;
                   2195:                 rgPts[iCnt].y = NextY;
                   2196:                 iCnt++;
                   2197: 
                   2198:                 if (iCnt == MAX_POINTS - 1)
                   2199:                     iCnt = 0;
                   2200:             }
                   2201: 
                   2202:             if ((iCnt % 3) == 1) {              // (iCnt + 1) % 3 == 1
                   2203:                 //
                   2204:                 // Override the ROP2 st. the pen won't erase its track
                   2205:                 //
                   2206:                 SetROP2(hDC, R2_COPYPEN);
                   2207:                 PolyBezier(hDC, (LPPOINT)&rgPts, (DWORD) iCnt);
                   2208:             }
                   2209:             return bSuccess;
                   2210: 
                   2211:         case DID_BMPOBJ: {
                   2212:             static BOOL          bBltReady = FALSE;
                   2213: 
                   2214:             if (bErase || bMove)
                   2215:                 return bSuccess;
                   2216: 
                   2217:             if (ghBmp == NULL) {
                   2218:                 SetWindowText(ghTextWnd, "ERROR: No bitmap to embed!");
                   2219:                 return bSuccess;
                   2220:             }
                   2221: 
                   2222:             if (bCntPt) {
                   2223:                 bBltReady = FALSE;
                   2224:                 rgPtsBMP[iCntBMP].x = NextX;
                   2225:                 rgPtsBMP[iCntBMP].y = NextY;
                   2226:                 iCntBMP++;
                   2227: 
                   2228:                 if (iCntBMP < MAX_POINTS_BMP) {
                   2229:                     return bSuccess;
                   2230:                 }
                   2231:             } else {
                   2232:                 //
                   2233:                 // Caller don't want to increment counter, so must be doing
                   2234:                 // recording, so we just Blt again...
                   2235:                 //
                   2236:                 // But, if the Blt data is no good, bail out...
                   2237:                 //
                   2238:                 if (!bBltReady) {
                   2239:                     return bSuccess;
                   2240:                 }
1.1.1.3 ! root     2241:                 bPlgBlt(hDC, rgPtsBMP);
1.1       root     2242:                 return bSuccess;
                   2243:             }
                   2244:             bBltReady = TRUE;
                   2245: 
1.1.1.3 ! root     2246:             bPlgBlt(hDC, rgPtsBMP);
1.1       root     2247:             iCntBMP = 0;                         // reset
                   2248:             return bSuccess;
                   2249:         }
                   2250: 
                   2251:         case DID_METAF: {
                   2252:             ENHMETAHEADER EnhMetaHdr;
                   2253:             RECT          rcClientDS;
                   2254:             static XFORM         xform;
                   2255:             static BOOL          bXformReady = FALSE;
1.1.1.3 ! root     2256:             int           iEntries;
        !          2257:             PLOGPALETTE     plogPal;
        !          2258:             PBYTE           pjTmp;
        !          2259:             HPALETTE        hPal;
        !          2260: 
1.1       root     2261: 
                   2262:             if (bErase || bMove)
                   2263:                 return bSuccess;
                   2264: 
                   2265:             if (ghMetaf == NULL) {
                   2266:                 SetWindowText(ghTextWnd, "ERROR: No metafile to embed!");
                   2267:                 return bSuccess;
                   2268:             }
                   2269: 
                   2270:             if (bCntPt) {
                   2271:                 bXformReady = FALSE;
                   2272:                 rgPtsMF[iCntMF].x = NextX;
                   2273:                 rgPtsMF[iCntMF].y = NextY;
                   2274:                 iCntMF++;
                   2275: 
                   2276:                 if (iCntMF < MAX_POINTS_MF) {
                   2277:                     return bSuccess;
                   2278:                 }
                   2279:             } else {
                   2280:                 //
                   2281:                 // Caller don't want to increment counter, so must be doing
                   2282:                 // recording, so we just set xform and play it again...
                   2283:                 //
                   2284:                 // But, if the xform data is no good, bail out...
                   2285:                 //
                   2286:                 if (!bXformReady) {
                   2287:                     return bSuccess;
                   2288:                 }
                   2289: 
                   2290:                 GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                   2291:                 SetWorldTransform(hDC, &xform);
                   2292:                 GetClientRect(ghwndDrawSurf, &rcClientDS);
1.1.1.3 ! root     2293: 
        !          2294:                 iEntries = GetEnhMetaFilePaletteEntries(ghMetaf, 0, NULL);
        !          2295: 
        !          2296:                 if (iEntries) {
        !          2297:                     if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          2298:                             sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) {
        !          2299:                         MessageBox(ghwndMain, "Failed in Creating Palette!", "Error", MB_OK);
        !          2300:                     }
        !          2301: 
        !          2302:                     plogPal->palVersion = 0x300;
        !          2303:                     plogPal->palNumEntries = (WORD) iEntries;
        !          2304:                     pjTmp = (PBYTE) plogPal;
        !          2305:                     pjTmp += 8;
        !          2306: 
        !          2307:                     GetEnhMetaFilePaletteEntries(ghMetaf, iEntries, (PPALETTEENTRY)pjTmp);
        !          2308:                     hPal = CreatePalette(plogPal);
        !          2309:                     GlobalFree(plogPal);
        !          2310: 
        !          2311:                     SelectPalette(hDC, hPal, FALSE);
        !          2312:                     RealizePalette(hDC);
        !          2313:                 }
        !          2314: 
1.1       root     2315:                 //PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rcClientDS);
1.1.1.3 ! root     2316:                 {
        !          2317:                 RECT rc;
        !          2318: 
        !          2319:                 rc.top = rc.left = 0;
        !          2320:                 rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          2321:                 rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          2322:                 if (!PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rc)) {
        !          2323:                     char    text[128];
        !          2324: 
        !          2325:                     wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          2326:                     OutputDebugString(text);
        !          2327:                 }
        !          2328: 
        !          2329:                 }
1.1       root     2330:                 ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   2331:                 return bSuccess;
                   2332:             }
                   2333: 
                   2334:             GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                   2335:             //
                   2336:             // Based on the three points, top-left, top-right and bottom-left
                   2337:             // (in this order), of the destination, solve equations for the
                   2338:             // elements of the transformation matrix.
                   2339:             //
                   2340:             xform.eDx = (float) rgPtsMF[0].x;
                   2341:             xform.eDy = (float) rgPtsMF[0].y;
                   2342:             xform.eM11 = (rgPtsMF[1].x - xform.eDx)/(EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left);
                   2343:             xform.eM12 = (rgPtsMF[1].y - xform.eDy)/(EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left);
                   2344:             xform.eM21 = (rgPtsMF[2].x - xform.eDx)/(EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top);
                   2345:             xform.eM22 = (rgPtsMF[2].y - xform.eDy)/(EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top);
                   2346: 
                   2347:             bXformReady = TRUE;
                   2348:             SetWorldTransform(hDC, &xform);
                   2349:             GetClientRect(ghwndDrawSurf, &rcClientDS);
1.1.1.3 ! root     2350: 
        !          2351:             iEntries = GetEnhMetaFilePaletteEntries(ghMetaf, 0, NULL);
        !          2352: 
        !          2353:             if (iEntries) {
        !          2354:                 if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          2355:                         sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) {
        !          2356:                     MessageBox(ghwndMain, "Failed in Creating Palette!", "Error", MB_OK);
        !          2357:                 }
        !          2358: 
        !          2359:                 plogPal->palVersion = 0x300;
        !          2360:                 plogPal->palNumEntries = (WORD) iEntries;
        !          2361:                 pjTmp = (PBYTE) plogPal;
        !          2362:                 pjTmp += 8;
        !          2363: 
        !          2364:                 GetEnhMetaFilePaletteEntries(ghMetaf, iEntries, (PPALETTEENTRY)pjTmp);
        !          2365:                 hPal = CreatePalette(plogPal);
        !          2366:                 GlobalFree(plogPal);
        !          2367: 
        !          2368:                 SelectPalette(hDC, hPal, FALSE);
        !          2369:                 RealizePalette(hDC);
        !          2370:             }
        !          2371: 
1.1       root     2372:             //PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rcClientDS);
1.1.1.3 ! root     2373:             {
        !          2374:             RECT rc;
        !          2375: 
        !          2376:             rc.top = rc.left = 0;
        !          2377:             rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          2378:             rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          2379:             if (!PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rc)) {
        !          2380:                  char    text[128];
        !          2381: 
        !          2382:                  wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          2383:                  OutputDebugString(text);
        !          2384:             }
        !          2385: 
        !          2386:             }
1.1       root     2387:             ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   2388:             iCntMF = 0;                         // reset
                   2389:             return bSuccess;
                   2390:         }
                   2391:         default:
                   2392:             break;
                   2393:     }
                   2394:     //
                   2395:     // Reset counter, user has selected other tools.
                   2396:     //
                   2397:     iCnt = 0;
                   2398:     iCntMF = 0;
                   2399:     iCntBMP = 0;
                   2400:     return bSuccess;
                   2401: }
                   2402: 
                   2403: /******************************Public*Routine******************************\
                   2404: *
                   2405: * hemfLoadMetafile
                   2406: *
                   2407: * Effects:   Brings up the Open file common dialog
                   2408: *            Get the enhanced metafile spec'd by user
                   2409: *            returns the handle to the enhanced metafile if successfull
                   2410: *               otherwise, returns 0.
                   2411: *
                   2412: * Warnings:
                   2413: *
                   2414: * History:
                   2415: *  08-May-1992 -by- Petrus Wong
                   2416: * Wrote it.
1.1.1.2   root     2417: *  28-Aug-1992 -by- Petrus Wong     supports aldus placable mf, wmf and emf
1.1       root     2418: \**************************************************************************/
                   2419: 
                   2420: HENHMETAFILE hemfLoadMetafile(HWND hwnd) {
                   2421:     OPENFILENAME    ofn;
                   2422:     char            szFile[256], szFileTitle[256];
                   2423:     static char     *szFilter;
                   2424: 
1.1.1.2   root     2425:     HMETAFILE       hmf;
                   2426:     UINT            uiSize;
                   2427:     LPVOID          pvData;
                   2428:     HDC             hDCDrawSurf;
                   2429:     HENHMETAFILE    hemf;
                   2430: 
                   2431:     HANDLE                  hFile, hMapFile;
                   2432:     LPVOID                  pMapFile;
                   2433:     LPENHMETAHEADER         pemh;
                   2434: 
                   2435:     BOOL        bSuccess;
1.1.1.3 ! root     2436:     char            text[128];
1.1.1.2   root     2437: 
                   2438: 
                   2439:     bSuccess = TRUE;
                   2440: 
1.1       root     2441:     szFilter =
1.1.1.2   root     2442:       "EnhMeta files (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0";
1.1       root     2443: 
                   2444:     strcpy(szFile, "*.emf\0");
                   2445:     ofn.lStructSize = sizeof(OPENFILENAME);
                   2446:     ofn.hwndOwner = hwnd;
                   2447:     ofn.lpstrFilter = szFilter;
                   2448:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   2449:     ofn.nMaxCustFilter = 0L;
                   2450:     ofn.nFilterIndex = 1;
                   2451:     ofn.lpstrFile = szFile;
                   2452:     ofn.nMaxFile = sizeof(szFile);
                   2453:     ofn.lpstrFileTitle = szFileTitle;
                   2454:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   2455:     ofn.lpstrInitialDir = NULL;
                   2456:     ofn.lpstrTitle = "Load Metafile";
                   2457:     ofn.Flags = 0L;
                   2458:     ofn.nFileOffset = 0;
                   2459:     ofn.nFileExtension = 0;
                   2460:     ofn.lpstrDefExt = "EMF";
                   2461: 
                   2462:     if (!GetOpenFileName(&ofn))
                   2463:         return 0L;
                   2464: 
1.1.1.2   root     2465:     if ((hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
                   2466:             OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == (HANDLE)-1) {
1.1.1.3 ! root     2467:         wsprintf(text, "Fail in file open! Error %ld\n", GetLastError());
        !          2468:         MessageBox(ghwndMain, text, "Error", MB_OK);
1.1.1.2   root     2469:         return 0L;
                   2470:     }
                   2471: 
                   2472:     //
                   2473:     // Create a map file of the opened file
                   2474:     //
                   2475:     if ((hMapFile = CreateFileMapping(hFile, NULL,
1.1.1.3 ! root     2476:                              PAGE_READONLY, 0, 0, "MapF")) == NULL) {
        !          2477:         wsprintf(text, "Fail in creating map file! Error %ld\n", GetLastError());
        !          2478:         MessageBox(ghwndMain, text, "Error", MB_OK);
1.1.1.2   root     2479:         bSuccess = FALSE;
                   2480:         goto ErrorExit1;
                   2481:     }
                   2482: 
                   2483:     //
                   2484:     // Map a view of the whole file
                   2485:     //
                   2486:     if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0)) == NULL) {
1.1.1.3 ! root     2487:         wsprintf(text, "Fail in mapping view of the Map File object! Error %ld\n", GetLastError());
        !          2488:         MessageBox(ghwndMain, text, "Error", MB_OK);
1.1.1.2   root     2489:         bSuccess = FALSE;
                   2490:         goto ErrorExit2;
                   2491:     }
                   2492: 
                   2493:     //
                   2494:     // First check that if it is an enhanced metafile
                   2495:     //
                   2496:     pemh = (LPENHMETAHEADER) pMapFile;
                   2497:     if (pemh->dSignature == META32_SIGNATURE) {
                   2498:         hemf = GetEnhMetaFile(szFile);
                   2499:         goto HLM_EXIT;
                   2500:     }
                   2501: 
                   2502:     //
                   2503:     // If it has an ALDUS header skip it
                   2504:     // Notice: APMSIZE is used because the HANDLE and RECT of the structure
                   2505:     //         depends on the environment
                   2506:     //
                   2507:     if (*((LPDWORD)pemh) == ALDUS_ID) {
1.1.1.3 ! root     2508:         //METAFILEPICT    mfp;
        !          2509: 
1.1.1.2   root     2510:         MessageBox(ghwndMain, "This is an ALDUS metafile!", "Hey!", MB_OK);
                   2511:         uiSize = *((LPDWORD) ((PBYTE)pMapFile + APMSIZE + 6));
                   2512:         hDCDrawSurf = GetDC(ghwndDrawSurf);
1.1.1.3 ! root     2513: 
        !          2514:         // Notice: mtSize is size of the file in word.
        !          2515:         // if LPMETAFILEPICT is NULL
        !          2516:         //    MM_ANISOTROPIC mode and default device size will be used.
1.1.1.2   root     2517:         hemf = SetWinMetaFileBits(uiSize*2L, (PBYTE)pMapFile + APMSIZE, hDCDrawSurf, NULL);
1.1.1.3 ! root     2518: #if 0
        !          2519:         switch ( ((PAPMFILEHEADER) pMapFile)->inch ) {
        !          2520:             // !!! End up in an upside down image
        !          2521:             //
        !          2522:             case 1440:
        !          2523:                 mfp.mm = MM_TWIPS;
        !          2524:                 OutputDebugString("MM_TWIPS\n");
        !          2525:                 break;
        !          2526:             case 2540:
        !          2527:                 OutputDebugString("MM_HIMETRIC\n");
        !          2528:                 mfp.mm = MM_HIMETRIC;
        !          2529:                 break;
        !          2530:             case 254:
        !          2531:                 OutputDebugString("MM_LOMETRIC\n");
        !          2532:                 mfp.mm = MM_LOMETRIC;
        !          2533:                 break;
        !          2534:             case 1000:
        !          2535:                 OutputDebugString("MM_HIENGLISH\n");
        !          2536:                 mfp.mm = MM_HIENGLISH;
        !          2537:                 break;
        !          2538:             case 100:
        !          2539:                 OutputDebugString("MM_LOENGLISH\n");
        !          2540:                 mfp.mm = MM_LOENGLISH;
        !          2541:                 break;
        !          2542:             default:
        !          2543:                 // !!! In addition, text is too small
        !          2544:                 //
        !          2545:                 OutputDebugString("MM_ANISOTROPIC\n");
        !          2546:                 mfp.mm = MM_ANISOTROPIC;
        !          2547:                 mfp.xExt = (((PAPMFILEHEADER) pMapFile)->bbox.Right - ((PAPMFILEHEADER) pMapFile)->bbox.Left)
        !          2548:                            * ((PAPMFILEHEADER) pMapFile)->inch * 2560;
        !          2549:                 mfp.yExt = (((PAPMFILEHEADER) pMapFile)->bbox.Bottom - ((PAPMFILEHEADER) pMapFile)->bbox.Top)
        !          2550:                            * ((PAPMFILEHEADER) pMapFile)->inch * 2560;
        !          2551:                 break;
        !          2552:         }
        !          2553:         mfp.hMF = 0;
        !          2554:         hemf = SetWinMetaFileBits(uiSize*2L, (PBYTE)pMapFile + APMSIZE, hDCDrawSurf, &mfp);
        !          2555: #endif
        !          2556: 
1.1.1.2   root     2557:         if (!hemf) {
                   2558:             char text[256];
                   2559: 
                   2560:             wsprintf(text, "SetWinMetaFileBits failed, %x", GetLastError());
                   2561:             MessageBox(ghwndMain, text, "Error!", MB_OK);
                   2562:         }
1.1.1.3 ! root     2563: 
        !          2564:         ghmf = SetMetaFileBitsEx(uiSize*2L, (PBYTE)pMapFile + APMSIZE);
        !          2565:         if (!ghmf) {
        !          2566:             char text[256];
        !          2567: 
        !          2568:             wsprintf(text, "SetMetaFileBitsEx failed, %x", GetLastError());
        !          2569:             MessageBox(ghwndMain, text, "Error!", MB_OK);
        !          2570:         }
        !          2571: 
        !          2572: // !!! Displaying the Windows format metafile
        !          2573: //if (!PlayMetaFile(hDCDrawSurf, ghmf)) {
        !          2574: //    wsprintf(text, "PlayMetaFile failed, %x", GetLastError());
        !          2575: //    MessageBox(ghwndMain, text, "Error!", MB_OK);
        !          2576: //}
        !          2577:         ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
1.1.1.2   root     2578:         goto HLM_EXIT;
                   2579:     }
                   2580: 
                   2581: 
                   2582:     //
                   2583:     // It is a Windows 3x format metafile (hopefully)
                   2584:     //
                   2585:     if (!(hmf = GetMetaFile((LPCSTR)szFile))) {
                   2586:         char text[256];
                   2587: 
                   2588:         wsprintf(text, "GetMetaFile failed, %x", GetLastError());
                   2589:         MessageBox(ghwndMain, text, "Error!", MB_OK);
                   2590:         bSuccess = FALSE;
                   2591:         goto ErrorExit3;
                   2592:     }
                   2593: 
                   2594:     if (!(uiSize = GetMetaFileBitsEx(hmf, 0, NULL))) {
                   2595:         MessageBox(ghwndMain, "Fail in 1st GetMetaFileBitsEx!", "Error", MB_OK);
                   2596:         return NULL;
                   2597:     }
                   2598: 
                   2599:     if ((pvData = (LPVOID) LocalAlloc(LMEM_FIXED, uiSize)) == NULL) {
                   2600:         MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
                   2601:         bSuccess = FALSE;
                   2602:         goto ErrorExit3;
                   2603:     }
                   2604: 
                   2605:     if (!(uiSize = GetMetaFileBitsEx(hmf, uiSize, pvData))) {
                   2606:         MessageBox(ghwndMain, "Fail in 2nd GetMetaFileBitsEx!", "Error", MB_OK);
                   2607:         bSuccess = FALSE;
                   2608:         goto ErrorExit3;
                   2609:     }
                   2610: 
                   2611:     DeleteMetaFile(hmf);
                   2612: 
                   2613:     hDCDrawSurf = GetDC(ghwndDrawSurf);
                   2614:     hemf = SetWinMetaFileBits(uiSize, (LPBYTE)pvData, hDCDrawSurf, NULL);
1.1.1.3 ! root     2615:     ghmf = SetMetaFileBitsEx(uiSize, (LPBYTE) pvData);
1.1.1.2   root     2616: 
                   2617:     LocalFree(pvData);
                   2618: 
                   2619:     ReleaseDC(ghwndDrawSurf ,hDCDrawSurf);
                   2620: 
                   2621: HLM_EXIT:
                   2622: ErrorExit3:
                   2623:     UnmapViewOfFile(pMapFile);
                   2624: 
                   2625: ErrorExit2:
                   2626:     CloseHandle(hMapFile);
                   2627: ErrorExit1:
                   2628:     CloseHandle(hFile);
                   2629: 
                   2630:     if (bSuccess)
                   2631:         return hemf;
                   2632:     else
                   2633:         return 0L;
1.1       root     2634: }
                   2635: 
                   2636: /******************************Public*Routine******************************\
                   2637: *
                   2638: * hDCRecordMetafileAs
                   2639: *
                   2640: * Effects:   Brings up the SaveAs common dialog
                   2641: *            Creates the enhanced metafile with the filename spec'd by user
                   2642: *            Modifies the second arg to reflect the new default filename
                   2643: *            less extension
                   2644: *            returns the created metafile DC if successful, otherwise, 0
                   2645: *
                   2646: * Warnings:
                   2647: *
                   2648: * History:
                   2649: *  08-May-1992 -by- Petrus Wong
                   2650: * Wrote it.
                   2651: \**************************************************************************/
                   2652: 
                   2653: HDC hDCRecordMetafileAs(HWND hwnd, LPSTR szFilename) {
                   2654:     OPENFILENAME ofn;
                   2655:     char szFile[256], szFileTitle[256];
                   2656:     static char *szFilter;
                   2657:     char *szTmp, szTmp2[256];
                   2658:     HDC  hDCMeta;
                   2659: 
1.1.1.2   root     2660:     int iWidthMM, iHeightMM, iWidthPels, iHeightPels, iMMPerPelX, iMMPerPelY;
                   2661:     RECT rc;
                   2662:     HDC hDC;
                   2663: 
                   2664: 
1.1       root     2665:     szFilter = "EnhMeta files (*.emf)\0\0";
                   2666:     strcpy(szFile, "*.emf\0");
                   2667:     ofn.lStructSize = sizeof(OPENFILENAME);
                   2668:     ofn.hwndOwner = hwnd;
                   2669:     ofn.lpstrFilter = szFilter;
                   2670:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   2671:     ofn.nMaxCustFilter = 0L;
                   2672:     ofn.nFilterIndex = 0L;
                   2673:     ofn.lpstrFile = szFile;
                   2674:     ofn.nMaxFile = sizeof(szFile);
                   2675:     ofn.lpstrFileTitle = szFileTitle;
                   2676:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   2677:     ofn.lpstrInitialDir = NULL;
                   2678:     ofn.lpstrTitle = "Save Metafile As";
                   2679:     ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
                   2680:     ofn.nFileOffset = 0;
                   2681:     ofn.nFileExtension = 0;
                   2682:     ofn.lpstrDefExt = (LPSTR)NULL;
                   2683: 
                   2684:     if (!GetSaveFileName(&ofn)) {
                   2685:         return 0L;
                   2686:     }
                   2687: 
1.1.1.2   root     2688: 
                   2689:     hDC = GetDC(hwnd);
                   2690:     iWidthMM = GetDeviceCaps(hDC, HORZSIZE);
                   2691:     iHeightMM = GetDeviceCaps(hDC, VERTSIZE);
                   2692:     iWidthPels = GetDeviceCaps(hDC, HORZRES);
                   2693:     iHeightPels = GetDeviceCaps(hDC, VERTRES);
                   2694:     ReleaseDC(hwnd, hDC);
                   2695:     iMMPerPelX = (iWidthMM * 100)/iWidthPels;
                   2696:     iMMPerPelY = (iHeightMM * 100)/iHeightPels;
                   2697:     GetClientRect(ghwndDrawSurf, &rc);
                   2698:     rc.left = rc.left * iMMPerPelX;
                   2699:     rc.top = rc.top * iMMPerPelY;
                   2700:     rc.right = rc.right * iMMPerPelX;
                   2701:     rc.bottom = rc.bottom * iMMPerPelY;
                   2702: 
                   2703: 
                   2704:     //hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)NULL, (LPSTR)NULL);
1.1.1.3 ! root     2705:     {
        !          2706:         CHAR    szDesc[256];
        !          2707: 
        !          2708:         wsprintf(szDesc, "SDK Enhanced Metafile Editor\\0%s\\0\\0", szFileTitle);
        !          2709:         hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)&rc, (LPSTR)szDesc);
        !          2710:         if ((SetGraphicsMode(hDCMeta, GM_ADVANCED)) == 0) {
        !          2711:            MessageBox(ghwndMain, "Fail in setting Advanced Graphics Mode!", "Error", MB_OK);
        !          2712:         }
        !          2713:     }
1.1       root     2714: 
                   2715:     //
                   2716:     // parses the new filename, removes the extension and copy it into
                   2717:     // szFilename
                   2718:     //
                   2719:     strcpy(szFilename, "");
                   2720:     szTmp = (char *)strtok(szFile, "\\");
                   2721:     strcpy(szTmp2, szTmp);
                   2722:     while (szTmp != NULL) {
                   2723:         szTmp = (char *)strtok(NULL, "\\");
                   2724:         if (szTmp != NULL) {
                   2725:             strcat(szFilename, szTmp2);
                   2726:             strcpy(szTmp2, szTmp);
                   2727:             strcat(szFilename, "\\");
                   2728:         }
                   2729:     }
                   2730:     szTmp = (char *)strtok(szTmp2, ".");
                   2731:     strcat(szFilename, szTmp);
                   2732: 
                   2733:     return hDCMeta;
                   2734: }
                   2735: 
                   2736: 
                   2737: /******************************Public*Routine******************************\
                   2738: *
                   2739: * bPlayRecord
                   2740: *
                   2741: * Effects:  Play metafile
                   2742: *           if PlayInfo.bPlayContinuous is TRUE
                   2743: *               play metafile from 1st record up to the PlayInfo.iRecord th
                   2744: *                   record
                   2745: *           else only play the PlayInfo.iRecord th record and those preceding
                   2746: *               records that are relevant like MoveTo, etc.
                   2747: *           Terminates enumeration after playing up to the
                   2748: *               PlayInfo.iRecord th record
                   2749: *
                   2750: * Warnings:
                   2751: *
                   2752: * History:
                   2753: *  08-May-1992 -by- Petrus Wong
                   2754: * Wrote it.
                   2755: \**************************************************************************/
                   2756: 
                   2757: BOOL APIENTRY bPlayRecord(HDC hDC, LPHANDLETABLE lpHandleTable,
                   2758:                                    LPENHMETARECORD lpEnhMetaRecord,
                   2759:                                    UINT nHandles,
                   2760:                                    LPVOID lpData) {
                   2761:     BOOL bSuccess;
                   2762:     static int  iCnt=0;
                   2763:     int         i;
                   2764:     char        ach[128];
                   2765:     char        achTmp[128];
                   2766:     LONG        lNumDword;
                   2767: 
                   2768:     bSuccess = TRUE;
                   2769: 
                   2770:     lNumDword = (lpEnhMetaRecord->nSize-8) / 4;
                   2771: 
                   2772:     iCnt++;
                   2773:     if (((PLAYINFO *) lpData)->bPlayContinuous) {
                   2774:         bSuccess = PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   2775:                                              lpEnhMetaRecord, nHandles);
                   2776:         if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   2777:             wsprintf((LPSTR) ach, "%s", rgMetaName[lpEnhMetaRecord->iType]);
                   2778:             for (i=0; i < lNumDword; i++) {
                   2779:                 wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   2780:                 if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   2781:                     break;
                   2782:                 strcat(ach, achTmp);
                   2783:             }
                   2784:         SetWindowText(ghTextWnd, ach);
                   2785:         }
                   2786:     } else {
                   2787: 
                   2788:         switch (lpEnhMetaRecord->iType) {
                   2789:             case MR_SETWINDOWEXTEX:
                   2790:             case MR_SETWINDOWORGEX:
                   2791:             case MR_SETVIEWPORTEXTEX:
                   2792:             case MR_SETVIEWPORTORGEX:
                   2793:             case MR_SETBRUSHORGEX:
                   2794:             case MR_SETMAPMODE:
                   2795:             case MR_SETBKMODE:
                   2796:             case MR_SETPOLYFILLMODE:
                   2797:             case MR_SETROP2:
                   2798:             case MR_SETSTRETCHBLTMODE:
                   2799:             case MR_SETTEXTALIGN:
                   2800:             case MR_SETTEXTCOLOR:
                   2801:             case MR_SETBKCOLOR:
                   2802:             case MR_OFFSETCLIPRGN:
                   2803:             case MR_MOVETOEX:
                   2804:             case MR_SETMETARGN:
                   2805:             case MR_EXCLUDECLIPRECT:
                   2806:             case MR_INTERSECTCLIPRECT:
                   2807:             case MR_SCALEVIEWPORTEXTEX:
                   2808:             case MR_SCALEWINDOWEXTEX:
                   2809:             case MR_SAVEDC:
                   2810:             case MR_RESTOREDC:
                   2811:             case MR_SETWORLDTRANSFORM:
                   2812:             case MR_MODIFYWORLDTRANSFORM:
                   2813:             case MR_SELECTOBJECT:
                   2814:             case MR_CREATEPEN:
                   2815:             case MR_CREATEBRUSHINDIRECT:
                   2816:             case MR_DELETEOBJECT:
                   2817:             case MR_SELECTPALETTE:
                   2818:             case MR_CREATEPALETTE:
                   2819:             case MR_SETPALETTEENTRIES:
                   2820:             case MR_RESIZEPALETTE:
                   2821:             case MR_REALIZEPALETTE:
                   2822:             case MR_SETARCDIRECTION:
                   2823:             case MR_SETMITERLIMIT:
                   2824:             case MR_BEGINPATH:
                   2825:             case MR_ENDPATH:
                   2826:             case MR_CLOSEFIGURE:
                   2827:             case MR_SELECTCLIPPATH:
                   2828:             case MR_ABORTPATH:
                   2829:             case MR_EXTCREATEFONTINDIRECTW:
                   2830:             case MR_CREATEMONOBRUSH:
                   2831:             case MR_CREATEDIBPATTERNBRUSHPT:
                   2832:             case MR_EXTCREATEPEN:
                   2833:                 goto PlayRec;
                   2834:             default:
                   2835:                 break;
                   2836:         } //switch
                   2837: 
                   2838:         if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   2839: PlayRec:
                   2840:             bSuccess = PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   2841:                                              lpEnhMetaRecord, nHandles);
                   2842:             wsprintf((LPSTR) ach, "%s", rgMetaName[lpEnhMetaRecord->iType]);
                   2843:             for (i=0; i < lNumDword; i++) {
                   2844:                 wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   2845:                 if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   2846:                     break;
                   2847:                 strcat(ach, achTmp);
                   2848:             }
                   2849:             SetWindowText(ghTextWnd, ach);
                   2850:         }
                   2851:     }
                   2852: 
                   2853:     if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   2854:         iCnt = 0;
                   2855:         return FALSE;
                   2856:     }
                   2857:     return bSuccess;
                   2858: }
                   2859: 
                   2860: /******************************Public*Routine******************************\
                   2861: *
                   2862: * LoadBitmapFile
                   2863: *
                   2864: * Effects:  Loads the bitmap from file and return the bitmap
                   2865: *
                   2866: * Warnings: pszFileName contains the full path
                   2867: *
                   2868: * History:
1.1.1.3 ! root     2869: *  18-Feb-1993 Petrus Wong           fix metaf bnp color problem
        !          2870: *  21-Oct-1992 Petrus Wong           fix data-misalignment
1.1       root     2871: *  13-May-1992 Petrus Wong           return bitmap handle
                   2872: *  09-Jan-1992 -by- Petrus Wong
                   2873: * Wrote it.
                   2874: \**************************************************************************/
                   2875: 
                   2876: HBITMAP hBmpLoadBitmapFile(HDC hDC, PSTR pszFileName)
                   2877: {
1.1.1.3 ! root     2878:     HANDLE              hFile, hMapFile;
        !          2879:     LPVOID              pMapFile, pMapFileTmp;
        !          2880:     LPBITMAPINFOHEADER  pbmh;
        !          2881:     LPBITMAPINFO        pbmi;
        !          2882:     PBYTE               pjTmp;
        !          2883:     ULONG               sizBMI;
        !          2884:     HBITMAP             hBitmap;
        !          2885:     INT                 iNumClr;
        !          2886:     BOOL                bCoreHdr;
        !          2887:     WORD                wBitCount;
        !          2888:     PFILEINFO           pFileInfo;
1.1       root     2889: 
                   2890:     hBitmap = NULL;
                   2891: 
                   2892:     if ((hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
                   2893:             OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == (HANDLE)-1) {
                   2894:         SetWindowText(ghTextWnd, "Fail in file open");
                   2895:         goto ErrExit1;
                   2896:     }
                   2897: 
                   2898:     //
                   2899:     // Create a map file of the opened file
                   2900:     //
                   2901:     if ((hMapFile = CreateFileMapping(hFile, NULL,
1.1.1.3 ! root     2902:                              PAGE_READONLY, 0, 0, NULL)) == (HANDLE)-1) {
1.1       root     2903:         SetWindowText(ghTextWnd, "Fail in creating map file");
                   2904:         goto ErrExit2;
                   2905: 
                   2906:     }
                   2907: 
                   2908:     //
                   2909:     // Map a view of the whole file
                   2910:     //
                   2911:     if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0)) == NULL) {
                   2912:         SetWindowText(ghTextWnd, "Fail in mapping view of the Map File object");
                   2913:         goto ErrExit3;
                   2914:     }
                   2915: 
1.1.1.3 ! root     2916:     pMapFileTmp = pMapFile;
        !          2917: 
1.1       root     2918:     //
                   2919:     // First check that it is a bitmap file
                   2920:     //
                   2921:     if (*((PWORD)pMapFile) != 0x4d42) {              // 'BM'
                   2922:         MessageBox(ghwndMain, "This is not a DIB bitmap file!", "Error", MB_OK);
                   2923:         goto ErrExit3;
                   2924:     }
                   2925: 
                   2926:     //
1.1.1.2   root     2927:     // The file header doesn't end on DWORD boundary...
1.1       root     2928:     //
1.1.1.2   root     2929:     pbmh = (LPBITMAPINFOHEADER)((PBYTE)pMapFile + sizeof(BITMAPFILEHEADER));
                   2930: 
1.1       root     2931:     {
1.1.1.2   root     2932:         BITMAPCOREHEADER bmch, *pbmch;
                   2933:         BITMAPINFOHEADER bmih, *pbmih;
                   2934:         PBYTE            pjTmp;
                   2935:         ULONG            ulSiz;
                   2936: 
                   2937:         pbmch = &bmch;
                   2938:         pbmih = &bmih;
                   2939: 
                   2940:         pjTmp = (PBYTE)pbmh;
                   2941:         ulSiz = sizeof(BITMAPCOREHEADER);
                   2942:         while (ulSiz--) {
                   2943:             *(((PBYTE)pbmch)++) = *(((PBYTE)pjTmp)++);
                   2944:         }
                   2945: 
                   2946:         pjTmp = (PBYTE)pbmh;
                   2947:         ulSiz = sizeof(BITMAPINFOHEADER);
                   2948:         while (ulSiz--) {
                   2949:             *(((PBYTE)pbmih)++) = *(((PBYTE)pjTmp)++);
                   2950:         }
                   2951: 
                   2952:         //
                   2953:         // Use the size to determine if it is a BitmapCoreHeader or
                   2954:         // BitmapInfoHeader
                   2955:         //
1.1.1.3 ! root     2956:         // Does PM supports 16 and 32 bpp? How?
        !          2957:         //
1.1.1.2   root     2958:         if (bmch.bcSize == sizeof(BITMAPCOREHEADER))
                   2959:         {
                   2960:             wBitCount = bmch.bcBitCount;
                   2961:             iNumClr = ((wBitCount == 24) ? 0 : (1 << wBitCount));
                   2962:             sizBMI = sizeof(BITMAPCOREHEADER)+sizeof(RGBTRIPLE)*iNumClr;
1.1.1.3 ! root     2963:             bCoreHdr = TRUE;
1.1.1.2   root     2964:         }
                   2965:         else            // BITMAPINFOHEADER
                   2966:         {
                   2967:             wBitCount = bmih.biBitCount;
1.1.1.3 ! root     2968:             switch (wBitCount) {
        !          2969:                 case 16:
        !          2970:                 case 32:
        !          2971:                     sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(DWORD)*3;
        !          2972:                     break;
        !          2973:                 case 24:
        !          2974:                     sizBMI = sizeof(BITMAPINFOHEADER);
        !          2975:                     break;
        !          2976:                 default:
        !          2977:                     iNumClr = (1 << wBitCount);
        !          2978:                     sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*iNumClr;
        !          2979:                     break;
        !          2980:             }
        !          2981:             bCoreHdr = FALSE;
1.1.1.2   root     2982:         }
1.1       root     2983:     }
                   2984: 
                   2985:     if ((pbmi = (LPBITMAPINFO) LocalAlloc(LMEM_FIXED,sizBMI)) == NULL) {
                   2986:         MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
                   2987:         goto ErrExit3;
                   2988:     }
                   2989: 
                   2990:     //
                   2991:     // Make sure we pass in a DWORD aligned BitmapInfo to CreateDIBitmap
                   2992:     // Otherwise, exception on the MIPS platform
                   2993:     // CR!!!  Equivalent to memcpy
                   2994:     //
                   2995:     pjTmp = (PBYTE)pbmi;
                   2996: 
                   2997:     while(sizBMI--)
                   2998:     {
                   2999:         *(((PBYTE)pjTmp)++) = *(((PBYTE)pbmh)++);
                   3000:     }
                   3001: 
                   3002:     pMapFile = (PBYTE)pMapFile + ((BITMAPFILEHEADER *)pMapFile)->bfOffBits;
                   3003: 
1.1.1.3 ! root     3004: // !!! Use CreateBitmap for monochrome bitmap?
        !          3005: 
        !          3006:     //
        !          3007:     // Select the palette into the DC first before CreateDIBitmap()
        !          3008:     //
        !          3009:     bSelectDIBPal(hDC, pbmi, bCoreHdr);
        !          3010: 
        !          3011: // !!! We always pass a screen DC to this routine.
        !          3012: // !!! Maybe we should pass a metafile DC to this routine too.
        !          3013: // !!! The bitmap handle created for the screen DC won't give correct
        !          3014: // !!! color for the metafile DC.  So now, we always use the original
        !          3015: // !!! DIB info.
1.1       root     3016:     if ((hBitmap = CreateDIBitmap(hDC, (LPBITMAPINFOHEADER)pbmi,
                   3017:                         CBM_INIT, pMapFile, pbmi, DIB_RGB_COLORS)) == NULL) {
                   3018:         SetWindowText(ghTextWnd, "Fail in creating DIB bitmap from file!");
                   3019:         goto ErrExit4;
                   3020:     }
                   3021: 
1.1.1.3 ! root     3022:     // reset gbUseDIB flag, now that we have opened up a new DIB
        !          3023:     gbUseDIB = FALSE;
1.1       root     3024: 
1.1.1.3 ! root     3025: // !!! Always use the DIB info o.w. metafile DC don't get the right color.
        !          3026: #if 0
        !          3027:     if (GetDeviceCaps(hDC, BITSPIXEL) < wBitCount) {
        !          3028: #endif
        !          3029:         gbUseDIB = TRUE;
        !          3030:         bFreeDibFile(&gDib);
        !          3031:         pFileInfo = &(gDib.rgFileInfo[0]);
        !          3032:         pFileInfo->hFile        = hFile;
        !          3033:         pFileInfo->hMapFile     = hMapFile;
        !          3034:         pFileInfo->lpvMapView   = pMapFileTmp;
        !          3035: 
        !          3036:         gDib.rgpjFrame[0]       = pMapFile;
        !          3037:         gDib.rgpbmi[0]          = pbmi;
        !          3038:         gDib.rgbCoreHdr[0]      = bCoreHdr;
        !          3039:         gDib.ulFrames           =
        !          3040:         gDib.ulFiles            = 1;
        !          3041:         return (hBitmap);
        !          3042: #if 0
        !          3043:     }
        !          3044: #endif
1.1       root     3045: 
                   3046: ErrExit4:
                   3047:     LocalFree(pbmi);
                   3048: ErrExit3:
                   3049:     CloseHandle(hMapFile);
                   3050: ErrExit2:
                   3051:     CloseHandle(hFile);
                   3052: ErrExit1:
                   3053: 
                   3054:     return (hBitmap);
                   3055: 
                   3056: }
                   3057: 
1.1.1.3 ! root     3058: 
        !          3059: /******************************Public*Routine******************************\
        !          3060: *
        !          3061: * bFreeDibFile
        !          3062: *
        !          3063: * Effects:
        !          3064: *
        !          3065: * Warnings:
        !          3066: *
        !          3067: * History:
        !          3068: *  09-Feb-1993 -by- Petrus Wong
        !          3069: * Wrote it.
        !          3070: \**************************************************************************/
        !          3071: 
        !          3072: BOOL bFreeDibFile(PDIBDATA pDibData)
        !          3073: {
        !          3074:     ULONG               ulFiles;
        !          3075:     ULONG               ulFrames;
        !          3076:     ULONG               i;
        !          3077:     PFILEINFO           pFileInfo;
        !          3078: 
        !          3079:     ulFiles = pDibData->ulFiles;
        !          3080:     ulFrames = pDibData->ulFrames;
        !          3081: 
        !          3082:     for (i = 0; i < ulFrames; i++) {
        !          3083:         LocalFree(pDibData->rgpjFrame[i]);
        !          3084:         LocalFree(pDibData->rgpbmi[i]);
        !          3085:     }
        !          3086: 
        !          3087:     for (i = 0; i < ulFiles; i++) {
        !          3088:         pFileInfo = &(pDibData->rgFileInfo[i]);
        !          3089:         CloseHandle(pFileInfo->hFile);
        !          3090:         CloseHandle(pFileInfo->hMapFile);
        !          3091:         UnmapViewOfFile(pFileInfo->lpvMapView);
        !          3092:     }
        !          3093: 
        !          3094:     pDibData->ulFiles = 0;
        !          3095:     pDibData->ulFrames = 0;
        !          3096:     return TRUE;
        !          3097: }
        !          3098: 
        !          3099: 
        !          3100: 
        !          3101: 
1.1       root     3102: /******************************Public*Routine******************************\
                   3103: *
                   3104: * bGetBMP
                   3105: *
                   3106: * Effects: call common dialog and pass the filename to hBmpLoadBitmapFile
                   3107: *          return TRUE if successful, FALSE otherwise
                   3108: *
                   3109: * Warnings:
                   3110: *
                   3111: * History:
                   3112: *  13-May-1992 -by- Petrus Wong
                   3113: * Wrote it.
                   3114: \**************************************************************************/
                   3115: 
                   3116: BOOL bGetBMP(HWND hwnd, BOOL bMask) {
                   3117:     OPENFILENAME    ofn;
                   3118:     char            szFile[256], szFileTitle[256];
                   3119:     static char     *szFilter;
                   3120:     BOOL            bSuccess;
                   3121:     HDC             hDC;
                   3122: 
                   3123:     bSuccess = FALSE;
                   3124: 
                   3125:     szFilter =
                   3126:       "DIB files (*.bmp)\0*.bmp\0RLE files (*.rle)\0*.rle\0\0";
                   3127: 
                   3128:     strcpy(szFile, "*.bmp\0");
                   3129:     ofn.lStructSize = sizeof(OPENFILENAME);
                   3130:     ofn.hwndOwner = hwnd;
                   3131:     ofn.lpstrFilter = szFilter;
                   3132:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   3133:     ofn.nMaxCustFilter = 0L;
                   3134:     ofn.nFilterIndex = 1;
                   3135:     ofn.lpstrFile = szFile;
                   3136:     ofn.nMaxFile = sizeof(szFile);
                   3137:     ofn.lpstrFileTitle = szFileTitle;
                   3138:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   3139:     ofn.lpstrInitialDir = NULL;
                   3140:     ofn.lpstrTitle = (bMask ? "Load Mask" : "Load Bitmap");
                   3141:     ofn.Flags = 0L;
                   3142:     ofn.nFileOffset = 0;
                   3143:     ofn.nFileExtension = 0;
                   3144:     ofn.lpstrDefExt = "BMP";
                   3145: 
                   3146:     if (!GetOpenFileName(&ofn))
                   3147:         return 0L;
                   3148: 
                   3149:     hDC = GetDC(ghwndDrawSurf);
                   3150:     if (bMask) {
                   3151:         ghBmpMask = hBmpLoadBitmapFile(hDC, szFile);
                   3152:         if (ghBmpMask != NULL)
                   3153:             bSuccess = TRUE;
                   3154:     } else {
                   3155:         ghBmp = hBmpLoadBitmapFile(hDC, szFile);
                   3156:         if (ghBmp != NULL)
                   3157:             bSuccess = TRUE;
                   3158:     }
                   3159:     ReleaseDC(ghwndDrawSurf, hDC);
                   3160: 
                   3161:     return bSuccess;
                   3162: }
                   3163: 
                   3164: /******************************Public*Routine******************************\
                   3165: *
                   3166: * bHitTest
                   3167: *
                   3168: * Effects:  Enumerates metafile records
                   3169: *           Calling bDoHitTest to process each record found.
                   3170: *               The mouse position is passed to the bDoHitTest
                   3171: *
                   3172: * Warnings:
                   3173: *
                   3174: * History:
                   3175: *  20-May-1992 -by- Petrus Wong
                   3176: * Wrote it.
                   3177: \**************************************************************************/
                   3178: 
                   3179: BOOL bHitTest(HDC hDC, INT x, INT y) {
                   3180:     BOOL          bSuccess;
                   3181:     ENHMETAHEADER EnhMetaHdr;
1.1.1.3 ! root     3182:     RECT          rcClientDS;
1.1       root     3183:     HTDATA        htData;
1.1.1.2   root     3184:     static        HCURSOR hCurHT, hCurWait;
1.1       root     3185: 
                   3186:     bSuccess = TRUE;
                   3187: 
                   3188:     if (ghMetaf == 0)
                   3189:         return 0L;
                   3190: 
1.1.1.2   root     3191:     hCurHT = LoadCursor(NULL, IDC_CROSS);
                   3192:     hCurWait = LoadCursor(NULL, IDC_WAIT);
                   3193: 
1.1       root     3194:     GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
1.1.1.3 ! root     3195: 
1.1       root     3196:     htData.point.x = x;
                   3197:     htData.point.y = y;
                   3198:     htData.iRecord = EnhMetaHdr.nRecords;
1.1.1.2   root     3199: 
                   3200:     SetCursor(hCurWait);
1.1.1.3 ! root     3201:     if (gbFit2Wnd) {
        !          3202:         GetClientRect(ghwndDrawSurf, &rcClientDS);
        !          3203:         EnumEnhMetaFile(hDC, ghMetaf, (ENHMFENUMPROC)bDoHitTest, (LPVOID) &htData, (LPRECT)&rcClientDS);
        !          3204:     } else {
        !          3205:         RECT rc;
        !          3206: 
        !          3207:         rc.top = rc.left = 0;
        !          3208:         rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          3209:         rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          3210:         EnumEnhMetaFile(hDC, ghMetaf, (ENHMFENUMPROC)bDoHitTest, (LPVOID) &htData, (LPRECT)&rc);
        !          3211:     }
1.1.1.2   root     3212:     SetCursor(hCurHT);
1.1       root     3213: 
                   3214:     return bSuccess;
                   3215: }
                   3216: 
                   3217: /******************************Public*Routine******************************\
                   3218: *
                   3219: * bDoHitTest
                   3220: *
                   3221: * Effects:      Play all records related to transformation
                   3222: *               Remember new mouse position if the record is a MoveTo
                   3223: *               Convert rectangle, ellipse, lineto and bezier to path
                   3224: *               Widen the path and convert it to region.
                   3225: *               Test if the mouse position is inside the region.
                   3226: *
                   3227: * Warnings:     Only handle rectangle, ellipse, line and polybezier
                   3228: *
                   3229: * History:
                   3230: *  20-May-1992 -by- Petrus Wong
                   3231: * Wrote it.
                   3232: \**************************************************************************/
                   3233: 
                   3234: BOOL APIENTRY bDoHitTest(HDC hDC, LPHANDLETABLE lpHandleTable,
                   3235:                                   LPENHMETARECORD lpEnhMetaRecord,
                   3236:                                   UINT nHandles,
                   3237:                                   LPVOID lpData) {
                   3238:     BOOL            bSuccess;
                   3239:     char            ach[128];
                   3240:     char            achTmp[128];
                   3241:     POINT           PtOrg;
                   3242:     LONG            lNumDword;
                   3243:     XFORM           xfSave;
                   3244:     SIZE            SizeWndEx, SizeViewEx;
                   3245:     POINT           ptWndOrgin, ptViewOrgin;
                   3246:     int             i, iMode;
                   3247:     HRGN            hRgn;
                   3248:     PPOINT          pPt, pPtTmp;
                   3249:     static HGDIOBJ  hObjOld=NULL;
                   3250:     static LONG     lCurX=0;
                   3251:     static LONG     lCurY=0;
                   3252:     static BOOL     bXform=FALSE;
                   3253:     static int      iCnt=0;
                   3254: 
                   3255:     iCnt++;
                   3256: 
                   3257:     //
                   3258:     // select a wide pen for widen path later on
                   3259:     //
                   3260:     hObjOld = SelectObject(hDC, ghpnWide);
                   3261: 
                   3262:     //
                   3263:     // save the mouse hit position, this was passed in as a POINT structure
                   3264:     //
                   3265:     PtOrg.x = (((HTDATA *)lpData)->point).x;
                   3266:     PtOrg.y = (((HTDATA *)lpData)->point).y;
                   3267: 
                   3268:     //
                   3269:     // save the number of parameters for the GDI fcn concerned in DWORD.
                   3270:     // This is the total size of metafile record in question less the
                   3271:     // size of the GDI function
                   3272:     //
                   3273:     lNumDword = (lpEnhMetaRecord->nSize-8) / 4;
                   3274: 
                   3275:     switch (lpEnhMetaRecord->iType) {
                   3276:     case MR_SETWINDOWEXTEX:
                   3277:     case MR_SETWINDOWORGEX:
                   3278:     case MR_SETVIEWPORTEXTEX:
                   3279:     case MR_SETVIEWPORTORGEX:
                   3280:     case MR_SETMAPMODE:
                   3281:     case MR_SCALEVIEWPORTEXTEX:
                   3282:     case MR_SCALEWINDOWEXTEX:
                   3283:     case MR_SETMETARGN:
                   3284:     case MR_SAVEDC:
                   3285:     case MR_RESTOREDC:
                   3286:     case MR_SETWORLDTRANSFORM:
                   3287:     case MR_MODIFYWORLDTRANSFORM: {
                   3288:         //
1.1.1.2   root     3289:         // play all records related to transformation & font
1.1       root     3290:         //
                   3291:         PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   3292:                                    lpEnhMetaRecord, nHandles);
                   3293:         bXform = TRUE;
                   3294:         return TRUE;
                   3295:     }
                   3296:     //
                   3297:     // convert the following GDI calls to path for hit testing
                   3298:     //
                   3299:     case MR_RECTANGLE: {
                   3300:         BeginPath(hDC);
                   3301:         Rectangle(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1],
                   3302:                        lpEnhMetaRecord->dParm[2], lpEnhMetaRecord->dParm[3]);
                   3303:         EndPath(hDC);
                   3304:         break;
                   3305:     }
                   3306:     case MR_ELLIPSE: {
                   3307:         BeginPath(hDC);
                   3308:         Ellipse(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1],
                   3309:                      lpEnhMetaRecord->dParm[2], lpEnhMetaRecord->dParm[3]);
                   3310:         EndPath(hDC);
                   3311:         break;
                   3312:     }
                   3313:     case MR_MOVETOEX: {
                   3314:         //
                   3315:         // Remember our current position
                   3316:         //
                   3317:         lCurX = lpEnhMetaRecord->dParm[0];
                   3318:         lCurY = lpEnhMetaRecord->dParm[1];
                   3319:         return TRUE;
                   3320:     }
                   3321:     case MR_LINETO: {
                   3322:         BeginPath(hDC);
                   3323:         MoveToEx(hDC, lCurX, lCurY, NULL);
                   3324:         LineTo(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1]);
                   3325:         EndPath(hDC);
                   3326:         break;
                   3327:     }
                   3328:     case MR_POLYBEZIER16: {
                   3329:         int         i;
                   3330:         LONG        lSize;
                   3331:         LONG        lPtCnt;
                   3332: 
                   3333:         lPtCnt = lpEnhMetaRecord->dParm[4];
                   3334:         lSize = lPtCnt * sizeof(POINTL);
                   3335: 
                   3336:         if ((pPt = (PPOINT) LocalAlloc(LMEM_FIXED, lSize)) == NULL) {
                   3337:             SetWindowText(ghTextWnd, "ERROR: Failed in Memory Allocation: NO HIT");
                   3338:             return TRUE;
                   3339:         }
                   3340: 
                   3341:         pPtTmp = pPt;
                   3342: 
                   3343:         for (i=0; i < (INT) lPtCnt; i++, pPtTmp++) {
                   3344:             pPtTmp->x = (LONG)(LOWORD(lpEnhMetaRecord->dParm[i+5]));
                   3345:             pPtTmp->y = (LONG)(HIWORD(lpEnhMetaRecord->dParm[i+5]));
                   3346:         }
                   3347: 
                   3348:         BeginPath(hDC);
                   3349:         PolyBezier(hDC, (LPPOINT)pPt, (DWORD) lPtCnt);
                   3350:         EndPath(hDC);
                   3351:         LocalFree(pPt);
                   3352:         break;
                   3353:     }
                   3354:     default:
1.1.1.2   root     3355:         wsprintf((LPSTR) ach, "NO HIT: I don't Hit-Test %s", rgMetaName[lpEnhMetaRecord->iType]);
                   3356:         SetWindowText(ghTextWnd, ach);
1.1       root     3357:         return TRUE;
                   3358:     }   //switch
                   3359: 
                   3360:     if (bXform) {
                   3361:         //
                   3362:         // Set World transform to identity temporarily so that pen width
                   3363:         // is not affected by world to page transformation
                   3364:         //
                   3365:         GetWorldTransform(hDC, &xfSave);
                   3366:         ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   3367: 
                   3368:         //
                   3369:         // Set Page transform to identity temporarily so that pen width
                   3370:         // is not affected by page to device transformation
                   3371:         //
                   3372:         iMode = GetMapMode(hDC);
                   3373: 
                   3374:         if ((iMode == MM_ISOTROPIC) || (iMode == MM_ANISOTROPIC)) {
                   3375:             GetWindowOrgEx(hDC, &ptWndOrgin);
                   3376:             GetWindowExtEx(hDC, &SizeWndEx);
                   3377:             GetViewportExtEx(hDC, &SizeViewEx);
                   3378:             GetViewportOrgEx(hDC, &ptViewOrgin);
                   3379:         }
                   3380: 
                   3381:         SetMapMode(hDC, MM_TEXT);
                   3382:     }
                   3383: 
                   3384:     WidenPath(hDC);
                   3385: 
                   3386:     hRgn = PathToRegion(hDC);
                   3387: 
                   3388:     if (hRgn == 0) {
                   3389:         SetWindowText(ghTextWnd, "ERROR: Null Region: NO HIT");
                   3390:         DeleteObject(hRgn);
                   3391:         return TRUE;
                   3392:     }
                   3393:     //DPtoLP(hDC, &PtOrg, 1);
                   3394:     //SetPixel(hDC, PtOrg.x, PtOrg.y, RGB(0, 255, 0));
                   3395:     //
                   3396:     // test if mouse hit position is in region
                   3397:     //
                   3398:     bSuccess = PtInRegion(hRgn, PtOrg.x, PtOrg.y);
1.1.1.3 ! root     3399:     //Temporily comment this out
1.1.1.2   root     3400:     FillRgn(hDC, hRgn, ghbrRed);
1.1       root     3401:     DeleteObject(hRgn);
                   3402:     //
                   3403:     // Set transform back.
                   3404:     //
                   3405:     if (bXform) {
                   3406:         SetWorldTransform(hDC, &xfSave);
                   3407:         SetMapMode(hDC, iMode);
                   3408: 
                   3409:         if ((iMode == MM_ISOTROPIC) || (iMode == MM_ANISOTROPIC)) {
                   3410:             SetWindowOrgEx(hDC, ptWndOrgin.x, ptWndOrgin.y, NULL);
                   3411:             SetWindowExtEx(hDC, SizeWndEx.cx, SizeWndEx.cy, NULL);
                   3412:             SetViewportExtEx(hDC, SizeViewEx.cx, SizeViewEx.cy, NULL);
                   3413:             SetViewportOrgEx(hDC, ptViewOrgin.x, ptViewOrgin.y, NULL);
                   3414:         }
                   3415:     }
                   3416: 
                   3417:     if (bSuccess) {
                   3418:         Beep(440, 500);
                   3419:         //
                   3420:         // Reporting the metafile record number.  Then reset counter.
                   3421:         //
                   3422:         SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iCnt, FALSE);
                   3423:         iCnt=0;
                   3424:         wsprintf((LPSTR) ach, "HIT %s", rgMetaName[lpEnhMetaRecord->iType]);
                   3425: 
                   3426:         for (i=0; i < lNumDword; i++) {
                   3427:             wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   3428:             if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   3429:                 break;
                   3430:             strcat(ach, achTmp);
                   3431:         }
                   3432: 
                   3433:         SetWindowText(ghTextWnd, ach);
                   3434:         SelectObject(hDC, hObjOld);
                   3435:         bXform = FALSE;
                   3436:         return FALSE;
                   3437:     }
                   3438:     SetWindowText(ghTextWnd, "NO HIT");
                   3439:     if (iCnt >= ((HTDATA *)lpData)->iRecord)
                   3440:         iCnt = 0;
                   3441:     return TRUE;
                   3442: 
                   3443:     UNREFERENCED_PARAMETER(lpHandleTable);
                   3444:     UNREFERENCED_PARAMETER(nHandles);
                   3445: 
                   3446: }
                   3447: 
                   3448: /******************************Public*Routine******************************\
                   3449: *
                   3450: * bChooseNewFont
                   3451: *
                   3452: * Effects:
                   3453: *
                   3454: * Warnings:
                   3455: *
                   3456: * History:
                   3457: *  20-May-1992 -by- Petrus Wong
                   3458: * Wrote it.
                   3459: \**************************************************************************/
                   3460: 
                   3461: BOOL bChooseNewFont(HWND hwnd, PLOGFONT plf, COLORREF *pClrRef) {
1.1.1.3 ! root     3462:    HDC                  hDC;
        !          3463:    static CHOOSEFONT    chf;
        !          3464:    static BOOL          bInit=TRUE;
        !          3465: 
        !          3466: 
        !          3467:    if (bInit) {
        !          3468:         bInit = FALSE;
        !          3469: 
        !          3470:         hDC = GetDC( hwnd );
        !          3471:         chf.hDC = CreateCompatibleDC( hDC );
        !          3472:         ReleaseDC( hwnd, hDC );
        !          3473: 
        !          3474:         chf.lStructSize = sizeof(CHOOSEFONT);
        !          3475:         chf.hwndOwner = hwnd;
        !          3476:         chf.lpLogFont = plf;
        !          3477:         chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
        !          3478:         chf.rgbColors = *pClrRef;
        !          3479:         chf.lCustData = 0;
        !          3480:         chf.hInstance = (HANDLE)NULL;
        !          3481:         chf.lpszStyle = (LPSTR)NULL;
        !          3482:         chf.nFontType = SCREEN_FONTTYPE;
        !          3483:         chf.nSizeMin = 0;
        !          3484:         chf.nSizeMax = 0;
        !          3485:         chf.lpfnHook = (LPCFHOOKPROC)NULL;
        !          3486:         chf.lpTemplateName = (LPSTR)NULL;
        !          3487:    }
1.1       root     3488: 
                   3489:    if (ChooseFont( &chf ) == FALSE ) {
                   3490:         DeleteDC( hDC );
                   3491:        return FALSE;
                   3492:    }
                   3493: 
                   3494:    *pClrRef = chf.rgbColors;
                   3495: 
                   3496:    DeleteDC( hDC );
                   3497:    return (TRUE);
                   3498: }
                   3499: 
                   3500: /******************************Public*Routine******************************\
                   3501: *
                   3502: * bChooseNewColor
                   3503: *
                   3504: * Effects:  Returns TRUE if successful; lpdwRGB points the color selected.
                   3505: *           Otherwise, FALSE.
                   3506: *
                   3507: * Warnings:
                   3508: *
                   3509: * History:
                   3510: *  21-May-1992 -by- Petrus Wong
                   3511: * Wrote it.
                   3512: \**************************************************************************/
                   3513: 
                   3514: BOOL bChooseNewColor(HWND hwnd, LPDWORD lpdwRGB) {
                   3515:     static DWORD argbCust[16] = {
                   3516:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3517:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3518:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3519:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3520:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3521:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3522:         RGB(255, 255, 255), RGB(255, 255, 255),
                   3523:         RGB(255, 255, 255), RGB(255, 255, 255)
                   3524:     };
                   3525:     CHOOSECOLOR cc;
                   3526:     BOOL bResult;
                   3527: 
                   3528:     cc.lStructSize = sizeof(CHOOSECOLOR);
                   3529:     cc.hwndOwner = hwnd;
                   3530:     cc.hInstance = ghModule;
                   3531:     cc.rgbResult = *lpdwRGB;
                   3532:     cc.lpCustColors = argbCust;
                   3533:     cc.Flags = CC_RGBINIT | CC_SHOWHELP;
                   3534:     cc.lCustData = 0;
                   3535:     cc.lpfnHook = NULL;
                   3536:     cc.lpTemplateName = NULL;
                   3537: 
                   3538:     bResult = ChooseColor(&cc);
                   3539: 
                   3540:     if (bResult) {
                   3541:         *lpdwRGB = cc.rgbResult;
                   3542:         return TRUE;
                   3543:     }
                   3544: 
                   3545:     return FALSE;
                   3546: }
                   3547: 
                   3548: 
                   3549: /******************************Public*Routine******************************\
                   3550: *
                   3551: * hBrCreateBrush
                   3552: *
                   3553: * Effects: Creates a brush with the specified RGB
                   3554: *
                   3555: * Warnings:
                   3556: *
                   3557: * History:
                   3558: *  04-Mar-1992 -by- Petrus Wong
                   3559: * Wrote it.
                   3560: \**************************************************************************/
                   3561: 
                   3562: HBRUSH hBrCreateBrush(HDC hDC, DWORD dwRGB)
                   3563: {
                   3564:     HDC hdcMem;
                   3565:     HBRUSH hbr;
                   3566:     HBRUSH hbrOld;
                   3567:     HBITMAP hbmPat;
                   3568:     HBITMAP hbmOld;
                   3569: 
                   3570:     hbr = CreateSolidBrush(dwRGB);
                   3571:     hdcMem = CreateCompatibleDC(hDC);
                   3572: 
                   3573:     //
                   3574:     // Minimum size for a bitmap to be used in a fill pattern is 8x8
                   3575:     //
                   3576:     hbmPat = CreateCompatibleBitmap(hDC, 8, 8);
                   3577: 
                   3578:     hbmOld = SelectObject(hdcMem, hbmPat);
                   3579:     hbrOld = SelectObject(hdcMem, hbr);
                   3580:     PatBlt(hdcMem, 0, 0, 8, 8, PATCOPY);
                   3581: 
                   3582:     //
                   3583:     // Deselect hbmPat and hbr
                   3584:     //
                   3585:     SelectObject(hdcMem, hbmOld);
                   3586:     SelectObject(hdcMem, hbrOld);
                   3587: 
                   3588:     DeleteDC(hdcMem);
                   3589:     DeleteObject(hbr);
                   3590: 
                   3591:     hbr = CreatePatternBrush(hbmPat);
                   3592: 
                   3593:     DeleteObject(hbmPat);
                   3594: 
                   3595:     return hbr;
                   3596: }
1.1.1.3 ! root     3597: 
        !          3598: 
        !          3599: /******************************Public*Routine******************************\
        !          3600: *
        !          3601: * bPrintMf  Brings up the print dialog for printer setup and then
        !          3602: *           starts printing the enhanced metafile.
        !          3603: *
        !          3604: *           pPD     Points to a PRTDATA structure that contains the
        !          3605: *                   the handle for the Enh. Metafile for printing.
        !          3606: *
        !          3607: * Effects:  Returns TRUE if sucessful.  Otherwise, it is FALSE.
        !          3608: *           GlobalFree pPD when exits.
        !          3609: *
        !          3610: * Warnings:
        !          3611: *
        !          3612: * History:
        !          3613: *  22-Oct-1992 -by- Petrus Wong
        !          3614: * Wrote it.
        !          3615: \**************************************************************************/
        !          3616: 
        !          3617: BOOL bPrintMf(PPRTDATA pPD) {
        !          3618:     DOCINFO         DocInfo;
        !          3619:     HDC             hDCPrinter;
        !          3620:     ENHMETAHEADER   EnhMetaHdr;
        !          3621:     HENHMETAFILE    hEnhMf;
        !          3622:     TCHAR           buf[128];
        !          3623:     PRINTDLG        pd;
        !          3624:     BOOL            bSuccess;
        !          3625:     int             iEntries;
        !          3626:     PLOGPALETTE     plogPal;
        !          3627:     PBYTE           pjTmp;
        !          3628:     HPALETTE        hPal;
        !          3629: 
        !          3630: 
        !          3631:     bSuccess = TRUE;
        !          3632: 
        !          3633:     if (pPD->hMetaf == 0) {
        !          3634:         SetWindowText(ghTextWnd, "NO Metafile to print");
        !          3635:         goto PMF_EXIT;
        !          3636:         bSuccess = FALSE;
        !          3637:     }
        !          3638: 
        !          3639:     hEnhMf = CopyEnhMetaFile(pPD->hMetaf, NULL);
        !          3640:     pd.lStructSize = sizeof(PRINTDLG);
        !          3641:     pd.hwndOwner   = ghwndMain;
        !          3642:     pd.Flags       = PD_RETURNDC;
        !          3643:     pd.hInstance   = ghModule;
        !          3644: 
        !          3645:     if (!PrintDlg(&pd)) {
        !          3646:         SetWindowText(ghTextWnd, "Cancel Printing");
        !          3647:         goto PMF_EXIT;
        !          3648:         bSuccess = FALSE;
        !          3649:     }
        !          3650: 
        !          3651: 
        !          3652:     if (pd.hDC == NULL) {
        !          3653:         SetWindowText(ghTextWnd, "Failed in creating printer DC");
        !          3654:         goto PMF_EXIT;
        !          3655:         bSuccess = FALSE;
        !          3656:     }
        !          3657: 
        !          3658:     hDCPrinter = pd.hDC;
        !          3659:     GetEnhMetaFileDescription(hEnhMf, 128, (LPTSTR)buf);
        !          3660: 
        !          3661:     DocInfo.cbSize      = sizeof(DOCINFO);
        !          3662:     DocInfo.lpszDocName = (LPTSTR) buf;
        !          3663:     DocInfo.lpszOutput  = NULL;
        !          3664:     StartDoc(hDCPrinter, &DocInfo);
        !          3665:     StartPage(hDCPrinter);
        !          3666: 
        !          3667:     SetWindowText(ghTextWnd, "Printing...");
        !          3668: 
        !          3669:     iEntries = GetEnhMetaFilePaletteEntries(hEnhMf, 0, NULL);
        !          3670: 
        !          3671:     if (iEntries) {
        !          3672:         if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          3673:                 sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) {
        !          3674:             MessageBox(ghwndMain, "Failed in Creating Palette!", "Error", MB_OK);
        !          3675:         }
        !          3676: 
        !          3677:         plogPal->palVersion = 0x300;
        !          3678:         plogPal->palNumEntries = (WORD) iEntries;
        !          3679:         pjTmp = (PBYTE) plogPal;
        !          3680:         pjTmp += 8;
        !          3681: 
        !          3682:         GetEnhMetaFilePaletteEntries(hEnhMf, iEntries, (PPALETTEENTRY)pjTmp);
        !          3683:         hPal = CreatePalette(plogPal);
        !          3684:         GlobalFree(plogPal);
        !          3685: 
        !          3686:         SelectPalette(hDCPrinter, hPal, FALSE);
        !          3687:         RealizePalette(hDCPrinter);
        !          3688:     }
        !          3689: 
        !          3690:     if (pPD->bFit2Wnd) {
        !          3691:         int     iWidth, iHeight;
        !          3692:         RECT    rc;
        !          3693: 
        !          3694:         iWidth = GetDeviceCaps(hDCPrinter, HORZRES);
        !          3695:         iHeight = GetDeviceCaps(hDCPrinter, VERTRES);
        !          3696:         rc.left = rc.top = 0;
        !          3697:         rc.right = iWidth;
        !          3698:         rc.bottom = iHeight;
        !          3699:         bSuccess = PlayEnhMetaFile(hDCPrinter, hEnhMf, (LPRECT) &rc);
        !          3700:         if (!bSuccess) {
        !          3701:             char    text[128];
        !          3702: 
        !          3703:             wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          3704:             OutputDebugString(text);
        !          3705:         }
        !          3706: 
        !          3707: 
        !          3708:     } else {
        !          3709:         GetEnhMetaFileHeader(hEnhMf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
        !          3710:         {
        !          3711:         RECT rc;
        !          3712: 
        !          3713:         rc.top = rc.left = 0;
        !          3714:         rc.right = EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left;
        !          3715:         rc.bottom = EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top;
        !          3716:         bSuccess = PlayEnhMetaFile(hDCPrinter, hEnhMf, (LPRECT) &rc);
        !          3717:         if (!bSuccess) {
        !          3718:             char    text[128];
        !          3719: 
        !          3720:             wsprintf(text, "Fail in PlayEnhMetaFile! Error %ld\n", GetLastError());
        !          3721:             OutputDebugString(text);
        !          3722:         }
        !          3723: 
        !          3724:         }
        !          3725:     }
        !          3726: 
        !          3727:     EndPage(hDCPrinter);
        !          3728:     EndDoc(hDCPrinter);
        !          3729:     SetWindowText(ghTextWnd, "Printing Thread Done...");
        !          3730: 
        !          3731: PMF_EXIT:
        !          3732: 
        !          3733:     ExitThread(0);
        !          3734:     GlobalFree(pPD);
        !          3735:     return bSuccess;
        !          3736: 
        !          3737: }
        !          3738: 
        !          3739: /******************************Public*Routine******************************\
        !          3740: *
        !          3741: * bSelectDIBPal
        !          3742: *
        !          3743: * Effects: Creates a logical palette from the DIB and select it into the DC
        !          3744: *          and realize the palette. Saving the hPal in the ghPal
        !          3745: *
        !          3746: * Warnings: Based on Windows NT DIB support.  If PM support 16,24,32 bpp
        !          3747: *           we need to modify this routine.
        !          3748: *           Global alert! ghPal is changed here...
        !          3749: *
        !          3750: * History:
        !          3751: *  22-Jan-1993      Petrus Wong         PM support
        !          3752: *  31-Dec-1992 -by- Petrus Wong
        !          3753: * Wrote it.
        !          3754: \**************************************************************************/
        !          3755: 
        !          3756: BOOL bSelectDIBPal(HDC hDC, LPBITMAPINFO pbmi, BOOL bCoreHdr)
        !          3757: {
        !          3758:   LOGPALETTE    *plogPal;
        !          3759:   UINT          uiSizPal;
        !          3760:   INT           i, iNumClr;
        !          3761:   WORD          wBitCount;
        !          3762: 
        !          3763:   if (bCoreHdr) {
        !          3764:     wBitCount = ((LPBITMAPCOREINFO)pbmi)->bmciHeader.bcBitCount;
        !          3765:   } else {
        !          3766:     wBitCount = pbmi->bmiHeader.biBitCount;
        !          3767:   }
        !          3768: 
        !          3769:   switch (wBitCount) {
        !          3770:     case 16:
        !          3771:     case 24:
        !          3772:     case 32:                            // Does PM supports these?
        !          3773:         return FALSE;
        !          3774:     default:
        !          3775:         iNumClr = (1 << wBitCount);
        !          3776:         break;
        !          3777:   }
        !          3778: 
        !          3779:   uiSizPal = sizeof(WORD)*2 + sizeof(PALETTEENTRY)*iNumClr;
        !          3780:   if ((plogPal = (LOGPALETTE *) LocalAlloc(LMEM_FIXED,uiSizPal)) == NULL) {
        !          3781:       MessageBox(ghwndMain, "Fail in Allocating palette!", "Error", MB_OK);
        !          3782:       ghPal = NULL;
        !          3783:       return FALSE;
        !          3784:   }
        !          3785: 
        !          3786:   plogPal->palVersion = 0x300;
        !          3787:   plogPal->palNumEntries = (WORD) iNumClr;
        !          3788: 
        !          3789:   if (bCoreHdr) {
        !          3790:     for (i=0; i<iNumClr; i++) {
        !          3791:         plogPal->palPalEntry[i].peRed   = ((LPBITMAPCOREINFO)pbmi)->bmciColors[i].rgbtRed;
        !          3792:         plogPal->palPalEntry[i].peGreen = ((LPBITMAPCOREINFO)pbmi)->bmciColors[i].rgbtGreen;
        !          3793:         plogPal->palPalEntry[i].peBlue  = ((LPBITMAPCOREINFO)pbmi)->bmciColors[i].rgbtBlue;
        !          3794:         plogPal->palPalEntry[i].peFlags = PC_RESERVED;
        !          3795:     }
        !          3796:   } else {
        !          3797:     for (i=0; i<iNumClr; i++) {
        !          3798:         plogPal->palPalEntry[i].peRed   = pbmi->bmiColors[i].rgbRed;
        !          3799:         plogPal->palPalEntry[i].peGreen = pbmi->bmiColors[i].rgbGreen;
        !          3800:         plogPal->palPalEntry[i].peBlue  = pbmi->bmiColors[i].rgbBlue;
        !          3801:         plogPal->palPalEntry[i].peFlags = PC_RESERVED;
        !          3802:     }
        !          3803:   }
        !          3804: 
        !          3805:   DeleteObject(ghPal);
        !          3806:   ghPal = CreatePalette((LPLOGPALETTE)plogPal);
        !          3807:   if ((ghPal) == NULL) {
        !          3808:       MessageBox(ghwndMain, "Fail in creating palette!", "Error", MB_OK);
        !          3809:       return FALSE;
        !          3810:   }
        !          3811: 
        !          3812:   if ((GetDeviceCaps(hDC, RASTERCAPS)) & RC_PALETTE) {
        !          3813:     SelectPalette(hDC, ghPal, FALSE);
        !          3814:     RealizePalette(hDC);
        !          3815:   }
        !          3816: 
        !          3817:   GlobalFree(plogPal);
        !          3818: 
        !          3819:   return TRUE;
        !          3820: }
        !          3821: 
        !          3822: 
        !          3823: /******************************Public*Routine******************************\
        !          3824: *
        !          3825: * bPlgBlt
        !          3826: *
        !          3827: * Effects:  If Source DIB bpp > Destination DC's
        !          3828: *           use Halftone for PlgBlt.
        !          3829: *
        !          3830: * Warnings: Global Alert!
        !          3831: *           gbUseDIB is always TRUE now.
        !          3832: *
        !          3833: * History:
        !          3834: *  12-Mar-1993      Petrus Wong     fixed clr problem on playback (non-HT)
        !          3835: *  18-Feb-1993      Petrus Wong     fixed clr problem on playback (HT)
        !          3836: *  10-Feb-1993 -by- Petrus Wong
        !          3837: * Wrote it.
        !          3838: \**************************************************************************/
        !          3839: 
        !          3840: BOOL bPlgBlt(HDC hDC, LPPOINT rgPtsBMP)
        !          3841: {
        !          3842:     HDC                  hDCRef;
        !          3843:     HDC                  hDCSrn;                // hDC can be metaf DC
        !          3844:     HGDIOBJ              hObjOld, hBmpMem;
        !          3845:     BITMAP               bm;
        !          3846:     INT                  iBpp;
        !          3847:     WORD                 wBitCnt;
        !          3848: 
        !          3849: 
        !          3850:     hDCSrn = GetDC(ghwndDrawSurf);
        !          3851:     hDCRef = CreateCompatibleDC(hDC);
        !          3852: 
        !          3853:     if (gbUseDIB) {
        !          3854:         int         cx, cy, dx, dy;
        !          3855:         PBITMAPINFO pbmi;
        !          3856: 
        !          3857:         pbmi = (gDib.rgpbmi[0]);
        !          3858:         dx = rgPtsBMP[0].x - rgPtsBMP[1].x;
        !          3859:         dy = rgPtsBMP[0].y - rgPtsBMP[1].y;
        !          3860:         cx = (INT) sqrt( dx * dx + dy * dy );
        !          3861: 
        !          3862:         dx = rgPtsBMP[0].x - rgPtsBMP[2].x;
        !          3863:         dy = rgPtsBMP[0].y - rgPtsBMP[2].y;
        !          3864:         cy = (INT) sqrt( dx * dx + dy * dy );
        !          3865: 
        !          3866:         iBpp = GetDeviceCaps(hDC, BITSPIXEL);
        !          3867: 
        !          3868:         if (gDib.rgbCoreHdr[0]) {
        !          3869:             wBitCnt = ((LPBITMAPCOREINFO)pbmi)->bmciHeader.bcBitCount;
        !          3870:         } else {
        !          3871:             wBitCnt = pbmi->bmiHeader.biBitCount;
        !          3872:         }
        !          3873: 
        !          3874:         if (iBpp < wBitCnt) {   // Do Halftone
        !          3875:             SetStretchBltMode(hDCRef, HALFTONE);
        !          3876:             if (ghHT) {
        !          3877:                 SelectPalette(hDCRef, ghHT, FALSE);
        !          3878:                 SelectPalette(hDC, ghHT, FALSE);
        !          3879:                 SelectPalette(hDCSrn, ghHT, FALSE); // hDC can be metaf DC
        !          3880:                 RealizePalette(hDCSrn);             // always realize the srn DC
        !          3881: 
        !          3882:                 // Don't have to realize the palette in hDCRef
        !          3883:                 // RealizePalette(hDCRef);
        !          3884: 
        !          3885:                 // has to be compatible with screen DC, cannot be hDCRef
        !          3886:                 // memory DC has no bitmap by default?
        !          3887:                 // hDC may be a metafile DC, so use hDCSrn
        !          3888:                 hBmpMem = CreateCompatibleBitmap(hDCSrn, cx, cy);
        !          3889:                 SelectObject(hDCRef, hBmpMem);
        !          3890:             } else {
        !          3891:                 MessageBox(ghwndMain, "Halftone palette is null!", "Error", MB_OK);
        !          3892:             }
        !          3893:         } else {
        !          3894:             SetStretchBltMode(hDCRef, COLORONCOLOR);
        !          3895:             if (ghPal) {
        !          3896:                 if (ghDCMetaf == hDC)
        !          3897:                     CopyPalette(ghPal);
        !          3898:                 SelectPalette(hDCRef, ghPal, FALSE);
        !          3899:                 SelectPalette(hDC, ghPal, FALSE);
        !          3900:                 SelectPalette(hDCSrn, ghPal, FALSE); // hDC can be metaf DC
        !          3901:                 RealizePalette(hDCSrn);             // always realize the srn DC
        !          3902: 
        !          3903:                 // Don't have to realize the palette in hDCRef
        !          3904:                 // RealizePalette(hDCRef);
        !          3905: 
        !          3906:                 // has to be compatible with screen DC, cannot be hDCRef
        !          3907:                 // memory DC has no bitmap by default?
        !          3908:                 // hDC may be a metafile DC, so use hDCSrn
        !          3909:                 hBmpMem = CreateCompatibleBitmap(hDCSrn, cx, cy);
        !          3910:                 SelectObject(hDCRef, hBmpMem);
        !          3911:             } else {
        !          3912:                 MessageBox(ghwndMain, "Palette is null!", "Error", MB_OK);
        !          3913:             }
        !          3914:         }
        !          3915: 
        !          3916:         if (gDib.rgbCoreHdr[0]) {
        !          3917:             StretchDIBits(hDCRef, 0,0, cx, cy,
        !          3918:                           0,0, ((LPBITMAPCOREINFO)pbmi)->bmciHeader.bcWidth, ((LPBITMAPCOREINFO)pbmi)->bmciHeader.bcHeight,
        !          3919:                           gDib.rgpjFrame[0], pbmi, DIB_RGB_COLORS, SRCCOPY);
        !          3920:         } else {
        !          3921:             StretchDIBits(hDCRef, 0,0, cx, cy,
        !          3922:                           0,0, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight,
        !          3923:                           gDib.rgpjFrame[0], pbmi, DIB_RGB_COLORS, SRCCOPY);
        !          3924:         }
        !          3925: 
        !          3926:         PlgBlt(hDC, rgPtsBMP, hDCRef, 0, 0, cx, cy,
        !          3927:                ghBmpMask, 0, 0);
        !          3928: 
        !          3929:         DeleteObject(hBmpMem);
        !          3930: 
        !          3931:     } else {
        !          3932:         hObjOld = SelectObject(hDCRef, ghBmp);
        !          3933: 
        !          3934:         GetObject(ghBmpMask, sizeof(BITMAP), (LPSTR)&bm);
        !          3935:         if (bm.bmBitsPixel != 1) {
        !          3936:             SetWindowText(ghTextWnd, "ERROR: Mask has to be a Monochrome bitmap!");
        !          3937:             ghBmpMask = NULL;
        !          3938:         }
        !          3939: 
        !          3940:         GetObject(ghBmp, sizeof(BITMAP), (LPSTR)&bm);
        !          3941: 
        !          3942:         if (ghPal) {
        !          3943:             SelectPalette(hDC, ghPal, FALSE);
        !          3944:             RealizePalette(hDC);
        !          3945:             SetStretchBltMode(hDC, COLORONCOLOR);
        !          3946:         }
        !          3947:         PlgBlt(hDC, rgPtsBMP, hDCRef, 0, 0, bm.bmWidth, bm.bmHeight,
        !          3948:                ghBmpMask, 0, 0);
        !          3949: 
        !          3950:         SelectObject(hDCRef, hObjOld);
        !          3951:     }
        !          3952: 
        !          3953:     DeleteDC(hDCRef);
        !          3954:     ReleaseDC(ghwndDrawSurf, hDCSrn);
        !          3955:     return TRUE;
        !          3956: 
        !          3957: }
        !          3958: 
        !          3959: 
        !          3960: 
        !          3961: /******************************Public*Routine******************************\
        !          3962: *
        !          3963: * HPALETTE CopyPalette
        !          3964: *
        !          3965: * Effects:
        !          3966: *
        !          3967: * Warnings:
        !          3968: *
        !          3969: * History:
        !          3970: *  18-Sep-1992 -by- Petrus Wong
        !          3971: * Wrote it.
        !          3972: \**************************************************************************/
        !          3973: 
        !          3974: HPALETTE CopyPalette(HPALETTE hPalSrc)
        !          3975: {
        !          3976:     PLOGPALETTE     plogPal;
        !          3977:     PBYTE           pjTmp;
        !          3978:     int             iNumEntries=0;
        !          3979:     HPALETTE        hPal;
        !          3980: 
        !          3981:     if ((iNumEntries = GetPaletteEntries(hPalSrc, 0, iNumEntries, NULL)) == 0) {
        !          3982:         MessageBox(ghwndMain, "No entry in palette to copy!", "Error", MB_OK);
        !          3983:         return (HPALETTE) NULL;
        !          3984:     }
        !          3985: 
        !          3986:     if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !          3987:             sizeof(DWORD) + sizeof(PALETTEENTRY)*iNumEntries )) == NULL) {
        !          3988:         MessageBox(ghwndMain, "Failed in CopyPalette!", "Error", MB_OK);
        !          3989:         return (HPALETTE) NULL;
        !          3990:     }
        !          3991: 
        !          3992:     plogPal->palVersion = 0x300;
        !          3993:     plogPal->palNumEntries = (WORD) iNumEntries;
        !          3994:     pjTmp = (PBYTE) plogPal;
        !          3995:     pjTmp += 8;
        !          3996:     GetPaletteEntries(hPalSrc, 0, iNumEntries, (PPALETTEENTRY)pjTmp);
        !          3997:     hPal = CreatePalette(plogPal);
        !          3998: 
        !          3999:     GlobalFree(plogPal);
        !          4000: 
        !          4001:     return hPal;
        !          4002: }
        !          4003: 
        !          4004: 
        !          4005: 
        !          4006: 
        !          4007: /******************************Public*Routine******************************\
        !          4008: *
        !          4009: * iTT
        !          4010: *
        !          4011: * Effects: set the global variable gbTT if the family is true type
        !          4012: *
        !          4013: * Warnings:
        !          4014: *
        !          4015: * History:
        !          4016: *  29-Apr-1993 -by- Petrus Wong
        !          4017: * Wrote it.
        !          4018: \**************************************************************************/
        !          4019: 
        !          4020: int CALLBACK iTT(
        !          4021:     LPLOGFONT    lpLF,
        !          4022:     LPTEXTMETRIC lpTM,
        !          4023:     DWORD        dwFontType,
        !          4024:     LPARAM       lpData)
        !          4025: {
        !          4026: 
        !          4027:     if (lpTM->tmPitchAndFamily & TMPF_TRUETYPE) {
        !          4028:         //OutputDebugString("TRUETYPE\n");
        !          4029:         *((BOOL *)lpData) = TRUE;
        !          4030:     } else {
        !          4031:         //OutputDebugString("NON-TRUETYPE\n");
        !          4032:         *((BOOL *)lpData) = FALSE;
        !          4033:     }
        !          4034: 
        !          4035: #if 0
        !          4036:     //
        !          4037:     // that's equivalent
        !          4038:     //
        !          4039:     if (dwFontType & TRUETYPE_FONTTYPE) {
        !          4040:         //OutputDebugString("TRUETYPE\n");
        !          4041:         *((BOOL *)lpData) = TRUE;
        !          4042:     } else {
        !          4043:         //OutputDebugString("NON-TRUETYPE\n");
        !          4044:         *((BOOL *)lpData) = FALSE;
        !          4045:     }
        !          4046: #endif
        !          4047:     return 0;
        !          4048: 
        !          4049:     UNREFERENCED_PARAMETER (lpLF);
        !          4050:     //UNREFERENCED_PARAMETER (lpTM);
        !          4051:     UNREFERENCED_PARAMETER (dwFontType);
        !          4052: 
        !          4053: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.