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

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>
                     38: 
1.1.1.2 ! root       39: 
1.1       root       40: //
                     41: // Forward declarations.
                     42: //
                     43: BOOL InitializeApp   (void);
1.1.1.2 ! root       44: LONG APIENTRY MainWndProc     (HWND, UINT, DWORD, LONG);
        !            45: LONG APIENTRY DrawSurfWndProc (HWND, UINT, DWORD, LONG);
        !            46: LONG APIENTRY About         (HWND, UINT, DWORD, LONG);
        !            47: LONG APIENTRY TextWndProc     (HWND, UINT, DWORD, LONG);
        !            48: LONG APIENTRY CtrlPanelDlgProc(HWND, UINT, DWORD, LONG);
1.1       root       49: BOOL bDrawStuff      (HDC, INT, INT, INT, INT, BOOL, BOOL, BOOL, LPSTR);
                     50: HENHMETAFILE hemfLoadMetafile(HWND);
                     51: HDC  hDCRecordMetafileAs(HWND, LPSTR);
                     52: BOOL APIENTRY bPlayRecord(HDC, LPHANDLETABLE, LPENHMETARECORD, UINT, LPVOID);
                     53: BOOL APIENTRY bDoHitTest(HDC, LPHANDLETABLE, LPENHMETARECORD, UINT, LPVOID);
                     54: BOOL bHitTest(HDC, INT, INT);
                     55: HBITMAP hBmpLoadBitmapFile(HDC, PSTR);
                     56: BOOL bGetBMP(HWND, BOOL);
                     57: BOOL bChooseNewFont(HWND, PLOGFONT, COLORREF * );
                     58: BOOL bChooseNewColor(HWND, LPDWORD);
                     59: HBRUSH hBrCreateBrush(HDC, DWORD);
1.1.1.2 ! root       60: extern int FAR PASCAL ShellAbout(HWND, LPCSTR, LPCSTR, HICON);
1.1       root       61: 
                     62: /***************************************************************************\
                     63: * WinMain
                     64: *
                     65: * History:
                     66: * 11-Feb-1992   Petrus Wong
                     67: \***************************************************************************/
1.1.1.2 ! root       68: int APIENTRY WinMain(
        !            69:            HANDLE hInstance,
        !            70:            HANDLE hPrevInstance,
        !            71:            LPSTR lpCmdLine,
        !            72:            int nShowCmd)
1.1       root       73: {
                     74:     MSG    msg;
                     75:     HANDLE hAccel;
                     76: 
                     77:     ghModule = GetModuleHandle(NULL);
                     78:     if (!InitializeApp()) {
                     79:        MessageBox(ghwndMain, "MfEdit: InitializeApp failure!", "Error", MB_OK);
                     80:         return 0;
                     81:     }
                     82: 
                     83:     if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
                     84:        MessageBox(ghwndMain, "MfEdit: Load Accel failure!", "Error", MB_OK);
                     85: 
                     86: 
                     87:     while (GetMessage(&msg, NULL, 0, 0)) {
                     88:         if (!TranslateAccelerator( ghwndMain, hAccel, &msg) ) {
                     89:             TranslateMessage(&msg);
                     90:             DispatchMessage(&msg);
                     91:         }
                     92:     }
                     93: 
                     94:     return 1;
                     95: 
                     96:     UNREFERENCED_PARAMETER(lpCmdLine);
                     97:     UNREFERENCED_PARAMETER(nShowCmd);
                     98:     UNREFERENCED_PARAMETER(hInstance);
                     99:     UNREFERENCED_PARAMETER(hPrevInstance);
                    100: }
                    101: 
                    102: 
                    103: /***************************************************************************\
                    104: * InitializeApp
                    105: *
                    106: * History:
                    107: * 11-Feb-1992   Petrus Wong
                    108: *   Name changes.
                    109: * 09-09-91      Petrus Wong    Created.
                    110: \***************************************************************************/
                    111: 
                    112: BOOL InitializeApp(void)
                    113: {
                    114:     WNDCLASS wc;
                    115:     int index;
                    116: 
                    117:     wc.style            = CS_DBLCLKS;
                    118:     wc.lpfnWndProc      = (WNDPROC)MainWndProc;
                    119:     wc.cbClsExtra       = 0;
                    120:     wc.cbWndExtra      = sizeof(DWORD);
                    121:     wc.hInstance        = ghModule;
                    122:     wc.hIcon            = LoadIcon(ghModule, MAKEINTRESOURCE(APPICON));
                    123:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
                    124:     wc.hbrBackground   = (HBRUSH)(COLOR_APPWORKSPACE + 1);
                    125:     wc.lpszMenuName     = "MainMenu";
                    126:     wc.lpszClassName   = "MetafDemoClass";
                    127: 
                    128:     if (!RegisterClass(&wc))
                    129:        return FALSE;
                    130: 
                    131:     wc.style            = CS_OWNDC | CS_SAVEBITS;
                    132:     wc.lpfnWndProc      = (WNDPROC)DrawSurfWndProc;
                    133:     wc.hIcon            = NULL;
                    134:     wc.hCursor          = NULL;
                    135:     wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);
                    136:     wc.lpszMenuName     = NULL;
                    137:     wc.lpszClassName    = "DrawSurfClass";
                    138: 
                    139:     if (!RegisterClass(&wc))
                    140:        return FALSE;
                    141: 
                    142:     wc.style           = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
                    143:     wc.lpfnWndProc     = (WNDPROC)TextWndProc;
                    144:     wc.hIcon           = NULL;
                    145:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
                    146:     wc.hbrBackground   = (HBRUSH)(COLOR_BTNFACE + 1);
                    147:     wc.lpszMenuName    = NULL;
                    148:     wc.lpszClassName   = "Text";
                    149: 
                    150:     if (!RegisterClass(&wc))
                    151:             return FALSE;
                    152: 
                    153: 
                    154: 
                    155:     hMenu      = LoadMenu(ghModule, "MainMenu");
                    156: 
                    157:     for (index = 0; index < OD_BTN_CNT; index++) {
                    158:         ghBmpDn[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_BASED+index));
                    159:         ghBmpUp[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_BASEU+index));
                    160:     }
                    161:     for (index = 0; index < OD_TOOL_CNT; index++) {
                    162:         ghToolBmpDn[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_TOOLBASED+index));
                    163:         ghToolBmpUp[index] = (PVOID)LoadBitmap(ghModule, (LPCSTR)MAKEINTRESOURCE(BMID_TOOLBASEU+index));
                    164: 
                    165:     }
                    166: 
                    167:     ghwndMain = CreateWindowEx(0L, "MetafDemoClass", "Enhanced Metafile Editor",
                    168:            WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
                    169:            WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
                    170:            WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
                    171:             80, 70, 600, 300,
                    172:            NULL, hMenu, ghModule, NULL);
                    173: 
                    174:     if (ghwndMain == NULL)
                    175:        return FALSE;
                    176: 
                    177:     SetWindowLong(ghwndMain, GWL_USERDATA, 0L);
1.1.1.2 ! root      178:     ghwndNext = SetClipboardViewer(ghwndMain);
1.1       root      179: 
                    180:     SetFocus(ghwndMain);    /* set initial focus */
                    181: 
                    182:     return TRUE;
                    183: }
                    184: 
                    185: 
                    186: /***************************************************************************\
                    187: * MainWndProc
                    188: *
                    189: * History:
                    190: * 11-Feb-1992   Petrus Wong
                    191: *   Name changes.  Added comments.
                    192: * 09-09-91      Petrus Wong    Created.
                    193: \***************************************************************************/
                    194: 
1.1.1.2 ! root      195: long APIENTRY MainWndProc(
1.1       root      196:     HWND hwnd,
                    197:     UINT message,
                    198:     DWORD wParam,
                    199:     LONG lParam)
                    200: {
                    201:     static int         iMetafCnt=0;
                    202:     static char        szFilename[256] = "c:\\metaf";
                    203:     static BOOL        bReset=FALSE;
                    204: 
                    205:     switch (message) {
                    206: 
                    207:       case WM_CREATE: {
                    208: 
                    209:        SetWindowLong(hwnd, 0, (LONG)NULL);
                    210:         ghDCMem = CreateCompatibleDC(NULL);
                    211: 
                    212:         ghwndCtrlPanel = CreateDialog(ghModule, (LPCSTR)MAKEINTRESOURCE(DID_CTRLPANEL),
                    213:                      hwnd, (DLGPROC) CtrlPanelDlgProc);
                    214: 
                    215:         ghwndDrawSurf = CreateWindow("DrawSurfClass", NULL,
                    216:                                     WS_BORDER | WS_CHILD | WS_VISIBLE,
                    217:                                     0, 0, 0, 0,
                    218:                                     hwnd,
                    219:                                     NULL,
                    220:                                     ghModule,
                    221:                                     NULL);
                    222: 
                    223:         ghTextWnd = CreateWindow("Text", NULL,
                    224:                                 WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
                    225:                                 0, 0, 0, 0,
                    226:                                 hwnd,
                    227:                                 NULL,               //(HMENU) 2,
                    228:                                 ghModule,
                    229:                                 NULL);
                    230: 
                    231:         ghbrRed = CreateSolidBrush(RGB(255, 0, 0));
                    232:         ghbrAppBkgd = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
                    233:         ghpnWide = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                    234:         return 0L;
                    235:       }
1.1.1.2 ! root      236:       case WM_DRAWCLIPBOARD:
        !           237:         if ((IsClipboardFormatAvailable(CF_METAFILEPICT)) ||
        !           238:             (IsClipboardFormatAvailable(CF_ENHMETAFILE)) )
        !           239:             EnableMenuItem(hMenu, MM_PASTE, MF_ENABLED);
        !           240:         else
        !           241:             EnableMenuItem(hMenu, MM_PASTE,  MF_GRAYED);
        !           242: 
        !           243:         if (ghwndNext)
        !           244:             SendMessage(ghwndNext, message, wParam, lParam);
        !           245:         return 0L;
1.1       root      246: 
                    247:       case WM_SIZE: {
                    248:           RECT        rc;
                    249:           LONG        lcyCtrlPanel, lcyDrawSurf;
                    250: 
                    251:           GetWindowRect(ghwndCtrlPanel, &rc);
                    252:           lcyCtrlPanel = rc.bottom-rc.top;
                    253:           lcyDrawSurf = HIWORD(lParam) - lcyCtrlPanel - glcyStatus;
                    254: 
                    255:           //
                    256:           // CR!! Alternatively, this window can be created with cy
                    257:           //      equals to cy of the screen and saving this call
                    258:           //      altogether.
                    259:           //
                    260:           MoveWindow(ghwndCtrlPanel,
                    261:                      0, 0, LOWORD(lParam), lcyCtrlPanel, TRUE);
                    262: 
                    263:           //
                    264:           // This ordering guarantees the text window paints correctly
                    265:           //
                    266:           MoveWindow(ghTextWnd,
                    267:                      0, lcyCtrlPanel + lcyDrawSurf,
                    268:                      LOWORD(lParam),                    // cx of hwnd
                    269:                      glcyStatus, TRUE);
                    270: 
                    271:           MoveWindow(ghwndDrawSurf,
                    272:                      0, lcyCtrlPanel,
                    273:                      LOWORD(lParam),                    // cx of hwnd
                    274:                      lcyDrawSurf, TRUE);
1.1.1.2 ! root      275:           //break;
        !           276:           return DefWindowProc(hwnd, message, wParam, lParam);
1.1       root      277:       }
                    278: 
                    279:       case WM_DESTROY: {
                    280:         DeleteDC(ghDCMem);
                    281:         DeleteEnhMetaFile(ghMetaf);
                    282:         DestroyWindow(ghwndCtrlPanel);
                    283:         DeleteObject(ghbrRed);
                    284:         DeleteObject(ghbrCur);
                    285:         DeleteObject(ghpnCur);
                    286:         DeleteObject(ghbrAppBkgd);
                    287:         DeleteObject(ghpnWide);
1.1.1.2 ! root      288:         ChangeClipboardChain(ghwndMain, ghwndNext);
1.1       root      289:        PostQuitMessage(0);
                    290:        return 0L;
                    291:       }
                    292: 
                    293:       case WM_COMMAND: {
                    294:         static int     iPlus=0;
                    295: 
                    296:        switch (LOWORD(wParam)) {
                    297:             case DID_ZERO:
                    298:             case DID_ONE:
                    299:             case DID_TWO:
                    300:             case DID_THREE:
                    301:             case DID_FOUR:
                    302:             case DID_FIVE:
                    303:             case DID_SIX:
                    304:             case DID_SEVEN:
                    305:             case DID_EIGHT:
                    306:             case DID_NINE: {
                    307:                 HDC           hDCDrawSurf;
                    308:                 ENHMETAHEADER EnhMetaHdr;
                    309:                 //RECT          rcClientDS;
                    310:                 int           iRecord;
                    311:                 PLAYINFO      PlayInfo;
                    312: 
                    313:                 if (ghMetaf == 0)
                    314:                     return 0L;
                    315: 
                    316:                 GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                    317:                 iRecord = LOWORD(wParam) - DID_ZERO + iPlus;
                    318:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iRecord, FALSE);
                    319:                 PlayInfo.iRecord = iRecord;
                    320:                 PlayInfo.bPlayContinuous = FALSE;
                    321:                 iPlus = 0;
                    322: 
                    323:                 if ((EnhMetaHdr.nRecords > 1) && (iRecord > 0) &&
                    324:                     (iRecord <= (INT) EnhMetaHdr.nRecords)) {
                    325:                     //!!!GetClientRect(ghwndDrawSurf, &rcClientDS);
                    326:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
                    327:                     //!!!EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, &rcClientDS);
1.1.1.2 ! root      328:                     EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
1.1       root      329:                     //
                    330:                     // Enabling the user to record a metafile record selectively
                    331:                     //
1.1.1.2 ! root      332:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
        !           333:                         EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
        !           334:                     }
1.1       root      335:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                    336:                 }
                    337:                 return 0L;
                    338:             }
                    339:             case DID_TEN_PLUS: {
                    340:                 if (ghMetaf == 0)
                    341:                     return 0L;
                    342: 
                    343:                 iPlus += 10;
                    344:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iPlus, FALSE);
                    345:                 return 0L;
                    346:             }
                    347:             case MM_PRINT:
                    348:             case MM_PAGESETUP:
                    349:             case MM_PRINTSETUP:
                    350:             case MM_CUT:
                    351:                 return 0L;
1.1.1.2 ! root      352: 
        !           353:             case MM_COPY:   {
        !           354:                 HENHMETAFILE hEmfTmp;
        !           355:                 if (ghMetaf == 0) {
        !           356:                     SetWindowText(ghTextWnd, "No Metafile for copying");
        !           357:                     return 0L;
        !           358:                 }
        !           359: 
        !           360:                 OpenClipboard(ghwndMain);
        !           361:                 EmptyClipboard();
        !           362:                 hEmfTmp = CopyEnhMetaFile(ghMetaf, NULL);
        !           363: 
        !           364:                 if (hEmfTmp) {
        !           365:                     SetClipboardData(CF_ENHMETAFILE, hEmfTmp);
        !           366:                     DeleteEnhMetaFile(hEmfTmp);
        !           367:                 }
        !           368: 
        !           369:                 CloseClipboard();
        !           370:                 return 0L;
        !           371:             }
        !           372: 
        !           373:             case MM_PASTE:  {
        !           374:                 HENHMETAFILE hEmfTmp;
        !           375:                 ENHMETAHEADER EnhMetaHdr;
        !           376: 
        !           377:                 OpenClipboard(ghwndMain);
        !           378: 
        !           379:                 hEmfTmp = GetClipboardData(CF_ENHMETAFILE);
        !           380:                 if (hEmfTmp) {
        !           381:                   DeleteEnhMetaFile(ghMetaf);
        !           382:                   ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL);
        !           383:                   DeleteEnhMetaFile(hEmfTmp);
        !           384:                   GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
        !           385:                   SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE);
        !           386:                   bReset = TRUE;
        !           387:                 }
        !           388: 
        !           389:                 CloseClipboard();
        !           390:                 EnableMenuItem(hMenu, MM_COPY,  MF_ENABLED);
        !           391:                 return 0L;
        !           392:             }
        !           393: 
        !           394:             case MM_DEL:    {
        !           395:                 OpenClipboard(ghwndMain);
        !           396:                 EmptyClipboard();
        !           397:                 CloseClipboard();
        !           398:                 return 0L;
        !           399:             }
        !           400: 
1.1       root      401:             case MM_PEN: {
                    402:                 HDC     hDC;
                    403:                 DWORD   dwRGB;
                    404: 
                    405:                 if (bChooseNewColor(hwnd, &dwRGB)) {
                    406:                     hDC = GetDC(ghwndDrawSurf);
                    407:                     if (ghpnCur != NULL)
                    408:                         DeleteObject(ghpnCur);
                    409:                     ghpnCur = CreatePen(PS_SOLID, 1, dwRGB);
                    410:                     SelectObject(hDC, ghpnCur);
                    411:                     if (ghDCMetaf != NULL)
                    412:                         SelectObject(ghDCMetaf, ghpnCur);
                    413:                     ReleaseDC(ghwndDrawSurf, hDC);
                    414:                 }
                    415:                 return 0L;
                    416:             }
                    417:             case MM_BRUSH: {
                    418:                 HDC     hDC;
                    419:                 static DWORD   dwRGB=RGB(255, 255, 255);
                    420: 
                    421:                 if (bChooseNewColor(hwnd, &dwRGB)) {
                    422:                     hDC = GetDC(ghwndDrawSurf);
                    423:                     if (ghbrCur != NULL)
                    424:                         DeleteObject(ghbrCur);
                    425:                     ghbrCur = hBrCreateBrush(hDC, dwRGB);
                    426:                     SelectObject(hDC, ghbrCur);
                    427:                     if (ghDCMetaf != NULL)
                    428:                         SelectObject(ghDCMetaf, ghbrCur);
                    429:                     ReleaseDC(ghwndDrawSurf, hDC);
                    430:                 }
                    431:                 return 0L;
                    432:             }
                    433:             case MM_FONT: {
                    434:                 if (bChooseNewFont(ghwndMain, &glf, &gCrText)) {
                    435:                     ghCurFont = CreateFontIndirect(&glf);
                    436:                     if (ghDCMetaf != NULL)
                    437:                         SelectObject(ghDCMetaf, ghCurFont);
                    438:                 }
                    439:                 return 0L;
                    440:             }
                    441: 
                    442:             case MM_HITTEST: {
                    443:                 static BOOL bHitTest=FALSE;
                    444:                 HWND        hwndRecBtn;
                    445: 
                    446:                 bHitTest = (bHitTest ? FALSE : TRUE);
                    447:                 hwndRecBtn = GetDlgItem(ghwndCtrlPanel, DID_RECORD);
                    448:                 if (bHitTest) {
                    449:                     CheckMenuItem(hMenu, MM_HITTEST, MF_CHECKED);
                    450:                     EnableMenuItem(hMenu, MM_RECORD, MF_GRAYED);
                    451:                     EnableWindow(hwndRecBtn, FALSE);
                    452:                     gbHitTest = TRUE;
                    453:                 } else {
                    454:                     CheckMenuItem(hMenu, MM_HITTEST, MF_UNCHECKED);
                    455:                     EnableMenuItem(hMenu, MM_RECORD, MF_ENABLED);
                    456:                     EnableWindow(hwndRecBtn, TRUE);
                    457:                     gbHitTest = FALSE;
                    458:                     return 0L;
                    459:                 }
                    460: 
                    461:                 if (ghMetaf == 0) {
                    462:                     SetWindowText(ghTextWnd, "No Metafile loaded for hit-testing");
                    463:                     return 0L;
                    464:                 }
                    465:                 return 0L;
                    466:             }
1.1.1.2 ! root      467: 
        !           468:            case MM_LEABOUT:
1.1       root      469:                if (DialogBox(ghModule, (LPCSTR)"AboutBox", ghwndMain, (DLGPROC)About) == -1)
                    470:                        MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
1.1.1.2 ! root      471:                 return 0L;
        !           472: 
        !           473:            case MM_ABOUT:
        !           474:                 ShellAbout(ghwndMain, "Metafile Editor", "",
        !           475:                            LoadIcon(ghModule, MAKEINTRESOURCE(APPICON)));
1.1       root      476:                return 0L;
                    477: 
                    478:             case MM_LOAD_MASKBMP:
                    479:                 SetWindowText(ghTextWnd, "Load Mask Bitmap");
                    480:                 bGetBMP(hwnd, TRUE);
                    481:                 return 0L;
                    482: 
                    483:             case MM_LOAD_BMP:
                    484:                 SetWindowText(ghTextWnd, "Load Bitmap");
                    485:                 bGetBMP(hwnd, FALSE);
                    486:                 return 0L;
                    487: 
                    488:             case MM_SAVE_BMP:
                    489:                 SetWindowText(ghTextWnd, "Save Drawing Surface as Bitmap");
                    490:                 return 0L;
                    491: 
                    492:             case MM_LOAD:
                    493:            case DID_OPEN: {
                    494:                 ENHMETAHEADER EnhMetaHdr;
1.1.1.2 ! root      495:                 HENHMETAFILE  hEmfTmp;
1.1       root      496: 
                    497:                 SetWindowText(ghTextWnd, "Load Metafile");
1.1.1.2 ! root      498:                 //
        !           499:                 // If user hit cancel, we still have the original metafile
        !           500:                 //
        !           501:                 //DeleteEnhMetaFile(ghMetaf);
        !           502:                 //ghMetaf = hemfLoadMetafile(hwnd);
        !           503:                 hEmfTmp = hemfLoadMetafile(hwnd);
        !           504:                 if (hEmfTmp != 0) {
        !           505:                     DeleteEnhMetaFile(ghMetaf);
        !           506:                     ghMetaf = CopyEnhMetaFile(hEmfTmp, NULL);
1.1       root      507:                     GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                    508:                     SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, EnhMetaHdr.nRecords, FALSE);
1.1.1.2 ! root      509:                     DeleteEnhMetaFile(hEmfTmp);
        !           510:                     EnableMenuItem(hMenu, MM_COPY,  MF_ENABLED);
        !           511:                 //} else {
        !           512:                 //    SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE);
1.1       root      513:                 }
                    514:                 bReset = TRUE;
                    515:                 return 0L;
                    516:             }
                    517:             case MM_RECORD:
                    518:                 if (gbHitTest) {
                    519:                     SetWindowText(ghTextWnd, "Please CANCEL Hit Testing Mode First!");
                    520:                     return 0L;
                    521:                 }
                    522: 
                    523:                 SetWindowText(ghTextWnd, "Recording...");
                    524:                 if (!gbRecording) {
                    525:                     ghDCMetaf = hDCRecordMetafileAs(hwnd, szFilename);
                    526:                 }
                    527: 
                    528:                 if (ghDCMetaf == NULL) {
                    529:                    SetWindowText(ghTextWnd, "ERROR: Failed in creating the metafile DC!");
                    530:                    return 0L;
                    531:                 }
                    532:                 gbRecording = TRUE;
                    533: 
                    534:                 if (ghpnCur != NULL)
                    535:                     SelectObject(ghDCMetaf, ghpnCur);
                    536: 
                    537:                 if (ghbrCur != NULL)
                    538:                     SelectObject(ghDCMetaf, ghbrCur);
                    539: 
                    540:                 if (ghCurFont != NULL)
                    541:                     SelectObject(ghDCMetaf, ghCurFont);
                    542:                 return 0L;
                    543: 
                    544:            case DID_RECORD: {
                    545:                 char tmp[256];
                    546:                 char suffix[20];
                    547: 
                    548:                 if (gbHitTest) {
                    549:                     SetWindowText(ghTextWnd, "Please CANCEL Hit Testing Mode First!");
                    550:                     return 0L;
                    551:                 }
                    552: 
                    553:                 SetWindowText(ghTextWnd, "Recording...");
                    554:                 if (!gbRecording) {
                    555:                    wsprintf((LPSTR) suffix, "%d.emf", iMetafCnt);
                    556:                     iMetafCnt++;
                    557:                     strcpy(tmp, szFilename);
                    558:                     strcat(tmp, suffix);
                    559:                     ghDCMetaf = CreateEnhMetaFile((HDC)NULL, tmp, (LPRECT)NULL, (LPSTR)NULL);
                    560:                 }
                    561: 
                    562:                 if (ghDCMetaf == NULL) {
                    563:                    SetWindowText(ghTextWnd, "ERROR: Failed in creating the metafile DC!");
                    564:                    return 0L;
                    565:                 }
                    566:                 gbRecording = TRUE;
                    567: 
                    568:                 if (ghpnCur != NULL)
                    569:                     SelectObject(ghDCMetaf, ghpnCur);
                    570: 
                    571:                 if (ghbrCur != NULL)
                    572:                     SelectObject(ghDCMetaf, ghbrCur);
                    573: 
                    574:                 if (ghCurFont != NULL)
                    575:                     SelectObject(ghDCMetaf, ghCurFont);
                    576: 
                    577:                 return 0L;
                    578:             }
                    579:            case DID_STOP:
                    580:                 SetWindowText(ghTextWnd, "Stop");
                    581:                 if (gbRecording) {
                    582:                     ghMetaf = CloseEnhMetaFile(ghDCMetaf);
                    583:                     gbRecording = FALSE;
                    584:                 }
                    585:                 return 0L;
1.1.1.2 ! root      586: 
1.1       root      587:            case DID_PLAY: {
                    588:                 HDC hDCDrawSurf;
                    589:                 ENHMETAHEADER EnhMetaHdr;
                    590:                 //!!!RECT          rcClientDS;
                    591: 
                    592:                 SetWindowText(ghTextWnd, "Playing Metafile");
                    593:                 if (ghMetaf != NULL) {
                    594:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
                    595:                     //!!!GetClientRect(ghwndDrawSurf, &rcClientDS);
                    596:                     GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                    597:                     //!!!PlayEnhMetaFile( hDCDrawSurf, ghMetaf, (LPRECT) &rcClientDS);
                    598:                     PlayEnhMetaFile( hDCDrawSurf, ghMetaf, (LPRECT) &EnhMetaHdr.rclBounds);
                    599: 
                    600:                     //
                    601:                     // Enabling the user to embed another metafile
                    602:                     //
1.1.1.2 ! root      603:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
1.1       root      604:                         PlayEnhMetaFile( ghDCMetaf, ghMetaf, (LPRECT) &EnhMetaHdr.rclBounds);
1.1.1.2 ! root      605:                     }
1.1       root      606: 
                    607:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
1.1.1.2 ! root      608:                 } else {
        !           609:                     SetWindowText(ghTextWnd, "No Metafile for Playing");
1.1       root      610:                 }
1.1.1.2 ! root      611: 
1.1       root      612:                 return 0L;
                    613:             }
                    614:            case DID_FF: {
                    615:                 HDC           hDCDrawSurf;
                    616:                 ENHMETAHEADER EnhMetaHdr;
                    617:                 //!!!RECT          rcClientDS;
                    618:                 static int    iRecord = 0;
                    619:                 PLAYINFO      PlayInfo;
                    620: 
                    621:                 if (ghMetaf == 0)
                    622:                     return 0L;
                    623: 
                    624:                 PlayInfo.iRecord = ++iRecord;
                    625:                 PlayInfo.bPlayContinuous = TRUE;
                    626: 
                    627:                 GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                    628:                 SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iRecord, FALSE);
                    629:                 if ((EnhMetaHdr.nRecords > 1) && (iRecord <= (INT)EnhMetaHdr.nRecords)) {
                    630:                     //!!!GetClientRect(ghwndDrawSurf, &rcClientDS);
                    631:                     hDCDrawSurf = GetDC(ghwndDrawSurf);
                    632:                     //!!!EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (PROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &rcClientDS);
1.1.1.2 ! root      633:                     EnumEnhMetaFile(hDCDrawSurf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT) &EnhMetaHdr.rclBounds);
1.1       root      634: 
                    635:                     //
                    636:                     // Enabling the user to record a metafile records selectively
                    637:                     //
1.1.1.2 ! root      638:                     if ((gbRecording) && (ghDCMetaf != NULL)) {
        !           639:                         EnumEnhMetaFile(ghDCMetaf, ghMetaf, (ENHMFENUMPROC)bPlayRecord, (LPVOID) &PlayInfo, (LPRECT)&EnhMetaHdr.rclBounds);
        !           640:                     }
1.1       root      641: 
                    642:                     ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                    643:                 }
                    644: 
                    645:                 if ((iRecord == (INT) EnhMetaHdr.nRecords) || bReset) {
                    646:                     iRecord = 0;
                    647:                     if (bReset)
                    648:                         SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, 0, FALSE);
                    649:                     bReset = FALSE;
                    650:                 }
                    651: 
                    652:                 return 0L;
                    653:             }
                    654:            case DID_CLEAR: {
                    655:                 HDC     hDCDrawSurf;
                    656:                 HGDIOBJ hObjOld;
                    657:                 RECT    rcDrawSurf;
                    658: 
                    659:                 SetWindowText(ghTextWnd, "Drawing Surface cleared");
                    660:                 hDCDrawSurf = GetDC(ghwndDrawSurf);
                    661:                 ghbrAppBkgd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
                    662:                 hObjOld = SelectObject(hDCDrawSurf, ghbrAppBkgd);
                    663:                 GetClientRect(ghwndDrawSurf, &rcDrawSurf);
                    664:                 PatBlt(hDCDrawSurf, 0, 0, rcDrawSurf.right, rcDrawSurf.bottom, PATCOPY);
                    665:                 ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
                    666:                 SelectObject(hDCDrawSurf, hObjOld);
                    667:                 return 0L;
                    668:             }
                    669: 
                    670:             case DID_PEN:
                    671:                 SetWindowText(ghTextWnd, "Pen");
                    672:                 return 0L;
                    673:             case DID_TEXT:
                    674:                 SetWindowText(ghTextWnd, "Text");
                    675:                 return 0L;
                    676:             case DID_RECT:
                    677:                 SetWindowText(ghTextWnd, "Rectangle");
                    678:                 return 0L;
                    679:             case DID_FILLRECT:
                    680:                 SetWindowText(ghTextWnd, "Filled Rectangle");
                    681:                 return 0L;
                    682:             case DID_ELLIPSE:
                    683:                 SetWindowText(ghTextWnd, "Ellipse");
                    684:                 return 0L;
                    685:             case DID_FILLELLIPSE:
                    686:                 SetWindowText(ghTextWnd, "Filled Ellipse");
                    687:                 return 0L;
                    688:             case DID_LINE:
                    689:                 SetWindowText(ghTextWnd, "Line");
                    690:                 return 0L;
                    691:             case DID_BEZIER:
                    692:                 SetWindowText(ghTextWnd,
                    693:                     "Bezier: Click with Left button for placing control points");
                    694:                 return 0L;
                    695:             case DID_BMPOBJ:
                    696:                 SetWindowText(ghTextWnd,
                    697:                     "Bitmap: Click three points for the destination of the bitmap");
                    698:                 return 0L;
                    699:             case DID_METAF:
                    700:                 SetWindowText(ghTextWnd,
                    701:                     "External Metafile: Click three points for the destination of the Metafile");
                    702:                 return 0L;
                    703:            default:
                    704:                 return DefWindowProc(hwnd, message, wParam, lParam);
                    705:         }
                    706:       }     // WM_COMMAND
                    707:       default:
                    708:         return DefWindowProc(hwnd, message, wParam, lParam);
                    709:     }
                    710: }
                    711: 
                    712: /******************************Public*Routine******************************\
                    713: *
                    714: * DrawSurfWndProc
                    715: *       Drawing surface window procedure
                    716: *
                    717: * Effects:  Trapping all mouse messages and call the DrawStuff appropriately
                    718: *           for drawing to the drawing surface DC and metafile DC as needed.
                    719: *
                    720: * Warnings:
                    721: *
                    722: * History:
                    723: *  30-Apr-1992 -by- Petrus Wong
                    724: * Wrote it.
                    725: \**************************************************************************/
                    726: 
1.1.1.2 ! root      727: long APIENTRY DrawSurfWndProc(
1.1       root      728:     HWND hwnd,
                    729:     UINT message,
                    730:     DWORD wParam,
                    731:     LONG lParam)
                    732: {
                    733:     static BOOL    bTrack = FALSE;
                    734:     static int     OrgX, OrgY;
                    735:     static int     PrevX, PrevY;
                    736:     static HDC     hDC;
                    737:     static HCURSOR hCurArrow, hCurHT;
                    738: 
                    739:     switch (message) {
                    740:       case WM_CREATE:
                    741:           {
                    742:               RECT       rect;
                    743: 
                    744:               GetClientRect(GetParent(hwnd), &rect);
                    745: 
                    746:               SetWindowPos(hwnd, NULL,
                    747:                       0,
                    748:                       30,
                    749:                       rect.right-rect.left,
                    750:                       rect.bottom-rect.top-30,
                    751:                       SWP_NOZORDER | SWP_NOMOVE);
                    752: 
                    753:               CreateCaret(hwnd, NULL, 1, 12);
                    754:               ghCurFont = GetStockObject(SYSTEM_FONT);
                    755:               GetObject(ghCurFont, sizeof(LOGFONT), &glf);
                    756:               hCurArrow = LoadCursor(NULL, IDC_ARROW);
                    757:               hCurHT = LoadCursor(NULL, IDC_CROSS);
                    758:               break;
                    759:           }
                    760: 
                    761:       case WM_LBUTTONDOWN: {
                    762:         int    x, y;
                    763: 
                    764:         x = (int) LOWORD(lParam);
                    765:         y = (int) HIWORD(lParam);
                    766: 
                    767:         if (gbHitTest) {
                    768:             hDC = GetDC(hwnd);
                    769:             bHitTest(hDC, x, y);
                    770:             ReleaseDC(hwnd, hDC);
                    771:             break;
                    772:         }
                    773: 
                    774:         bTrack = TRUE;
                    775:         OrgX = PrevX = x;
                    776:         OrgY = PrevY = y;
                    777: 
                    778:         hDC = GetDC(hwnd);
                    779:         SetCapture(hwnd);
                    780:         break;
                    781:       }
                    782: 
                    783:       case WM_MOUSEMOVE: {
                    784:         RECT rectClient;
                    785:         int NextX;
                    786:         int NextY;
                    787: 
                    788:         if (gbHitTest) {
                    789:             SetCursor(hCurHT);
                    790:         } else {
                    791:             SetCursor(hCurArrow);
                    792:         }
                    793: 
                    794:         // Update the selection region
                    795:         if (bTrack) {
                    796:             NextX = (SHORT) LOWORD(lParam);
                    797:             NextY = (SHORT) HIWORD(lParam);
                    798: 
                    799:             // Do not draw outside the window's client area
                    800: 
                    801:             GetClientRect (hwnd, &rectClient);
                    802:             if (NextX < rectClient.left) {
                    803:                 NextX = rectClient.left;
                    804:             } else if (NextX >= rectClient.right) {
                    805:                 NextX = rectClient.right - 1;
                    806:             }
                    807:             if (NextY < rectClient.top) {
                    808:                 NextY = rectClient.top;
                    809:             } else if (NextY >= rectClient.bottom) {
                    810:                 NextY = rectClient.bottom - 1;
                    811:             }
                    812:             if ((NextX != PrevX) || (NextY != PrevY)) {
                    813:                SetROP2(hDC, R2_NOT);           // Erases the previous box
                    814:                bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, TRUE, TRUE, FALSE, NULL);
                    815: 
                    816:                //
                    817:                // Optimization.  Do not record in metafile DC if it is going
                    818:                // to be erased.  So only call bDrawStuff with the PEN tool.
                    819:                //
                    820:                if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                    821:                    bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, TRUE, TRUE, FALSE, NULL);
                    822:                }
                    823: 
                    824: 
                    825:             // Get the current mouse position
                    826:                PrevX = NextX;
                    827:                PrevY = NextY;
                    828: 
                    829:                //
                    830:                // SetROP2(hDC, R2_COPYPEN);
                    831:                //   This is commented out because we don't want to erase
                    832:                //   the background as it sweeps.
                    833:                //
                    834:                bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, FALSE, TRUE, FALSE, NULL);
                    835: 
                    836:                if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                    837:                    bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, FALSE, TRUE, FALSE, NULL);
                    838:                }
                    839: 
                    840:             }
                    841:         }
                    842:         break;
                    843: 
                    844:       }
                    845: 
                    846:       case WM_LBUTTONUP: {
                    847:         int NextX;
                    848:         int NextY;
                    849: 
                    850:         if (!bTrack)
                    851:            break;
                    852: 
                    853:         // End the selection
                    854:            ReleaseCapture();
                    855:            bTrack = FALSE;
                    856: 
                    857:         // Erases the box
                    858:            //
                    859:            // SetROP2(hDC, R2_NOT);
                    860:            //   This is assumed to be R2_NOT, thus unnecessary
                    861:            //
                    862:            bDrawStuff(hDC, OrgX, OrgY, PrevX, PrevY, TRUE, FALSE, FALSE, NULL);
                    863: 
                    864:            if (gbRecording && (ghDCMetaf != NULL) && (gdwCurTool == DID_PEN)) {
                    865:                bDrawStuff(ghDCMetaf, OrgX, OrgY, PrevX, PrevY, TRUE, FALSE, FALSE, NULL);
                    866:            }
                    867: 
                    868:            NextX = LOWORD(lParam);
                    869:            NextY = HIWORD(lParam);
                    870: 
                    871:         // Draws the new box
                    872:            SetROP2(hDC, R2_COPYPEN);
                    873:            bDrawStuff(hDC, OrgX, OrgY, NextX, NextY, FALSE, FALSE, TRUE, NULL);
                    874: 
                    875:            ReleaseDC(hwnd, hDC);
                    876: 
                    877:            if (gbRecording && (ghDCMetaf != NULL)) {
                    878:                 bDrawStuff(ghDCMetaf, OrgX, OrgY, NextX, NextY, FALSE, FALSE, FALSE, NULL);
                    879:            }
                    880: 
                    881:         break;
                    882:       } // case WM_LBUTTONUP
                    883: 
                    884:       case WM_CHAR: {
                    885: 
                    886:         if (gdwCurTool != DID_TEXT)
                    887:             break;
                    888: 
                    889:         hDC = GetDC(hwnd);
                    890:         bDrawStuff(hDC, 0, 0, 0, 0, TRUE, FALSE, FALSE, (LPSTR)&wParam);
                    891:         ReleaseDC(hwnd, hDC);
                    892: 
                    893:         if (gbRecording && (ghDCMetaf != NULL)) {
                    894:             bDrawStuff(ghDCMetaf, 0, 0, 0, 0, TRUE, FALSE, FALSE, (LPSTR)&wParam);
                    895:         }
                    896: 
                    897:         break;
                    898:       }
                    899: 
                    900:       case WM_DESTROY: {
                    901:         DestroyCaret();
                    902:         DeleteObject(ghCurFont);
                    903:        PostQuitMessage(0);
                    904:        return 0L;
                    905:       }
                    906: 
                    907:       default:
                    908:        return DefWindowProc(hwnd, message, wParam, lParam);
                    909:     }
                    910: }
                    911: 
                    912: 
                    913: /***************************************************************************\
                    914: * About
                    915: *
                    916: * About dialog proc.
                    917: *
                    918: * History:
                    919: * 09-09-91 Petrus Wong Rewrote.
                    920: * 04-13-91 ????         Created.
                    921: \***************************************************************************/
                    922: 
1.1.1.2 ! root      923: long APIENTRY About(
1.1       root      924:     HWND hDlg,
                    925:     UINT message,
                    926:     DWORD wParam,
                    927:     LONG lParam)
                    928: {
                    929:     switch (message) {
                    930:     case WM_INITDIALOG:
                    931:         return TRUE;
                    932: 
                    933:     case WM_COMMAND:
                    934:         if (wParam == IDOK)
                    935:             EndDialog(hDlg, wParam);
                    936:         break;
                    937:     }
                    938: 
                    939:     return FALSE;
                    940: 
                    941:     UNREFERENCED_PARAMETER(lParam);
                    942:     UNREFERENCED_PARAMETER(hDlg);
                    943: }
                    944: 
                    945: /***************************************************************************\
                    946: *
                    947: * TextWndProc
                    948: *
                    949: * Text Window procedure for displaying miscellaneous messages to user.
                    950: *
                    951: * History:
                    952: * 10-07-91  Petrus Wong
                    953: *   3D text output
                    954: *
                    955: \***************************************************************************/
                    956: 
1.1.1.2 ! root      957: LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
1.1       root      958: {
                    959:     static HFONT hFont = (HFONT) NULL;
                    960: 
                    961:     switch (message)
                    962:     {
                    963:     case WM_CREATE:
                    964:         {
                    965:            LOGFONT    lf;
                    966:            HDC        hDC;
                    967:            HFONT      hOldFont;
                    968:             TEXTMETRIC tm;
                    969:            //RECT       rect;
                    970: 
                    971:             SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);
                    972: 
                    973:            hDC = GetDC(hwnd);
                    974:            // this is the height for 8 point size font in pixels
                    975:            lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
                    976: 
                    977:            hFont = CreateFontIndirect(&lf);
                    978:            hOldFont = SelectObject(hDC, hFont);
                    979:            GetTextMetrics(hDC, &tm);
                    980: 
                    981:            // base the height of the window on size of text
                    982:            glcyStatus = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
                    983:             ReleaseDC(hwnd, hDC);
                    984:             break;
                    985:         }
                    986: 
                    987:     case WM_DESTROY:
                    988:            if (hFont)
                    989:                DeleteObject(hFont);
                    990:            break;
                    991: 
                    992:     case WM_SETTEXT:
                    993:             DefWindowProc(hwnd, message, wParam, lParam);
                    994:             InvalidateRect(hwnd,NULL,FALSE);
                    995:             UpdateWindow(hwnd);
                    996:             return 0L;
                    997: 
                    998:     case WM_PAINT:
                    999:         {
                   1000:             PAINTSTRUCT ps;
                   1001:             RECT   rc;
                   1002:             char   ach[128];
                   1003:             int    len, nxBorder, nyBorder;
                   1004:             HFONT  hOldFont = NULL;
                   1005: 
                   1006:             BeginPaint(hwnd, &ps);
                   1007: 
                   1008:             GetClientRect(hwnd,&rc);
                   1009: 
                   1010:             nxBorder = GetSystemMetrics(SM_CXBORDER);
                   1011:            rc.left  += 9*nxBorder;
                   1012:             rc.right -= 9*nxBorder;
                   1013: 
                   1014:             nyBorder = GetSystemMetrics(SM_CYBORDER);
                   1015:            rc.top    += 3*nyBorder;
                   1016:            rc.bottom -= 3*nyBorder;
                   1017: 
                   1018:            // 3D Text
                   1019:             len = GetWindowText(hwnd, ach, sizeof(ach));
                   1020:            SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));
                   1021: 
                   1022:            SetBkMode(ps.hdc, TRANSPARENT);
                   1023:            SetTextColor(ps.hdc, RGB(64,96,96));
                   1024:            if (hFont)
                   1025:                hOldFont = SelectObject(ps.hdc, hFont);
                   1026:            ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
                   1027:                        &rc, ach, len, NULL);
                   1028: 
                   1029:            SetTextColor(ps.hdc, RGB(128,128,128));
                   1030:            if (hFont)
                   1031:                hOldFont = SelectObject(ps.hdc, hFont);
                   1032:            ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
                   1033:                        &rc, ach, len, NULL);
                   1034: 
                   1035:            SetTextColor(ps.hdc, RGB(255,255,255));
                   1036:            if (hFont)
                   1037:                hOldFont = SelectObject(ps.hdc, hFont);
                   1038:            ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
                   1039:                        &rc, ach, len, NULL);
                   1040: 
                   1041:            SetBkMode(ps.hdc, OPAQUE);
                   1042: 
                   1043:            if (hOldFont)
                   1044:                SelectObject(ps.hdc, hOldFont);
                   1045: 
                   1046:             EndPaint(hwnd, &ps);
                   1047:             return 0L;
                   1048:         }
                   1049:     }
                   1050:     return DefWindowProc(hwnd, message, wParam, lParam);
                   1051: }
                   1052: 
                   1053: /******************************Public*Routine******************************\
                   1054: *
                   1055: * CtrlPanelDlgProc
                   1056: *       The Control Panel dialog procedure
                   1057: *
                   1058: * Effects:  Responsible for drawing the owner draw buttons.  Notifying
                   1059: *           parent of user's action.
                   1060: *
                   1061: * Warnings:
                   1062: *
                   1063: * History:
                   1064: *  27-May-1992 -by- Petrus Wong
                   1065: * Wrote it.
                   1066: \**************************************************************************/
                   1067: 
1.1.1.2 ! root     1068: LONG APIENTRY CtrlPanelDlgProc(HWND hwnd, UINT msg, DWORD dwParam, LONG lParam)
1.1       root     1069: {
                   1070:     switch (msg) {
                   1071:         case WM_INITDIALOG: {
                   1072:             int index;
                   1073: 
                   1074:             for (index = 0; index < OD_BTN_CNT; index++) {
                   1075:                 grHwndCtrlBtn[index] = (PVOID)GetDlgItem(hwnd, (INT)(ID_OD_BTN_BASE+index));
                   1076:             }
                   1077:             for (index = 0; index < OD_TOOL_CNT; index++) {
                   1078:                 grHwndToolBtn[index] = (PVOID)GetDlgItem(hwnd, (INT)(ID_OD_TOOL_BASE+index));
                   1079:             }
                   1080:             return TRUE;
                   1081:         }
                   1082: 
                   1083:         case WM_DRAWITEM: {
                   1084:             PDRAWITEMSTRUCT pDIS = (PDRAWITEMSTRUCT) lParam;
                   1085:             HBITMAP hBmpOld;
                   1086:             BITMAP  bm;
                   1087:             HANDLE  hCtl;
                   1088:             HDC     hDCCtl;
                   1089: 
                   1090:             if (pDIS->CtlID == gdwCurCtrl) {
                   1091:                 GetObject((HBITMAP) ghBmpDn[pDIS->CtlID - ID_OD_BTN_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1092:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP) ghBmpDn[pDIS->CtlID - ID_OD_BTN_BASE]);
                   1093:             }
                   1094: 
                   1095:             if (pDIS->CtlID == gdwCurTool) {
                   1096:                 GetObject((HBITMAP)ghToolBmpDn[pDIS->CtlID - ID_OD_TOOL_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1097:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghToolBmpDn[pDIS->CtlID - ID_OD_TOOL_BASE]);
                   1098:             }
                   1099: 
                   1100:             if ((pDIS->CtlID < ID_OD_TOOL_BASE) && (pDIS->CtlID != gdwCurCtrl)) {
                   1101:                 GetObject((HBITMAP)ghBmpUp[pDIS->CtlID - ID_OD_BTN_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1102:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghBmpUp[pDIS->CtlID - ID_OD_BTN_BASE]);
                   1103:             }
                   1104: 
                   1105:             if ((pDIS->CtlID >= ID_OD_TOOL_BASE) && (pDIS->CtlID != gdwCurTool)) {
                   1106:                 GetObject((HBITMAP)ghToolBmpUp[pDIS->CtlID - ID_OD_TOOL_BASE], sizeof(BITMAP), (LPSTR)&bm);
                   1107:                 hBmpOld = SelectObject(ghDCMem, (HBITMAP)ghToolBmpUp[pDIS->CtlID - ID_OD_TOOL_BASE]);
                   1108:             }
                   1109: 
                   1110:             //
                   1111:             // pDIS->hDC is clipped to the update region but unfortunately
                   1112:             // that doesn't work well with StretchBlt.  StretchBlt is used
                   1113:             // because I don't have to make sure that the bitmap size is
                   1114:             // exactly the same as the size of the button.
                   1115:             //
                   1116:             hCtl   = GetDlgItem(hwnd, pDIS->CtlID);
                   1117:             hDCCtl = GetDC(hCtl);
                   1118:             StretchBlt(hDCCtl,                                //pDIS->hDC,
                   1119:                    pDIS->rcItem.left, pDIS->rcItem.top,
                   1120:                    pDIS->rcItem.right - pDIS->rcItem.left,
                   1121:                    pDIS->rcItem.bottom - pDIS->rcItem.top,
                   1122:                    ghDCMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
                   1123:             ReleaseDC(hCtl, hDCCtl);
                   1124:             SelectObject(ghDCMem, hBmpOld);
                   1125:             break;
                   1126:         }
                   1127: 
                   1128:         case WM_COMMAND: {
                   1129:             DWORD dwOldCtrl = gdwCurCtrl;
                   1130:             DWORD dwOldTool = gdwCurTool;
                   1131: 
                   1132:             switch (dwParam) {
                   1133:                 case DID_ONE:
                   1134:                 case DID_TWO:
                   1135:                 case DID_THREE:
                   1136:                 case DID_FOUR:
                   1137:                 case DID_FIVE:
                   1138:                 case DID_SIX:
                   1139:                 case DID_SEVEN:
                   1140:                 case DID_EIGHT:
                   1141:                 case DID_NINE:
                   1142:                 case DID_ZERO:
                   1143:                 case DID_TEN_PLUS:
                   1144:                     //SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, dwParam - DID_ZERO, FALSE);
                   1145:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1146:                     break;
                   1147:                 case DID_OPEN:
                   1148:                 case DID_RECORD:
                   1149:                 case DID_STOP:
                   1150:                 case DID_PLAY:
                   1151:                 case DID_FF:
                   1152:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1153:                     gdwCurCtrl = dwParam;
                   1154:                     InvalidateRect((HWND)grHwndCtrlBtn[dwOldCtrl - ID_OD_BTN_BASE], NULL, FALSE);
                   1155:                     InvalidateRect((HWND)grHwndCtrlBtn[gdwCurCtrl - ID_OD_BTN_BASE], NULL, FALSE);
                   1156:                     break;
                   1157:                 case DID_CLEAR:
                   1158:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1159:                     break;
                   1160:                 case DID_TEXT:
                   1161:                 case DID_PEN:
                   1162:                 case DID_RECT:
                   1163:                 case DID_FILLRECT:
                   1164:                 case DID_ELLIPSE:
                   1165:                 case DID_FILLELLIPSE:
                   1166:                 case DID_LINE:
                   1167:                 case DID_BEZIER:
                   1168:                 case DID_BMPOBJ:
                   1169:                 case DID_METAF:
                   1170:                     SendMessage(ghwndMain, WM_COMMAND, dwParam, lParam);
                   1171:                     gdwCurTool = dwParam;
                   1172:                     InvalidateRect((HWND)grHwndToolBtn[dwOldTool - ID_OD_TOOL_BASE], NULL, FALSE);
                   1173:                     InvalidateRect((HWND)grHwndToolBtn[gdwCurTool - ID_OD_TOOL_BASE], NULL, FALSE);
                   1174:                     break;
                   1175:             }
                   1176:             break;
                   1177:         }
                   1178: 
                   1179: 
                   1180:         case WM_PAINT:
                   1181:             {
                   1182:                 HDC hdc;
                   1183:                 RECT rc, rcDlg;
                   1184:                 PAINTSTRUCT ps;
                   1185:                 HPEN hpenWindowFrame, hpenDarkGray;
                   1186:                 int  icyDlg;
                   1187:                 int  icyBorder;
                   1188: 
                   1189:                 icyBorder = GetSystemMetrics(SM_CYBORDER);
                   1190: 
                   1191:                 GetWindowRect(hwnd, &rcDlg);
                   1192:                 icyDlg = rcDlg.right - rcDlg.left;
                   1193: 
                   1194:                 /*
                   1195:                  * Draw our border lines.
                   1196:                  */
                   1197:                 GetClientRect(hwnd, &rc);
                   1198:                 hdc = BeginPaint(hwnd, &ps);
                   1199: 
                   1200:                 SelectObject(hdc, GetStockObject(WHITE_PEN));
                   1201:                 MoveToEx(hdc, rc.left, rc.top, NULL);
                   1202:                 LineTo(hdc, rc.right, rc.top);
                   1203: 
                   1204:                 hpenDarkGray = CreatePen(PS_SOLID, 1, DARKGRAY);
                   1205:                 SelectObject(hdc, hpenDarkGray);
                   1206:                 MoveToEx(hdc, rc.left, (rc.top + icyDlg) - icyBorder - 1, NULL);
                   1207:                 LineTo(hdc, rc.right, (rc.top + icyDlg) - icyBorder - 1);
                   1208: 
                   1209:                 hpenWindowFrame = CreatePen(PS_SOLID, icyBorder,
                   1210:                         GetSysColor(COLOR_WINDOWFRAME));
                   1211:                 SelectObject(hdc, hpenWindowFrame);
                   1212:                 MoveToEx(hdc, rc.left, (rc.top + icyDlg) - icyBorder, NULL);
                   1213:                 LineTo(hdc, rc.right, (rc.top + icyDlg) - icyBorder);
                   1214: 
                   1215:                 EndPaint(hwnd, &ps);
                   1216:                 DeleteObject(hpenWindowFrame);
                   1217:                 DeleteObject(hpenDarkGray);
                   1218:             }
                   1219: 
                   1220:             break;
                   1221: 
                   1222: 
                   1223:         //case WM_CTLCOLOR:
                   1224:         case WM_CTLCOLORDLG:
                   1225:         //case WM_CTLCOLORLISTBOX:
1.1.1.2 ! root     1226:         case WM_CTLCOLORSTATIC:
1.1       root     1227:             switch (GET_WM_CTLCOLOR_TYPE(dwParam, lParam, msg)) {
                   1228:                 case CTLCOLOR_DLG:
                   1229:                 //case CTLCOLOR_LISTBOX:
                   1230:                     return (BOOL)GetStockObject(LTGRAY_BRUSH);
                   1231: 
1.1.1.2 ! root     1232:                 case CTLCOLOR_STATIC:
        !          1233:                     SetBkMode(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
        !          1234:                               TRANSPARENT);
        !          1235:                 //    SetTextColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
        !          1236:                 //              RGB(255,0,0));
1.1       root     1237:                 //    SetBkColor(GET_WM_CTLCOLOR_HDC(dwParam, lParam, msg),
                   1238:                 //            LIGHTGRAY);
1.1.1.2 ! root     1239:                 //              RGB(255, 255,0));
        !          1240:                     return (BOOL)GetStockObject(DKGRAY_BRUSH);
1.1       root     1241:             }
1.1.1.2 ! root     1242:             //return (BOOL)NULL;
        !          1243:             return (BOOL)GetStockObject(LTGRAY_BRUSH);
1.1       root     1244: 
                   1245:         default:
                   1246:             return FALSE;
                   1247:     }
                   1248: 
                   1249:     return FALSE;
                   1250: }
                   1251: 
                   1252: 
                   1253: 
                   1254: /******************************Public*Routine******************************\
                   1255: *
                   1256: * bDrawStuff
                   1257: *
                   1258: * Effects:  The drawing routines are localized here.
                   1259: *           bErase is TRUE if this fcn is called for erasing previous object.
                   1260: *           (as in tracking objects.)  It is FALSE, otherwise.
                   1261: *
                   1262: *           bMove is TRUE if this fcn is called inside the WM_MOUSEMOVE (as
                   1263: *           in tracking objects.)  It is FALSE, otherwise.
                   1264: *
                   1265: *           bCntPt is TRUE if this fcn is to increment either the iCnt or
                   1266: *           iCntMF counter (used only in processing metafile or bezier.)
                   1267: *           It is FALSE, otherwise.
                   1268: *
                   1269: *           lpstr contains the character to be drawn by TextOut when it is
                   1270: *           not NULL.
                   1271: *
                   1272: * Warnings: Metafile and Bezier assume that the caller is calling this fcn
                   1273: *           to draw in the screen DC first. Then draw it to the metafile DC.
                   1274: *           Thus, when it is called to draw on the metafile DC, the points
                   1275: *           would have been set already.
                   1276: *
                   1277: * History:
                   1278: *  10-May-1992 -by- Petrus Wong
                   1279: * Wrote it.
                   1280: \**************************************************************************/
                   1281: 
                   1282: BOOL bDrawStuff(HDC hDC, INT OrgX, INT OrgY,
                   1283:                          INT NextX, INT NextY,
                   1284:                          BOOL bErase,
                   1285:                          BOOL bMove,
                   1286:                          BOOL bCntPt,
                   1287:                          LPSTR lpstr) {
                   1288:     BOOL bSuccess;
                   1289:     HGDIOBJ hObjOld;
                   1290:     static POINT rgPts[MAX_POINTS], rgPtsMF[MAX_POINTS_MF], rgPtsBMP[MAX_POINTS_BMP];
                   1291:     static int   iCnt=0, iCntMF=0, iCntBMP=0;
                   1292:     static BOOL  bCaretShown=FALSE;
                   1293: 
                   1294:     bSuccess = TRUE;
                   1295:     if (bCaretShown) {
                   1296:         HideCaret(ghwndDrawSurf);
                   1297:         bCaretShown = FALSE;
                   1298:     }
                   1299: 
                   1300:     switch (gdwCurTool) {
                   1301:         case DID_PEN:
                   1302:             if (bErase) {
                   1303:                 MoveToEx(hDC, NextX, NextY, NULL);
                   1304:             } else {
                   1305:                 //
                   1306:                 // Override the ROP2 st. the pen won't erase its track
                   1307:                 //
                   1308:                 SetROP2(hDC, R2_COPYPEN);
                   1309:                 LineTo(hDC, NextX, NextY);
                   1310:             }
                   1311:             break;
                   1312:         case DID_TEXT: {
                   1313:             POINT   Pt;
                   1314: 
                   1315:             if (lpstr == NULL) {
                   1316:                 ShowCaret(ghwndDrawSurf);
                   1317:                 bCaretShown = TRUE;
                   1318:                 SetCaretPos(NextX, NextY);
                   1319:                 MoveToEx(hDC, NextX, NextY, NULL);
                   1320:                 SetFocus(ghwndDrawSurf);
                   1321:                 break;
                   1322:             }
                   1323: 
1.1.1.2 ! root     1324:             SetTextAlign(hDC, TA_BASELINE | TA_LEFT | TA_UPDATECP);
1.1       root     1325:             hObjOld = SelectObject(hDC, ghCurFont);
                   1326:             SetTextColor(hDC, gCrText);
                   1327:             SetBkMode(hDC, TRANSPARENT);
1.1.1.2 ! root     1328: 
        !          1329: 
        !          1330:             {
        !          1331:             LONG    lHeight;
        !          1332:             LONG    lWidth;
        !          1333:             TEXTMETRIC     tm;
        !          1334: 
        !          1335:             if (GetTextMetrics(hDC, &tm)) {
        !          1336:                 lHeight = tm.tmHeight;
        !          1337:                 lWidth  = tm.tmMaxCharWidth;
        !          1338:             }
        !          1339: 
        !          1340:             TextOut(hDC, NextX,    NextY,    lpstr, 1);
1.1       root     1341:             GetCurrentPositionEx(hDC, (LPPOINT) &Pt);
1.1.1.2 ! root     1342:             SetCaretPos(Pt.x+lWidth, Pt.y);
        !          1343: 
        !          1344:             }
        !          1345: 
        !          1346:             SelectObject(hDC, hObjOld);
        !          1347:             //GetCurrentPositionEx(hDC, (LPPOINT) &Pt);
        !          1348:             //SetCaretPos(Pt.x, Pt.y+2);
1.1       root     1349:             ShowCaret(ghwndDrawSurf);
                   1350:             bCaretShown = TRUE;
                   1351: 
                   1352:             break;
                   1353:         }
                   1354:         case DID_RECT:
                   1355:             hObjOld = SelectObject(hDC, GetStockObject(NULL_BRUSH));
                   1356:             Rectangle(hDC, OrgX, OrgY, NextX, NextY);
                   1357:             SelectObject(hDC, hObjOld);
                   1358:             break;
                   1359:         case DID_FILLRECT:
                   1360:             Rectangle(hDC, OrgX, OrgY, NextX, NextY);
                   1361:             break;
                   1362:         case DID_ELLIPSE:
                   1363:             hObjOld = SelectObject(hDC, GetStockObject(NULL_BRUSH));
                   1364:             Ellipse(hDC, OrgX, OrgY, NextX, NextY);
                   1365:             SelectObject(hDC, hObjOld);
                   1366:             break;
                   1367:         case DID_FILLELLIPSE:
                   1368:             Ellipse(hDC, OrgX, OrgY, NextX, NextY);
                   1369:             break;
                   1370:         case DID_LINE:
                   1371:             MoveToEx(hDC, OrgX, OrgY, NULL);
                   1372:             LineTo(hDC, NextX, NextY);
                   1373:             break;
                   1374:         case DID_BEZIER:
                   1375:             if (bErase || bMove)
                   1376:                 return bSuccess;
                   1377: 
                   1378:             if (bCntPt) {
                   1379:                 rgPts[iCnt].x = NextX;
                   1380:                 rgPts[iCnt].y = NextY;
                   1381:                 iCnt++;
                   1382: 
                   1383:                 if (iCnt == MAX_POINTS - 1)
                   1384:                     iCnt = 0;
                   1385:             }
                   1386: 
                   1387:             if ((iCnt % 3) == 1) {              // (iCnt + 1) % 3 == 1
                   1388:                 //
                   1389:                 // Override the ROP2 st. the pen won't erase its track
                   1390:                 //
                   1391:                 SetROP2(hDC, R2_COPYPEN);
                   1392:                 PolyBezier(hDC, (LPPOINT)&rgPts, (DWORD) iCnt);
                   1393:             }
                   1394:             return bSuccess;
                   1395: 
                   1396:         case DID_BMPOBJ: {
                   1397:             static BOOL          bBltReady = FALSE;
                   1398:             HDC                  hDCRef;
                   1399:             HGDIOBJ              hObjOld;
                   1400:             BITMAP               bm;
                   1401: 
                   1402:             if (bErase || bMove)
                   1403:                 return bSuccess;
                   1404: 
                   1405:             if (ghBmp == NULL) {
                   1406:                 SetWindowText(ghTextWnd, "ERROR: No bitmap to embed!");
                   1407:                 return bSuccess;
                   1408:             }
                   1409: 
                   1410:             if (bCntPt) {
                   1411:                 bBltReady = FALSE;
                   1412:                 rgPtsBMP[iCntBMP].x = NextX;
                   1413:                 rgPtsBMP[iCntBMP].y = NextY;
                   1414:                 iCntBMP++;
                   1415: 
                   1416:                 if (iCntBMP < MAX_POINTS_BMP) {
                   1417:                     return bSuccess;
                   1418:                 }
                   1419:             } else {
                   1420:                 //
                   1421:                 // Caller don't want to increment counter, so must be doing
                   1422:                 // recording, so we just Blt again...
                   1423:                 //
                   1424:                 // But, if the Blt data is no good, bail out...
                   1425:                 //
                   1426:                 if (!bBltReady) {
                   1427:                     return bSuccess;
                   1428:                 }
                   1429:                 hDCRef = CreateCompatibleDC(NULL);
                   1430:                 hObjOld = SelectObject(hDCRef, ghBmp);
                   1431:                 GetObject(ghBmp, sizeof(BITMAP), (LPSTR)&bm);
                   1432:                 PlgBlt(hDC, rgPtsBMP, hDCRef, 0, 0, bm.bmWidth, bm.bmHeight,
                   1433:                        ghBmpMask, 0, 0);
                   1434:                 SelectObject(hDCRef, hObjOld);
                   1435:                 DeleteDC(hDCRef);
                   1436:                 return bSuccess;
                   1437:             }
                   1438:             bBltReady = TRUE;
                   1439:             hDCRef = CreateCompatibleDC(NULL);
                   1440:             hObjOld = SelectObject(hDCRef, ghBmp);
                   1441: 
                   1442:             GetObject(ghBmpMask, sizeof(BITMAP), (LPSTR)&bm);
                   1443:             if (bm.bmBitsPixel != 1) {
                   1444:                 SetWindowText(ghTextWnd, "ERROR: Mask has to be a Monochrome bitmap!");
                   1445:                 ghBmpMask = NULL;
                   1446:             }
                   1447: 
                   1448:             //
                   1449:             // Avoiding a HT bug
                   1450:             //
                   1451:             //ghBmpMask = NULL;
                   1452:             GetObject(ghBmp, sizeof(BITMAP), (LPSTR)&bm);
                   1453:             //SetStretchBltMode(hDC, HALFTONE);
                   1454:             PlgBlt(hDC, rgPtsBMP, hDCRef, 0, 0, bm.bmWidth, bm.bmHeight,
                   1455:                    ghBmpMask, 0, 0);
                   1456:             SelectObject(hDCRef, hObjOld);
                   1457:             DeleteDC(hDCRef);
                   1458:             iCntBMP = 0;                         // reset
                   1459:             return bSuccess;
                   1460:         }
                   1461: 
                   1462:         case DID_METAF: {
                   1463:             ENHMETAHEADER EnhMetaHdr;
                   1464:             RECT          rcClientDS;
                   1465:             static XFORM         xform;
                   1466:             static BOOL          bXformReady = FALSE;
                   1467: 
                   1468:             if (bErase || bMove)
                   1469:                 return bSuccess;
                   1470: 
                   1471:             if (ghMetaf == NULL) {
                   1472:                 SetWindowText(ghTextWnd, "ERROR: No metafile to embed!");
                   1473:                 return bSuccess;
                   1474:             }
                   1475: 
                   1476:             if (bCntPt) {
                   1477:                 bXformReady = FALSE;
                   1478:                 rgPtsMF[iCntMF].x = NextX;
                   1479:                 rgPtsMF[iCntMF].y = NextY;
                   1480:                 iCntMF++;
                   1481: 
                   1482:                 if (iCntMF < MAX_POINTS_MF) {
                   1483:                     return bSuccess;
                   1484:                 }
                   1485:             } else {
                   1486:                 //
                   1487:                 // Caller don't want to increment counter, so must be doing
                   1488:                 // recording, so we just set xform and play it again...
                   1489:                 //
                   1490:                 // But, if the xform data is no good, bail out...
                   1491:                 //
                   1492:                 if (!bXformReady) {
                   1493:                     return bSuccess;
                   1494:                 }
                   1495: 
                   1496:                 GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                   1497:                 SetWorldTransform(hDC, &xform);
                   1498:                 GetClientRect(ghwndDrawSurf, &rcClientDS);
                   1499:                 //PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rcClientDS);
                   1500:                 PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &EnhMetaHdr.rclBounds);
                   1501:                 ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   1502:                 return bSuccess;
                   1503:             }
                   1504: 
                   1505:             GetEnhMetaFileHeader(ghMetaf, sizeof(ENHMETAHEADER), &EnhMetaHdr);
                   1506:             //
                   1507:             // Based on the three points, top-left, top-right and bottom-left
                   1508:             // (in this order), of the destination, solve equations for the
                   1509:             // elements of the transformation matrix.
                   1510:             //
                   1511:             xform.eDx = (float) rgPtsMF[0].x;
                   1512:             xform.eDy = (float) rgPtsMF[0].y;
                   1513:             xform.eM11 = (rgPtsMF[1].x - xform.eDx)/(EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left);
                   1514:             xform.eM12 = (rgPtsMF[1].y - xform.eDy)/(EnhMetaHdr.rclBounds.right - EnhMetaHdr.rclBounds.left);
                   1515:             xform.eM21 = (rgPtsMF[2].x - xform.eDx)/(EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top);
                   1516:             xform.eM22 = (rgPtsMF[2].y - xform.eDy)/(EnhMetaHdr.rclBounds.bottom - EnhMetaHdr.rclBounds.top);
                   1517: 
                   1518:             bXformReady = TRUE;
                   1519:             SetWorldTransform(hDC, &xform);
                   1520:             GetClientRect(ghwndDrawSurf, &rcClientDS);
                   1521:             //PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &rcClientDS);
                   1522:             PlayEnhMetaFile(hDC, ghMetaf, (LPRECT) &EnhMetaHdr.rclBounds);
                   1523:             ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   1524:             iCntMF = 0;                         // reset
                   1525:             return bSuccess;
                   1526:         }
                   1527:         default:
                   1528:             break;
                   1529:     }
                   1530:     //
                   1531:     // Reset counter, user has selected other tools.
                   1532:     //
                   1533:     iCnt = 0;
                   1534:     iCntMF = 0;
                   1535:     iCntBMP = 0;
                   1536:     return bSuccess;
                   1537: }
                   1538: 
                   1539: /******************************Public*Routine******************************\
                   1540: *
                   1541: * hemfLoadMetafile
                   1542: *
                   1543: * Effects:   Brings up the Open file common dialog
                   1544: *            Get the enhanced metafile spec'd by user
                   1545: *            returns the handle to the enhanced metafile if successfull
                   1546: *               otherwise, returns 0.
                   1547: *
                   1548: * Warnings:
                   1549: *
                   1550: * History:
                   1551: *  08-May-1992 -by- Petrus Wong
                   1552: * Wrote it.
1.1.1.2 ! root     1553: *  28-Aug-1992 -by- Petrus Wong     supports aldus placable mf, wmf and emf
1.1       root     1554: \**************************************************************************/
                   1555: 
                   1556: HENHMETAFILE hemfLoadMetafile(HWND hwnd) {
                   1557:     OPENFILENAME    ofn;
                   1558:     char            szFile[256], szFileTitle[256];
                   1559:     static char     *szFilter;
                   1560: 
1.1.1.2 ! root     1561:     HMETAFILE       hmf;
        !          1562:     UINT            uiSize;
        !          1563:     LPVOID          pvData;
        !          1564:     HDC             hDCDrawSurf;
        !          1565:     HENHMETAFILE    hemf;
        !          1566: 
        !          1567:     HANDLE                  hFile, hMapFile;
        !          1568:     LPVOID                  pMapFile;
        !          1569:     LPENHMETAHEADER         pemh;
        !          1570: 
        !          1571:     BOOL        bSuccess;
        !          1572: 
        !          1573: 
        !          1574:     bSuccess = TRUE;
        !          1575: 
1.1       root     1576:     szFilter =
1.1.1.2 ! root     1577:       "EnhMeta files (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0";
1.1       root     1578: 
                   1579:     strcpy(szFile, "*.emf\0");
                   1580:     ofn.lStructSize = sizeof(OPENFILENAME);
                   1581:     ofn.hwndOwner = hwnd;
                   1582:     ofn.lpstrFilter = szFilter;
                   1583:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   1584:     ofn.nMaxCustFilter = 0L;
                   1585:     ofn.nFilterIndex = 1;
                   1586:     ofn.lpstrFile = szFile;
                   1587:     ofn.nMaxFile = sizeof(szFile);
                   1588:     ofn.lpstrFileTitle = szFileTitle;
                   1589:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   1590:     ofn.lpstrInitialDir = NULL;
                   1591:     ofn.lpstrTitle = "Load Metafile";
                   1592:     ofn.Flags = 0L;
                   1593:     ofn.nFileOffset = 0;
                   1594:     ofn.nFileExtension = 0;
                   1595:     ofn.lpstrDefExt = "EMF";
                   1596: 
                   1597:     if (!GetOpenFileName(&ofn))
                   1598:         return 0L;
                   1599: 
1.1.1.2 ! root     1600:     if ((hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
        !          1601:             OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == (HANDLE)-1) {
        !          1602:         MessageBox(ghwndMain, "Fail in file open!", "Error", MB_OK);
        !          1603:         return 0L;
        !          1604:     }
        !          1605: 
        !          1606:     //
        !          1607:     // Create a map file of the opened file
        !          1608:     //
        !          1609:     if ((hMapFile = CreateFileMapping(hFile, NULL,
        !          1610:                              PAGE_READONLY, 0, 0, "MapF")) == (HANDLE)-1) {
        !          1611:         MessageBox(ghwndMain, "Fail in creating map file!", "Error", MB_OK);
        !          1612:         bSuccess = FALSE;
        !          1613:         goto ErrorExit1;
        !          1614:     }
        !          1615: 
        !          1616:     //
        !          1617:     // Map a view of the whole file
        !          1618:     //
        !          1619:     if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0)) == NULL) {
        !          1620:         MessageBox(ghwndMain, "Fail in mapping view of the Map File object!", "Error", MB_OK);
        !          1621:         bSuccess = FALSE;
        !          1622:         goto ErrorExit2;
        !          1623:     }
        !          1624: 
        !          1625:     //
        !          1626:     // First check that if it is an enhanced metafile
        !          1627:     //
        !          1628:     pemh = (LPENHMETAHEADER) pMapFile;
        !          1629:     if (pemh->dSignature == META32_SIGNATURE) {
        !          1630:         hemf = GetEnhMetaFile(szFile);
        !          1631:         goto HLM_EXIT;
        !          1632:     }
        !          1633: 
        !          1634:     //
        !          1635:     // If it has an ALDUS header skip it
        !          1636:     // Notice: APMSIZE is used because the HANDLE and RECT of the structure
        !          1637:     //         depends on the environment
        !          1638:     //
        !          1639:     if (*((LPDWORD)pemh) == ALDUS_ID) {
        !          1640:         MessageBox(ghwndMain, "This is an ALDUS metafile!", "Hey!", MB_OK);
        !          1641:         uiSize = *((LPDWORD) ((PBYTE)pMapFile + APMSIZE + 6));
        !          1642:         hDCDrawSurf = GetDC(ghwndDrawSurf);
        !          1643:         hemf = SetWinMetaFileBits(uiSize*2L, (PBYTE)pMapFile + APMSIZE, hDCDrawSurf, NULL);
        !          1644:         ReleaseDC(ghwndDrawSurf, hDCDrawSurf);
        !          1645:         if (!hemf) {
        !          1646:             char text[256];
        !          1647: 
        !          1648:             wsprintf(text, "SetWinMetaFileBits failed, %x", GetLastError());
        !          1649:             MessageBox(ghwndMain, text, "Error!", MB_OK);
        !          1650:         }
        !          1651:         goto HLM_EXIT;
        !          1652:     }
        !          1653: 
        !          1654: 
        !          1655:     //
        !          1656:     // It is a Windows 3x format metafile (hopefully)
        !          1657:     //
        !          1658:     if (!(hmf = GetMetaFile((LPCSTR)szFile))) {
        !          1659:         char text[256];
        !          1660: 
        !          1661:         wsprintf(text, "GetMetaFile failed, %x", GetLastError());
        !          1662:         MessageBox(ghwndMain, text, "Error!", MB_OK);
        !          1663:         bSuccess = FALSE;
        !          1664:         goto ErrorExit3;
        !          1665:     }
        !          1666: 
        !          1667:     if (!(uiSize = GetMetaFileBitsEx(hmf, 0, NULL))) {
        !          1668:         MessageBox(ghwndMain, "Fail in 1st GetMetaFileBitsEx!", "Error", MB_OK);
        !          1669:         return NULL;
        !          1670:     }
        !          1671: 
        !          1672:     if ((pvData = (LPVOID) LocalAlloc(LMEM_FIXED, uiSize)) == NULL) {
        !          1673:         MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
        !          1674:         bSuccess = FALSE;
        !          1675:         goto ErrorExit3;
        !          1676:     }
        !          1677: 
        !          1678:     if (!(uiSize = GetMetaFileBitsEx(hmf, uiSize, pvData))) {
        !          1679:         MessageBox(ghwndMain, "Fail in 2nd GetMetaFileBitsEx!", "Error", MB_OK);
        !          1680:         bSuccess = FALSE;
        !          1681:         goto ErrorExit3;
        !          1682:     }
        !          1683: 
        !          1684:     DeleteMetaFile(hmf);
        !          1685: 
        !          1686:     hDCDrawSurf = GetDC(ghwndDrawSurf);
        !          1687:     hemf = SetWinMetaFileBits(uiSize, (LPBYTE)pvData, hDCDrawSurf, NULL);
        !          1688: 
        !          1689:     LocalFree(pvData);
        !          1690: 
        !          1691:     ReleaseDC(ghwndDrawSurf ,hDCDrawSurf);
        !          1692: 
        !          1693: HLM_EXIT:
        !          1694: ErrorExit3:
        !          1695:     UnmapViewOfFile(pMapFile);
        !          1696: 
        !          1697: ErrorExit2:
        !          1698:     CloseHandle(hMapFile);
        !          1699: ErrorExit1:
        !          1700:     CloseHandle(hFile);
        !          1701: 
        !          1702:     if (bSuccess)
        !          1703:         return hemf;
        !          1704:     else
        !          1705:         return 0L;
1.1       root     1706: }
                   1707: 
                   1708: /******************************Public*Routine******************************\
                   1709: *
                   1710: * hDCRecordMetafileAs
                   1711: *
                   1712: * Effects:   Brings up the SaveAs common dialog
                   1713: *            Creates the enhanced metafile with the filename spec'd by user
                   1714: *            Modifies the second arg to reflect the new default filename
                   1715: *            less extension
                   1716: *            returns the created metafile DC if successful, otherwise, 0
                   1717: *
                   1718: * Warnings:
                   1719: *
                   1720: * History:
                   1721: *  08-May-1992 -by- Petrus Wong
                   1722: * Wrote it.
                   1723: \**************************************************************************/
                   1724: 
                   1725: HDC hDCRecordMetafileAs(HWND hwnd, LPSTR szFilename) {
                   1726:     OPENFILENAME ofn;
                   1727:     char szFile[256], szFileTitle[256];
                   1728:     static char *szFilter;
                   1729:     char *szTmp, szTmp2[256];
                   1730:     HDC  hDCMeta;
                   1731: 
1.1.1.2 ! root     1732:     int iWidthMM, iHeightMM, iWidthPels, iHeightPels, iMMPerPelX, iMMPerPelY;
        !          1733:     RECT rc;
        !          1734:     HDC hDC;
        !          1735: 
        !          1736: 
1.1       root     1737:     szFilter = "EnhMeta files (*.emf)\0\0";
                   1738:     strcpy(szFile, "*.emf\0");
                   1739:     ofn.lStructSize = sizeof(OPENFILENAME);
                   1740:     ofn.hwndOwner = hwnd;
                   1741:     ofn.lpstrFilter = szFilter;
                   1742:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   1743:     ofn.nMaxCustFilter = 0L;
                   1744:     ofn.nFilterIndex = 0L;
                   1745:     ofn.lpstrFile = szFile;
                   1746:     ofn.nMaxFile = sizeof(szFile);
                   1747:     ofn.lpstrFileTitle = szFileTitle;
                   1748:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   1749:     ofn.lpstrInitialDir = NULL;
                   1750:     ofn.lpstrTitle = "Save Metafile As";
                   1751:     ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
                   1752:     ofn.nFileOffset = 0;
                   1753:     ofn.nFileExtension = 0;
                   1754:     ofn.lpstrDefExt = (LPSTR)NULL;
                   1755: 
                   1756:     if (!GetSaveFileName(&ofn)) {
                   1757:         return 0L;
                   1758:     }
                   1759: 
1.1.1.2 ! root     1760: 
        !          1761:     hDC = GetDC(hwnd);
        !          1762:     iWidthMM = GetDeviceCaps(hDC, HORZSIZE);
        !          1763:     iHeightMM = GetDeviceCaps(hDC, VERTSIZE);
        !          1764:     iWidthPels = GetDeviceCaps(hDC, HORZRES);
        !          1765:     iHeightPels = GetDeviceCaps(hDC, VERTRES);
        !          1766:     ReleaseDC(hwnd, hDC);
        !          1767:     iMMPerPelX = (iWidthMM * 100)/iWidthPels;
        !          1768:     iMMPerPelY = (iHeightMM * 100)/iHeightPels;
        !          1769:     GetClientRect(ghwndDrawSurf, &rc);
        !          1770:     rc.left = rc.left * iMMPerPelX;
        !          1771:     rc.top = rc.top * iMMPerPelY;
        !          1772:     rc.right = rc.right * iMMPerPelX;
        !          1773:     rc.bottom = rc.bottom * iMMPerPelY;
        !          1774: 
        !          1775: 
        !          1776: 
        !          1777:     //hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)NULL, (LPSTR)NULL);
        !          1778:     hDCMeta = CreateEnhMetaFile((HDC)NULL, szFile, (LPRECT)&rc, (LPSTR)NULL);
1.1       root     1779: 
                   1780:     //
                   1781:     // parses the new filename, removes the extension and copy it into
                   1782:     // szFilename
                   1783:     //
                   1784:     strcpy(szFilename, "");
                   1785:     szTmp = (char *)strtok(szFile, "\\");
                   1786:     strcpy(szTmp2, szTmp);
                   1787:     while (szTmp != NULL) {
                   1788:         szTmp = (char *)strtok(NULL, "\\");
                   1789:         if (szTmp != NULL) {
                   1790:             strcat(szFilename, szTmp2);
                   1791:             strcpy(szTmp2, szTmp);
                   1792:             strcat(szFilename, "\\");
                   1793:         }
                   1794:     }
                   1795:     szTmp = (char *)strtok(szTmp2, ".");
                   1796:     strcat(szFilename, szTmp);
                   1797: 
                   1798:     return hDCMeta;
                   1799: }
                   1800: 
                   1801: 
                   1802: /******************************Public*Routine******************************\
                   1803: *
                   1804: * bPlayRecord
                   1805: *
                   1806: * Effects:  Play metafile
                   1807: *           if PlayInfo.bPlayContinuous is TRUE
                   1808: *               play metafile from 1st record up to the PlayInfo.iRecord th
                   1809: *                   record
                   1810: *           else only play the PlayInfo.iRecord th record and those preceding
                   1811: *               records that are relevant like MoveTo, etc.
                   1812: *           Terminates enumeration after playing up to the
                   1813: *               PlayInfo.iRecord th record
                   1814: *
                   1815: * Warnings:
                   1816: *
                   1817: * History:
                   1818: *  08-May-1992 -by- Petrus Wong
                   1819: * Wrote it.
                   1820: \**************************************************************************/
                   1821: 
                   1822: BOOL APIENTRY bPlayRecord(HDC hDC, LPHANDLETABLE lpHandleTable,
                   1823:                                    LPENHMETARECORD lpEnhMetaRecord,
                   1824:                                    UINT nHandles,
                   1825:                                    LPVOID lpData) {
                   1826:     BOOL bSuccess;
                   1827:     static int  iCnt=0;
                   1828:     int         i;
                   1829:     char        ach[128];
                   1830:     char        achTmp[128];
                   1831:     LONG        lNumDword;
                   1832: 
                   1833:     bSuccess = TRUE;
                   1834: 
                   1835:     lNumDword = (lpEnhMetaRecord->nSize-8) / 4;
                   1836: 
                   1837:     iCnt++;
                   1838:     if (((PLAYINFO *) lpData)->bPlayContinuous) {
                   1839:         bSuccess = PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   1840:                                              lpEnhMetaRecord, nHandles);
                   1841:         if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   1842:             wsprintf((LPSTR) ach, "%s", rgMetaName[lpEnhMetaRecord->iType]);
                   1843:             for (i=0; i < lNumDword; i++) {
                   1844:                 wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   1845:                 if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   1846:                     break;
                   1847:                 strcat(ach, achTmp);
                   1848:             }
                   1849:         SetWindowText(ghTextWnd, ach);
                   1850:         }
                   1851:     } else {
                   1852: 
                   1853:         switch (lpEnhMetaRecord->iType) {
                   1854:             case MR_SETWINDOWEXTEX:
                   1855:             case MR_SETWINDOWORGEX:
                   1856:             case MR_SETVIEWPORTEXTEX:
                   1857:             case MR_SETVIEWPORTORGEX:
                   1858:             case MR_SETBRUSHORGEX:
                   1859:             case MR_SETMAPMODE:
                   1860:             case MR_SETBKMODE:
                   1861:             case MR_SETPOLYFILLMODE:
                   1862:             case MR_SETROP2:
                   1863:             case MR_SETSTRETCHBLTMODE:
                   1864:             case MR_SETTEXTALIGN:
                   1865:             case MR_SETTEXTCOLOR:
                   1866:             case MR_SETBKCOLOR:
                   1867:             case MR_OFFSETCLIPRGN:
                   1868:             case MR_MOVETOEX:
                   1869:             case MR_SETMETARGN:
                   1870:             case MR_EXCLUDECLIPRECT:
                   1871:             case MR_INTERSECTCLIPRECT:
                   1872:             case MR_SCALEVIEWPORTEXTEX:
                   1873:             case MR_SCALEWINDOWEXTEX:
                   1874:             case MR_SAVEDC:
                   1875:             case MR_RESTOREDC:
                   1876:             case MR_SETWORLDTRANSFORM:
                   1877:             case MR_MODIFYWORLDTRANSFORM:
                   1878:             case MR_SELECTOBJECT:
                   1879:             case MR_CREATEPEN:
                   1880:             case MR_CREATEBRUSHINDIRECT:
                   1881:             case MR_DELETEOBJECT:
                   1882:             case MR_SELECTPALETTE:
                   1883:             case MR_CREATEPALETTE:
                   1884:             case MR_SETPALETTEENTRIES:
                   1885:             case MR_RESIZEPALETTE:
                   1886:             case MR_REALIZEPALETTE:
                   1887:             case MR_SETARCDIRECTION:
                   1888:             case MR_SETMITERLIMIT:
                   1889:             case MR_BEGINPATH:
                   1890:             case MR_ENDPATH:
                   1891:             case MR_CLOSEFIGURE:
                   1892:             case MR_SELECTCLIPPATH:
                   1893:             case MR_ABORTPATH:
                   1894:             case MR_EXTCREATEFONTINDIRECTW:
                   1895:             case MR_CREATEMONOBRUSH:
                   1896:             case MR_CREATEDIBPATTERNBRUSHPT:
                   1897:             case MR_EXTCREATEPEN:
                   1898:                 goto PlayRec;
                   1899:             default:
                   1900:                 break;
                   1901:         } //switch
                   1902: 
                   1903:         if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   1904: PlayRec:
                   1905:             bSuccess = PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   1906:                                              lpEnhMetaRecord, nHandles);
                   1907:             wsprintf((LPSTR) ach, "%s", rgMetaName[lpEnhMetaRecord->iType]);
                   1908:             for (i=0; i < lNumDword; i++) {
                   1909:                 wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   1910:                 if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   1911:                     break;
                   1912:                 strcat(ach, achTmp);
                   1913:             }
                   1914:             SetWindowText(ghTextWnd, ach);
                   1915:         }
                   1916:     }
                   1917: 
                   1918:     if (iCnt == ((PLAYINFO *) lpData)->iRecord) {
                   1919:         iCnt = 0;
                   1920:         return FALSE;
                   1921:     }
                   1922:     return bSuccess;
                   1923: }
                   1924: 
                   1925: /******************************Public*Routine******************************\
                   1926: *
                   1927: * LoadBitmapFile
                   1928: *
                   1929: * Effects:  Loads the bitmap from file and return the bitmap
                   1930: *
                   1931: * Warnings: pszFileName contains the full path
                   1932: *
                   1933: * History:
                   1934: *  13-May-1992 Petrus Wong           return bitmap handle
                   1935: *  09-Jan-1992 -by- Petrus Wong
                   1936: * Wrote it.
                   1937: \**************************************************************************/
                   1938: 
                   1939: HBITMAP hBmpLoadBitmapFile(HDC hDC, PSTR pszFileName)
                   1940: {
                   1941:     HANDLE hFile, hMapFile;
                   1942:     LPVOID pMapFile;
                   1943:     LPBITMAPINFOHEADER pbmh;
                   1944:     LPBITMAPINFO  pbmi;
                   1945:     PBYTE pjTmp;
                   1946:     ULONG sizBMI;
                   1947:     HBITMAP hBitmap;
1.1.1.2 ! root     1948:     INT   iNumClr;
1.1       root     1949: 
                   1950:     hBitmap = NULL;
                   1951: 
                   1952:     if ((hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
                   1953:             OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == (HANDLE)-1) {
                   1954:         SetWindowText(ghTextWnd, "Fail in file open");
                   1955:         goto ErrExit1;
                   1956:     }
                   1957: 
                   1958:     //
                   1959:     // Create a map file of the opened file
                   1960:     //
                   1961:     if ((hMapFile = CreateFileMapping(hFile, NULL,
                   1962:                              PAGE_READONLY, 0, 0, "MapF")) == (HANDLE)-1) {
                   1963:         SetWindowText(ghTextWnd, "Fail in creating map file");
                   1964:         goto ErrExit2;
                   1965: 
                   1966:     }
                   1967: 
                   1968:     //
                   1969:     // Map a view of the whole file
                   1970:     //
                   1971:     if ((pMapFile = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0)) == NULL) {
                   1972:         SetWindowText(ghTextWnd, "Fail in mapping view of the Map File object");
                   1973:         goto ErrExit3;
                   1974:     }
                   1975: 
                   1976:     //
                   1977:     // First check that it is a bitmap file
                   1978:     //
                   1979:     if (*((PWORD)pMapFile) != 0x4d42) {              // 'BM'
                   1980:         MessageBox(ghwndMain, "This is not a DIB bitmap file!", "Error", MB_OK);
                   1981:         goto ErrExit3;
                   1982:     }
                   1983: 
                   1984:     //
1.1.1.2 ! root     1985:     // The file header doesn't end on DWORD boundary...
1.1       root     1986:     //
1.1.1.2 ! root     1987:     pbmh = (LPBITMAPINFOHEADER)((PBYTE)pMapFile + sizeof(BITMAPFILEHEADER));
        !          1988: 
1.1       root     1989:     {
1.1.1.2 ! root     1990:         BITMAPCOREHEADER bmch, *pbmch;
        !          1991:         BITMAPINFOHEADER bmih, *pbmih;
        !          1992:         PBYTE            pjTmp;
        !          1993:         ULONG            ulSiz;
        !          1994: 
        !          1995:         pbmch = &bmch;
        !          1996:         pbmih = &bmih;
        !          1997: 
        !          1998:         pjTmp = (PBYTE)pbmh;
        !          1999:         ulSiz = sizeof(BITMAPCOREHEADER);
        !          2000:         while (ulSiz--) {
        !          2001:             *(((PBYTE)pbmch)++) = *(((PBYTE)pjTmp)++);
        !          2002:         }
        !          2003: 
        !          2004:         pjTmp = (PBYTE)pbmh;
        !          2005:         ulSiz = sizeof(BITMAPINFOHEADER);
        !          2006:         while (ulSiz--) {
        !          2007:             *(((PBYTE)pbmih)++) = *(((PBYTE)pjTmp)++);
        !          2008:         }
        !          2009: 
        !          2010:         //
        !          2011:         // Use the size to determine if it is a BitmapCoreHeader or
        !          2012:         // BitmapInfoHeader
        !          2013:         //
        !          2014:         if (bmch.bcSize == sizeof(BITMAPCOREHEADER))
        !          2015:         {
        !          2016:             WORD wBitCount;
        !          2017: 
        !          2018:             wBitCount = bmch.bcBitCount;
        !          2019:             iNumClr = ((wBitCount == 24) ? 0 : (1 << wBitCount));
        !          2020:             sizBMI = sizeof(BITMAPCOREHEADER)+sizeof(RGBTRIPLE)*iNumClr;
        !          2021:         }
        !          2022:         else            // BITMAPINFOHEADER
        !          2023:         {
        !          2024:             WORD wBitCount;
        !          2025: 
        !          2026:             wBitCount = bmih.biBitCount;
        !          2027:             iNumClr = ((wBitCount == 24) ? 0 : (1 << wBitCount));
        !          2028:             sizBMI = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*iNumClr;
        !          2029:         }
        !          2030: 
        !          2031: 
1.1       root     2032:     }
                   2033: 
                   2034:     if ((pbmi = (LPBITMAPINFO) LocalAlloc(LMEM_FIXED,sizBMI)) == NULL) {
                   2035:         MessageBox(ghwndMain, "Fail in Memory Allocation!", "Error", MB_OK);
                   2036:         goto ErrExit3;
                   2037:     }
                   2038: 
                   2039:     //
                   2040:     // Make sure we pass in a DWORD aligned BitmapInfo to CreateDIBitmap
                   2041:     // Otherwise, exception on the MIPS platform
                   2042:     // CR!!!  Equivalent to memcpy
                   2043:     //
                   2044:     pjTmp = (PBYTE)pbmi;
                   2045: 
                   2046:     while(sizBMI--)
                   2047:     {
                   2048:         *(((PBYTE)pjTmp)++) = *(((PBYTE)pbmh)++);
                   2049:     }
                   2050: 
                   2051:     pMapFile = (PBYTE)pMapFile + ((BITMAPFILEHEADER *)pMapFile)->bfOffBits;
                   2052: 
                   2053:     if ((hBitmap = CreateDIBitmap(hDC, (LPBITMAPINFOHEADER)pbmi,
                   2054:                         CBM_INIT, pMapFile, pbmi, DIB_RGB_COLORS)) == NULL) {
                   2055:         SetWindowText(ghTextWnd, "Fail in creating DIB bitmap from file!");
                   2056:         goto ErrExit4;
                   2057:     }
                   2058: 
                   2059: 
                   2060: 
                   2061: ErrExit4:
                   2062:     LocalFree(pbmi);
                   2063: ErrExit3:
                   2064:     CloseHandle(hMapFile);
                   2065: ErrExit2:
                   2066:     CloseHandle(hFile);
                   2067: ErrExit1:
                   2068: 
                   2069:     return (hBitmap);
                   2070: 
                   2071: }
                   2072: 
                   2073: /******************************Public*Routine******************************\
                   2074: *
                   2075: * bGetBMP
                   2076: *
                   2077: * Effects: call common dialog and pass the filename to hBmpLoadBitmapFile
                   2078: *          return TRUE if successful, FALSE otherwise
                   2079: *
                   2080: * Warnings:
                   2081: *
                   2082: * History:
                   2083: *  13-May-1992 -by- Petrus Wong
                   2084: * Wrote it.
                   2085: \**************************************************************************/
                   2086: 
                   2087: BOOL bGetBMP(HWND hwnd, BOOL bMask) {
                   2088:     OPENFILENAME    ofn;
                   2089:     char            szFile[256], szFileTitle[256];
                   2090:     static char     *szFilter;
                   2091:     BOOL            bSuccess;
                   2092:     HDC             hDC;
                   2093: 
                   2094:     bSuccess = FALSE;
                   2095: 
                   2096:     szFilter =
                   2097:       "DIB files (*.bmp)\0*.bmp\0RLE files (*.rle)\0*.rle\0\0";
                   2098: 
                   2099:     strcpy(szFile, "*.bmp\0");
                   2100:     ofn.lStructSize = sizeof(OPENFILENAME);
                   2101:     ofn.hwndOwner = hwnd;
                   2102:     ofn.lpstrFilter = szFilter;
                   2103:     ofn.lpstrCustomFilter = (LPSTR) NULL;
                   2104:     ofn.nMaxCustFilter = 0L;
                   2105:     ofn.nFilterIndex = 1;
                   2106:     ofn.lpstrFile = szFile;
                   2107:     ofn.nMaxFile = sizeof(szFile);
                   2108:     ofn.lpstrFileTitle = szFileTitle;
                   2109:     ofn.nMaxFileTitle = sizeof(szFileTitle);
                   2110:     ofn.lpstrInitialDir = NULL;
                   2111:     ofn.lpstrTitle = (bMask ? "Load Mask" : "Load Bitmap");
                   2112:     ofn.Flags = 0L;
                   2113:     ofn.nFileOffset = 0;
                   2114:     ofn.nFileExtension = 0;
                   2115:     ofn.lpstrDefExt = "BMP";
                   2116: 
                   2117:     if (!GetOpenFileName(&ofn))
                   2118:         return 0L;
                   2119: 
                   2120:     hDC = GetDC(ghwndDrawSurf);
                   2121:     if (bMask) {
                   2122:         ghBmpMask = hBmpLoadBitmapFile(hDC, szFile);
                   2123:         if (ghBmpMask != NULL)
                   2124:             bSuccess = TRUE;
                   2125:     } else {
                   2126:         ghBmp = hBmpLoadBitmapFile(hDC, szFile);
                   2127:         if (ghBmp != NULL)
                   2128:             bSuccess = TRUE;
                   2129:     }
                   2130:     ReleaseDC(ghwndDrawSurf, hDC);
                   2131: 
                   2132:     return bSuccess;
                   2133: }
                   2134: 
                   2135: /******************************Public*Routine******************************\
                   2136: *
                   2137: * bHitTest
                   2138: *
                   2139: * Effects:  Enumerates metafile records
                   2140: *           Calling bDoHitTest to process each record found.
                   2141: *               The mouse position is passed to the bDoHitTest
                   2142: *
                   2143: * Warnings:
                   2144: *
                   2145: * History:
                   2146: *  20-May-1992 -by- Petrus Wong
                   2147: * Wrote it.
                   2148: \**************************************************************************/
                   2149: 
                   2150: BOOL bHitTest(HDC hDC, INT x, INT y) {
                   2151:     BOOL          bSuccess;
                   2152:     ENHMETAHEADER EnhMetaHdr;
                   2153:     //POINT         point;
                   2154:     //!!!RECT          rcClientDS;
                   2155:     HTDATA        htData;
1.1.1.2 ! root     2156:     static        HCURSOR hCurHT, hCurWait;
1.1       root     2157: 
                   2158:     bSuccess = TRUE;
                   2159: 
                   2160:     if (ghMetaf == 0)
                   2161:         return 0L;
                   2162: 
1.1.1.2 ! root     2163:     hCurHT = LoadCursor(NULL, IDC_CROSS);
        !          2164:     hCurWait = LoadCursor(NULL, IDC_WAIT);
        !          2165: 
1.1       root     2166:     GetEnhMetaFileHeader(ghMetaf, sizeof(EnhMetaHdr), &EnhMetaHdr);
                   2167:     //!!!GetClientRect(ghwndDrawSurf, &rcClientDS);
                   2168:     htData.point.x = x;
                   2169:     htData.point.y = y;
                   2170:     htData.iRecord = EnhMetaHdr.nRecords;
1.1.1.2 ! root     2171: 
        !          2172:     SetCursor(hCurWait);
        !          2173:     EnumEnhMetaFile(hDC, ghMetaf, (ENHMFENUMPROC)bDoHitTest, (LPVOID) &htData, (LPRECT)&EnhMetaHdr.rclBounds);
1.1       root     2174:     //!!!EnumEnhMetaFile(hDC, ghMetaf, (PROC)bDoHitTest, (LPVOID) &point, (LPRECT)&rcClientDS);
1.1.1.2 ! root     2175:     SetCursor(hCurHT);
1.1       root     2176: 
                   2177:     return bSuccess;
                   2178: }
                   2179: 
                   2180: /******************************Public*Routine******************************\
                   2181: *
                   2182: * bDoHitTest
                   2183: *
                   2184: * Effects:      Play all records related to transformation
                   2185: *               Remember new mouse position if the record is a MoveTo
                   2186: *               Convert rectangle, ellipse, lineto and bezier to path
                   2187: *               Widen the path and convert it to region.
                   2188: *               Test if the mouse position is inside the region.
                   2189: *
                   2190: * Warnings:     Only handle rectangle, ellipse, line and polybezier
                   2191: *
                   2192: * History:
                   2193: *  20-May-1992 -by- Petrus Wong
                   2194: * Wrote it.
                   2195: \**************************************************************************/
                   2196: 
                   2197: BOOL APIENTRY bDoHitTest(HDC hDC, LPHANDLETABLE lpHandleTable,
                   2198:                                   LPENHMETARECORD lpEnhMetaRecord,
                   2199:                                   UINT nHandles,
                   2200:                                   LPVOID lpData) {
                   2201:     BOOL            bSuccess;
                   2202:     char            ach[128];
                   2203:     char            achTmp[128];
                   2204:     POINT           PtOrg;
                   2205:     LONG            lNumDword;
                   2206:     XFORM           xfSave;
                   2207:     SIZE            SizeWndEx, SizeViewEx;
                   2208:     POINT           ptWndOrgin, ptViewOrgin;
                   2209:     int             i, iMode;
                   2210:     HRGN            hRgn;
                   2211:     PPOINT          pPt, pPtTmp;
                   2212:     static HGDIOBJ  hObjOld=NULL;
                   2213:     static LONG     lCurX=0;
                   2214:     static LONG     lCurY=0;
                   2215:     static BOOL     bXform=FALSE;
                   2216:     static int      iCnt=0;
                   2217: 
                   2218:     iCnt++;
                   2219: 
                   2220:     //
                   2221:     // select a wide pen for widen path later on
                   2222:     //
                   2223:     hObjOld = SelectObject(hDC, ghpnWide);
                   2224: 
                   2225:     //
                   2226:     // save the mouse hit position, this was passed in as a POINT structure
                   2227:     //
                   2228:     PtOrg.x = (((HTDATA *)lpData)->point).x;
                   2229:     PtOrg.y = (((HTDATA *)lpData)->point).y;
                   2230: 
                   2231:     //
                   2232:     // save the number of parameters for the GDI fcn concerned in DWORD.
                   2233:     // This is the total size of metafile record in question less the
                   2234:     // size of the GDI function
                   2235:     //
                   2236:     lNumDword = (lpEnhMetaRecord->nSize-8) / 4;
                   2237: 
                   2238:     switch (lpEnhMetaRecord->iType) {
                   2239:     case MR_SETWINDOWEXTEX:
                   2240:     case MR_SETWINDOWORGEX:
                   2241:     case MR_SETVIEWPORTEXTEX:
                   2242:     case MR_SETVIEWPORTORGEX:
                   2243:     case MR_SETMAPMODE:
                   2244:     case MR_SCALEVIEWPORTEXTEX:
                   2245:     case MR_SCALEWINDOWEXTEX:
                   2246:     case MR_SETMETARGN:
                   2247:     case MR_SAVEDC:
                   2248:     case MR_RESTOREDC:
                   2249:     case MR_SETWORLDTRANSFORM:
                   2250:     case MR_MODIFYWORLDTRANSFORM: {
                   2251:         //
1.1.1.2 ! root     2252:         // play all records related to transformation & font
1.1       root     2253:         //
                   2254:         PlayEnhMetaFileRecord(hDC, lpHandleTable,
                   2255:                                    lpEnhMetaRecord, nHandles);
                   2256:         bXform = TRUE;
                   2257:         return TRUE;
                   2258:     }
                   2259:     //
                   2260:     // convert the following GDI calls to path for hit testing
                   2261:     //
                   2262:     case MR_RECTANGLE: {
                   2263:         BeginPath(hDC);
                   2264:         Rectangle(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1],
                   2265:                        lpEnhMetaRecord->dParm[2], lpEnhMetaRecord->dParm[3]);
                   2266:         EndPath(hDC);
                   2267:         break;
                   2268:     }
                   2269:     case MR_ELLIPSE: {
                   2270:         BeginPath(hDC);
                   2271:         Ellipse(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1],
                   2272:                      lpEnhMetaRecord->dParm[2], lpEnhMetaRecord->dParm[3]);
                   2273:         EndPath(hDC);
                   2274:         break;
                   2275:     }
                   2276:     case MR_MOVETOEX: {
                   2277:         //
                   2278:         // Remember our current position
                   2279:         //
                   2280:         lCurX = lpEnhMetaRecord->dParm[0];
                   2281:         lCurY = lpEnhMetaRecord->dParm[1];
                   2282:         return TRUE;
                   2283:     }
                   2284:     case MR_LINETO: {
                   2285:         BeginPath(hDC);
                   2286:         MoveToEx(hDC, lCurX, lCurY, NULL);
                   2287:         LineTo(hDC, lpEnhMetaRecord->dParm[0], lpEnhMetaRecord->dParm[1]);
                   2288:         EndPath(hDC);
                   2289:         break;
                   2290:     }
                   2291:     case MR_POLYBEZIER16: {
                   2292:         int         i;
                   2293:         LONG        lSize;
                   2294:         LONG        lPtCnt;
                   2295: 
                   2296:         lPtCnt = lpEnhMetaRecord->dParm[4];
                   2297:         lSize = lPtCnt * sizeof(POINTL);
                   2298: 
                   2299:         if ((pPt = (PPOINT) LocalAlloc(LMEM_FIXED, lSize)) == NULL) {
                   2300:             SetWindowText(ghTextWnd, "ERROR: Failed in Memory Allocation: NO HIT");
                   2301:             return TRUE;
                   2302:         }
                   2303: 
                   2304:         pPtTmp = pPt;
                   2305: 
                   2306:         for (i=0; i < (INT) lPtCnt; i++, pPtTmp++) {
                   2307:             pPtTmp->x = (LONG)(LOWORD(lpEnhMetaRecord->dParm[i+5]));
                   2308:             pPtTmp->y = (LONG)(HIWORD(lpEnhMetaRecord->dParm[i+5]));
                   2309:         }
                   2310: 
                   2311:         BeginPath(hDC);
                   2312:         PolyBezier(hDC, (LPPOINT)pPt, (DWORD) lPtCnt);
                   2313:         EndPath(hDC);
                   2314:         LocalFree(pPt);
                   2315:         break;
                   2316:     }
                   2317:     default:
1.1.1.2 ! root     2318:         wsprintf((LPSTR) ach, "NO HIT: I don't Hit-Test %s", rgMetaName[lpEnhMetaRecord->iType]);
        !          2319:         SetWindowText(ghTextWnd, ach);
1.1       root     2320:         return TRUE;
                   2321:     }   //switch
                   2322: 
                   2323:     if (bXform) {
                   2324:         //
                   2325:         // Set World transform to identity temporarily so that pen width
                   2326:         // is not affected by world to page transformation
                   2327:         //
                   2328:         GetWorldTransform(hDC, &xfSave);
                   2329:         ModifyWorldTransform(hDC, NULL, MWT_IDENTITY);
                   2330: 
                   2331:         //
                   2332:         // Set Page transform to identity temporarily so that pen width
                   2333:         // is not affected by page to device transformation
                   2334:         //
                   2335:         iMode = GetMapMode(hDC);
                   2336: 
                   2337:         if ((iMode == MM_ISOTROPIC) || (iMode == MM_ANISOTROPIC)) {
                   2338:             GetWindowOrgEx(hDC, &ptWndOrgin);
                   2339:             GetWindowExtEx(hDC, &SizeWndEx);
                   2340:             GetViewportExtEx(hDC, &SizeViewEx);
                   2341:             GetViewportOrgEx(hDC, &ptViewOrgin);
                   2342:         }
                   2343: 
                   2344:         SetMapMode(hDC, MM_TEXT);
                   2345:     }
                   2346: 
                   2347:     WidenPath(hDC);
                   2348: 
                   2349:     hRgn = PathToRegion(hDC);
                   2350: 
                   2351:     if (hRgn == 0) {
                   2352:         SetWindowText(ghTextWnd, "ERROR: Null Region: NO HIT");
                   2353:         DeleteObject(hRgn);
                   2354:         return TRUE;
                   2355:     }
                   2356:     //DPtoLP(hDC, &PtOrg, 1);
                   2357:     //SetPixel(hDC, PtOrg.x, PtOrg.y, RGB(0, 255, 0));
                   2358:     //
                   2359:     // test if mouse hit position is in region
                   2360:     //
                   2361:     bSuccess = PtInRegion(hRgn, PtOrg.x, PtOrg.y);
                   2362:     //Temporily comment this out to avoid a bug in 265
1.1.1.2 ! root     2363:     FillRgn(hDC, hRgn, ghbrRed);
1.1       root     2364:     DeleteObject(hRgn);
                   2365:     //
                   2366:     // Set transform back.
                   2367:     //
                   2368:     if (bXform) {
                   2369:         SetWorldTransform(hDC, &xfSave);
                   2370:         SetMapMode(hDC, iMode);
                   2371: 
                   2372:         if ((iMode == MM_ISOTROPIC) || (iMode == MM_ANISOTROPIC)) {
                   2373:             SetWindowOrgEx(hDC, ptWndOrgin.x, ptWndOrgin.y, NULL);
                   2374:             SetWindowExtEx(hDC, SizeWndEx.cx, SizeWndEx.cy, NULL);
                   2375:             SetViewportExtEx(hDC, SizeViewEx.cx, SizeViewEx.cy, NULL);
                   2376:             SetViewportOrgEx(hDC, ptViewOrgin.x, ptViewOrgin.y, NULL);
                   2377:         }
                   2378:     }
                   2379: 
                   2380:     if (bSuccess) {
                   2381:         Beep(440, 500);
                   2382:         //
                   2383:         // Reporting the metafile record number.  Then reset counter.
                   2384:         //
                   2385:         SetDlgItemInt(ghwndCtrlPanel, DID_COUNTER, iCnt, FALSE);
                   2386:         iCnt=0;
                   2387:         wsprintf((LPSTR) ach, "HIT %s", rgMetaName[lpEnhMetaRecord->iType]);
                   2388: 
                   2389:         for (i=0; i < lNumDword; i++) {
                   2390:             wsprintf((LPSTR) achTmp, "%ld ", lpEnhMetaRecord->dParm[i]);
                   2391:             if ((strlen(ach)+strlen(achTmp))/sizeof(char) >= 128)
                   2392:                 break;
                   2393:             strcat(ach, achTmp);
                   2394:         }
                   2395: 
                   2396:         SetWindowText(ghTextWnd, ach);
                   2397:         SelectObject(hDC, hObjOld);
                   2398:         bXform = FALSE;
                   2399:         return FALSE;
                   2400:     }
                   2401:     SetWindowText(ghTextWnd, "NO HIT");
                   2402:     if (iCnt >= ((HTDATA *)lpData)->iRecord)
                   2403:         iCnt = 0;
                   2404:     return TRUE;
                   2405: 
                   2406:     UNREFERENCED_PARAMETER(lpHandleTable);
                   2407:     UNREFERENCED_PARAMETER(nHandles);
                   2408: 
                   2409: }
                   2410: 
                   2411: /******************************Public*Routine******************************\
                   2412: *
                   2413: * bChooseNewFont
                   2414: *
                   2415: * Effects:
                   2416: *
                   2417: * Warnings:
                   2418: *
                   2419: * History:
                   2420: *  20-May-1992 -by- Petrus Wong
                   2421: * Wrote it.
                   2422: \**************************************************************************/
                   2423: 
                   2424: BOOL bChooseNewFont(HWND hwnd, PLOGFONT plf, COLORREF *pClrRef) {
                   2425:    HDC          hDC;
                   2426:    CHOOSEFONT   chf;
                   2427: 
                   2428:    hDC = GetDC( hwnd );
                   2429:    chf.hDC = CreateCompatibleDC( hDC );
                   2430:    ReleaseDC( hwnd, hDC );
                   2431:    chf.lStructSize = sizeof(CHOOSEFONT);
                   2432:    chf.hwndOwner = hwnd;
                   2433:    chf.lpLogFont = plf;
                   2434:    chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
                   2435:    chf.rgbColors = *pClrRef;
                   2436:    chf.lCustData = 0;
                   2437:    chf.hInstance = (HANDLE)NULL;
                   2438:    chf.lpszStyle = (LPSTR)NULL;
                   2439:    chf.nFontType = SCREEN_FONTTYPE;
                   2440:    chf.nSizeMin = 0;
                   2441:    chf.nSizeMax = 0;
                   2442:    chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
1.1.1.2 ! root     2443:    chf.lpfnHook = (LPCFHOOKPROC)NULL;
1.1       root     2444:    chf.lpTemplateName = (LPSTR)NULL;
                   2445: 
                   2446:    if (ChooseFont( &chf ) == FALSE ) {
                   2447:         DeleteDC( hDC );
                   2448:        return FALSE;
                   2449:    }
                   2450: 
                   2451:    *pClrRef = chf.rgbColors;
                   2452: 
                   2453:    DeleteDC( hDC );
                   2454:    return (TRUE);
                   2455: }
                   2456: 
                   2457: /******************************Public*Routine******************************\
                   2458: *
                   2459: * bChooseNewColor
                   2460: *
                   2461: * Effects:  Returns TRUE if successful; lpdwRGB points the color selected.
                   2462: *           Otherwise, FALSE.
                   2463: *
                   2464: * Warnings:
                   2465: *
                   2466: * History:
                   2467: *  21-May-1992 -by- Petrus Wong
                   2468: * Wrote it.
                   2469: \**************************************************************************/
                   2470: 
                   2471: BOOL bChooseNewColor(HWND hwnd, LPDWORD lpdwRGB) {
                   2472:     static DWORD argbCust[16] = {
                   2473:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2474:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2475:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2476:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2477:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2478:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2479:         RGB(255, 255, 255), RGB(255, 255, 255),
                   2480:         RGB(255, 255, 255), RGB(255, 255, 255)
                   2481:     };
                   2482:     CHOOSECOLOR cc;
                   2483:     BOOL bResult;
                   2484: 
                   2485:     cc.lStructSize = sizeof(CHOOSECOLOR);
                   2486:     cc.hwndOwner = hwnd;
                   2487:     cc.hInstance = ghModule;
                   2488:     cc.rgbResult = *lpdwRGB;
                   2489:     cc.lpCustColors = argbCust;
                   2490:     cc.Flags = CC_RGBINIT | CC_SHOWHELP;
                   2491:     cc.lCustData = 0;
                   2492:     cc.lpfnHook = NULL;
                   2493:     cc.lpTemplateName = NULL;
                   2494: 
                   2495:     bResult = ChooseColor(&cc);
                   2496: 
                   2497:     if (bResult) {
                   2498:         *lpdwRGB = cc.rgbResult;
                   2499:         return TRUE;
                   2500:     }
                   2501: 
                   2502:     return FALSE;
                   2503: }
                   2504: 
                   2505: 
                   2506: /******************************Public*Routine******************************\
                   2507: *
                   2508: * hBrCreateBrush
                   2509: *
                   2510: * Effects: Creates a brush with the specified RGB
                   2511: *
                   2512: * Warnings:
                   2513: *
                   2514: * History:
                   2515: *  04-Mar-1992 -by- Petrus Wong
                   2516: * Wrote it.
                   2517: \**************************************************************************/
                   2518: 
                   2519: HBRUSH hBrCreateBrush(HDC hDC, DWORD dwRGB)
                   2520: {
                   2521:     HDC hdcMem;
                   2522:     HBRUSH hbr;
                   2523:     HBRUSH hbrOld;
                   2524:     HBITMAP hbmPat;
                   2525:     HBITMAP hbmOld;
                   2526: 
                   2527:     hbr = CreateSolidBrush(dwRGB);
                   2528:     hdcMem = CreateCompatibleDC(hDC);
                   2529: 
                   2530:     //
                   2531:     // Minimum size for a bitmap to be used in a fill pattern is 8x8
                   2532:     //
                   2533:     hbmPat = CreateCompatibleBitmap(hDC, 8, 8);
                   2534: 
                   2535:     hbmOld = SelectObject(hdcMem, hbmPat);
                   2536:     hbrOld = SelectObject(hdcMem, hbr);
                   2537:     PatBlt(hdcMem, 0, 0, 8, 8, PATCOPY);
                   2538: 
                   2539:     //
                   2540:     // Deselect hbmPat and hbr
                   2541:     //
                   2542:     SelectObject(hdcMem, hbmOld);
                   2543:     SelectObject(hdcMem, hbrOld);
                   2544: 
                   2545:     DeleteDC(hdcMem);
                   2546:     DeleteObject(hbr);
                   2547: 
                   2548:     hbr = CreatePatternBrush(hbmPat);
                   2549: 
                   2550:     DeleteObject(hbmPat);
                   2551: 
                   2552:     return hbr;
                   2553: }

unix.superglobalmegacorp.com

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