home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / SAMPLES / WMFDCODE / DLGPROC.C_ / DLGPROC.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  27.3 KB  |  864 lines

  1. /***********************************************************************
  2.  
  3.   MODULE     : DLGPROC.C
  4.  
  5.   FUNCTIONS  : WMFRecDlgProc
  6.                EnumRangeDlgProc
  7.                PlayFromListDlgProc
  8.                HeaderDlgProc
  9.                AldusHeaderDlgProc
  10.                ClpHeaderDlgProc
  11.                ListDlgProc
  12.                About
  13.  
  14.   COMMENTS   :
  15.  
  16.   HISTORY    : 1/16/91 - created - drc
  17.  
  18. ************************************************************************/
  19.  
  20. #include "windows.h"
  21. #include "wmfdcode.h"
  22.  
  23. /***********************************************************************
  24.  
  25.   FUNCTION   : WMFRecDlgProc
  26.  
  27.   PARAMETERS : HWND hDlg
  28.                unsigned message
  29.                WORD wParam
  30.                LONG lParam
  31.  
  32.   PURPOSE    : dialog procedure to handle the user input from the
  33.                dialog box that displays the contents of the metafile
  34.                record.
  35.  
  36.   CALLS      : WINDOWS
  37.                  lstrcpy
  38.                  GlobalLock
  39.                  GlobalUnlock
  40.                  wsprintf
  41.                  SendDlgItemMessage
  42.                  EndDialog
  43.                APP
  44.                  WaitCursor
  45.  
  46.   MESSAGES   : WM_INITDIALOG
  47.                WM_COMMAND
  48.  
  49.   RETURNS    : BOOL
  50.  
  51.   COMMENTS   :
  52.  
  53.   HISTORY    : 1/16/91 - created - drc
  54.  
  55. ************************************************************************/
  56.  
  57. BOOL FAR PASCAL __export WMFRecDlgProc(hDlg, message, wParam, lParam)
  58. HWND hDlg;
  59. unsigned message;
  60. WORD wParam;
  61. LONG lParam;
  62. {
  63.   int i;
  64.   char szMetaFunction[50];
  65.   HFONT hFont;
  66.  
  67.   switch (message)
  68.   {
  69.   case WM_INITDIALOG:
  70.  
  71.       /* font for the parameters listbox */
  72.       hFont = GetStockObject(ANSI_FIXED_FONT);
  73.  
  74.       /* select that font into the parameter listbox */
  75.       SendDlgItemMessage(hDlg, IDL_PARAMETERS, WM_SETFONT, hFont, (LONG)FALSE);
  76.  
  77.       /* initialize the controls of the dialog box to reflect the
  78.          contents of the current metafile record */
  79.  
  80.       /* lookup the metafile function */
  81.       for (i = 0; i < NUMMETAFUNCTIONS; i++) {
  82.         if (MetaRec.rdFunction == MetaFunctions[i].value)
  83.             break;
  84.         }
  85.  
  86.         /* if not found then it is an unknown record */
  87.         if (MetaRec.rdFunction != MetaFunctions[i].value)
  88.             lstrcpy((LPSTR)szMetaFunction, (LPSTR)"Unknown");
  89.         else
  90.             lstrcpy((LPSTR)szMetaFunction,(LPSTR)MetaFunctions[i].szFuncName);
  91.  
  92.       /* init the record number */
  93.       SetDlgItemInt(hDlg, IDE_RECNUM, iRecNum, FALSE);
  94.  
  95.       /* init the size control */
  96.       SetDlgItemInt(hDlg, IDE_RECSIZE, (WORD)MetaRec.rdSize, FALSE);
  97.  
  98.       /* init the function name control */
  99.       SetDlgItemText(hDlg, IDE_FUNCTION, (LPSTR)szMetaFunction);
  100.  
  101.       /* check the Hex radio button */
  102.       SendDlgItemMessage(hDlg, IDB_HEX, BM_SETCHECK, TRUE, 0L);
  103.  
  104.       /* load the parameter listbox with the parameters displayed in hex bytes */
  105.       LoadParameterLB(hDlg, MetaRec.rdSize - 3, IDB_HEX);
  106.  
  107.       return(TRUE);
  108.       break;
  109.    
  110.    case WM_COMMAND:
  111.       switch(wParam)
  112.         {
  113.  
  114.         /* this will handle the checking and  unchecking of the three buttons */
  115.         case IDB_HEX:
  116.         case IDB_DEC:
  117.         case IDB_CHAR:
  118.             CheckRadioButton(hDlg, IDB_HEX,  IDB_CHAR, wParam );
  119.             LoadParameterLB(hDlg, MetaRec.rdSize - 3,  wParam);
  120.             break;
  121.  
  122.         case IDGO:
  123.             /* display the hourglass cursor while metafile is playing */
  124.             WaitCursor(TRUE);
  125.  
  126.             bPlayItAll = TRUE;
  127.             bEnumRange = FALSE;
  128.             /* fall through with appropriate flags set */
  129.  
  130.         case IDOK:
  131.             bPlayRec = TRUE;
  132.             /* fall through with appropriate flags set */
  133.  
  134.         case IDCANCEL:
  135.             EndDialog(hDlg, TRUE);
  136.             return(TRUE);
  137.             break;
  138.  
  139.         case IDQUITENUM:
  140.             /* quit the enumeration.  Setup Dialogbox to return
  141.                FALSE as this return value is checked in a test
  142.                to end the enumeration */
  143.             EndDialog(hDlg, FALSE);
  144.             return(TRUE);
  145.             break; 
  146.  
  147.         default:
  148.            return (FALSE);
  149.         }
  150.      break;
  151.  
  152.   default:
  153.      return(FALSE);
  154.      break;
  155.    }
  156. return (TRUE);
  157. }
  158.  
  159. /***********************************************************************
  160.  
  161.   FUNCTION   : EnumRangeDlgProc
  162.  
  163.   PARAMETERS : HWND hDlg
  164.                unsigned message
  165.                WORD wParam
  166.                LONG lParam
  167.  
  168.   PURPOSE    : This dialog box lets the user specify whether all records
  169.                or a range are to be played.
  170.  
  171.   CALLS      : WINDOWS
  172.                  SendDlgItemMessage
  173.                  GetDlgItemInt
  174.                  HIWORD
  175.                  MessageBox
  176.                  SetFocus
  177.                  InvalidateClientRect
  178.                  EndDialog
  179.  
  180.   MESSAGES   : WM_INITDIALOG
  181.                WM_COMMAND
  182.  
  183.   RETURNS    : BOOL
  184.  
  185.   COMMENTS   :
  186.  
  187.   HISTORY    : 1/16/91 - created - Dennis Crain
  188.  
  189. ************************************************************************/
  190.  
  191. BOOL FAR PASCAL __export EnumRangeDlgProc(hDlg, message, wParam, lParam)
  192. HWND hDlg;                                /* window handle of the dialog box */
  193. unsigned message;                         /* type of message                 */
  194. WORD wParam;                              /* message-specific information    */
  195. LONG lParam;
  196. {
  197.     BOOL lpTranslated;
  198.     RECT rect;
  199.  
  200.     switch (message) {
  201.         case WM_INITDIALOG:
  202.             /* play all of the mf records is the default */
  203.             SendDlgItemMessage(hDlg, IDCB_ALL, BM_SETCHECK, 1, 0L);
  204.             return (TRUE);
  205.  
  206.         case WM_COMMAND:
  207.             switch (wParam)
  208.                 {
  209.                 case IDE_FROM:
  210.  
  211.                     /* if the user elects to play a range of record then
  212.                        turn the play all check off */
  213.  
  214.                     if (HIWORD(lParam) == EN_CHANGE)
  215.                         SendDlgItemMessage(hDlg, IDCB_ALL, BM_SETCHECK, 0, 0L);
  216.                     break;
  217.  
  218.                 case IDE_TO:
  219.                     if (HIWORD(lParam) == EN_CHANGE)
  220.                         SendDlgItemMessage(hDlg, IDCB_ALL, BM_SETCHECK, 0, 0L);
  221.                     break;
  222.  
  223.                 case IDOK:
  224.  
  225.                    /* if a range of records is to be played */
  226.  
  227.                    if ( !IsDlgButtonChecked(hDlg, IDCB_ALL) ) {
  228.  
  229.                      /* set the enumerate range flag */
  230.                      bEnumRange = TRUE;
  231.  
  232.                      /* initialize the play record flag */
  233.                      bPlayRec = FALSE;
  234.  
  235.                      /* get the range */
  236.                      iStartRange = GetDlgItemInt(hDlg, IDE_FROM, (BOOL FAR *)&lpTranslated, FALSE);
  237.  
  238.                      /* trap the error where the start value has not been entered */
  239.                      if (!iStartRange) {
  240.                          MessageBox(hWndMain, "Invalid FROM value",
  241.                                     NULL, MB_OK | MB_ICONEXCLAMATION);
  242.                          SetFocus(GetDlgItem(hDlg, IDE_FROM));
  243.                      break;
  244.  
  245.                      }
  246.  
  247.                      iEndRange = GetDlgItemInt(hDlg, IDE_TO, (BOOL FAR *)&lpTranslated, FALSE);
  248.                      if (!iEndRange) {
  249.                          MessageBox(hWndMain, "Invalid TO value",
  250.                                     NULL, MB_OK | MB_ICONEXCLAMATION);
  251.                          SetFocus(GetDlgItem(hDlg, IDE_TO));
  252.  
  253.                         break;
  254.                      }
  255.  
  256.                    }
  257.                    /* all records are to be played */
  258.                    else {
  259.                      /* set the enumerate range to false */
  260.                      bEnumRange = FALSE;
  261.  
  262.                      /* initialize the play it all flag - yes this should
  263.                         be false! */
  264.                      bPlayItAll = FALSE;
  265.  
  266.                      /* init the play record flag */
  267.                      bPlayRec = TRUE;
  268.                    }
  269.                    /* force paint of the client area */
  270.                    GetClientRect(hWndMain, (LPRECT)&rect);
  271.                    InvalidateRect(hWndMain, (LPRECT)&rect, TRUE);
  272.  
  273.                    EndDialog(hDlg, TRUE);
  274.                    return (TRUE);
  275.                    break;
  276.  
  277.                 case IDCANCEL:
  278.                    /* user didn't really want to play the metafile */
  279.                    bEnumRange = FALSE;
  280.                    bPlayItAll = TRUE;
  281.                    bPlayRec   = FALSE;
  282.                    EndDialog(hDlg, IDCANCEL);
  283.                    return (TRUE);
  284.                    break;
  285.  
  286.                 default:
  287.                    return (FALSE);
  288.                 }
  289.         break;
  290.     }
  291.     return (FALSE);                           /* Didn't process a message    */
  292. }
  293.  
  294. /***********************************************************************
  295.  
  296.   FUNCTION   : PlayFromListDlgProc
  297.  
  298.   PARAMETERS : HWND hDlg
  299.                unsigned message
  300.                WORD wParam
  301.                LONG lParam
  302.  
  303.   PURPOSE    : a means to indicate whether the selected or unselected
  304.                records among the list of metafile records are to be
  305.                played.
  306.  
  307.   CALLS      : WINDOWS
  308.                  SendDlgItemMessage
  309.                  IsDlgButtonChecked
  310.                  HIWORD
  311.  
  312.   MESSAGES   : WM_INITDIALOG
  313.                WM_COMMAND
  314.  
  315.   RETURNS    : BOOL
  316.  
  317.   COMMENTS   :
  318.  
  319.   HISTORY    : 1/16/91 - created - Dennis Crain
  320.  
  321. ************************************************************************/
  322.  
  323. BOOL FAR PASCAL __export PlayFromListDlgProc(hDlg, message, wParam, lParam)
  324. HWND hDlg;
  325. unsigned message;
  326. WORD wParam;
  327. LONG lParam;
  328. {
  329.     switch (message) {
  330.         case WM_INITDIALOG:
  331.             /* the default is to play the selected records */
  332.             SendDlgItemMessage(hDlg, IDCB_SEL, BM_SETCHECK, 1, 0L);
  333.             return (TRUE);
  334.  
  335.         case WM_COMMAND:
  336.             switch (wParam)
  337.             {
  338.               case IDOK:
  339.                 /* was the play selected or play unselected button checked? */
  340.                 if ( IsDlgButtonChecked(hDlg, IDCB_SEL) )
  341.                     bPlaySelList = TRUE;
  342.                 else
  343.                     bPlaySelList = FALSE;
  344.  
  345.                 EndDialog(hDlg, TRUE);
  346.                 return (TRUE);
  347.  
  348.               case IDCB_SEL:
  349.                 /* show the button click */
  350.                 if (HIWORD(lParam) == BN_CLICKED)
  351.                    SendDlgItemMessage(hDlg, IDCB_UNSEL, BM_SETCHECK, 0, 0L);
  352.                 break;
  353.  
  354.               case IDCB_UNSEL:
  355.                 /* show the button click */
  356.                 if (HIWORD(lParam) == BN_CLICKED)
  357.                    SendDlgItemMessage(hDlg, IDCB_SEL, BM_SETCHECK, 0, 0L);
  358.                 break;
  359.  
  360.               default:
  361.                 return (FALSE);
  362.  
  363.             }
  364.             break;
  365.     }
  366.     return (FALSE);
  367. }
  368.  
  369. /***********************************************************************
  370.  
  371.   FUNCTION   : HeaderDlgProc
  372.  
  373.   PARAMETERS : HWND hDlg
  374.                unsigned message
  375.                WORD wParam
  376.                LONG lParam
  377.  
  378.   PURPOSE    : show the "standard" metafile header as described in the
  379.                Windows SDK section 9.5.1 of the SDK Reference volume 2
  380.  
  381.   CALLS      : WINDOWS
  382.                  wsprintf
  383.                  SetDlgItemText
  384.                  EndDialog
  385.  
  386.   MESSAGES   : WM_INITDIALOG
  387.                WM_COMMAND
  388.  
  389.   RETURNS    : BOOL
  390.  
  391.   COMMENTS   : Metafile header format
  392.  
  393.                WORD    mtType;
  394.                WORD    mtHeaderSize;
  395.                WORD    mtVersion;
  396.                DWORD   mtSize;
  397.                WORD    mtNoObjects;
  398.                DWORD   mtMaxRecord;
  399.  
  400.                These fields have the following  meanings:
  401.  
  402.                Field          Definition
  403.  
  404.                mtType         specifies whether the metafile is in
  405.                               memory or recorded in a disk file.
  406.                               1 == memory 2 == disk
  407.  
  408.                mtHeaderSize   Specifies the size in words of the metafile
  409.                               header
  410.  
  411.                mtVersion      Specifies the Windows version number.
  412.  
  413.                mtSize         Specifies the size in words of the file
  414.  
  415.                mtNoObjects    Specifies the maximum number of objects that
  416.                               exist in the metafile at the same time
  417.  
  418.                mtMaxRecord    Specifies the size in words of the largest
  419.                               record in the metafile.
  420.  
  421.                mtNoParameters Is not used
  422.  
  423.   HISTORY    : 1/16/91 - created - Dennis Crain
  424.  
  425. ************************************************************************/
  426.  
  427. BOOL FAR PASCAL __export HeaderDlgProc(hDlg, message, wParam, lParam)
  428. HWND hDlg;                                /* window handle of the dialog box */
  429. unsigned message;                         /* type of message                 */
  430. WORD wParam;                              /* message-specific information    */
  431. LONG lParam;
  432. {
  433.     char szBuf[30];
  434.  
  435.     switch (message) {
  436.         case WM_INITDIALOG:
  437.             /* format the Windows version number */
  438.             wsprintf((LPSTR)szBuf, "%x", mfHeader.mtVersion);
  439.             SetDlgItemText(hDlg, IDS_VER, (LPSTR)szBuf);
  440.  
  441.             /* format the size of the metafile */
  442.             wsprintf((LPSTR)szBuf, "%lu", mfHeader.mtSize * 2L);
  443.             SetDlgItemText(hDlg, IDS_SIZE, (LPSTR)szBuf);
  444.  
  445.             /* format the maximum numbers of objects that exist
  446.                in the metafile at the same time */
  447.             wsprintf((LPSTR)szBuf, "%d", mfHeader.mtNoObjects);
  448.             SetDlgItemText(hDlg, IDS_OBJECTS, (LPSTR)szBuf);
  449.  
  450.             /* format the size of the largest record in the metafile */
  451.             wsprintf((LPSTR)szBuf, "%lu", mfHeader.mtMaxRecord);
  452.             SetDlgItemText(hDlg, IDS_MAXREC, (LPSTR)szBuf);
  453.             return (TRUE);
  454.  
  455.         case WM_COMMAND:
  456.             if (wParam == IDOK) {
  457.                 EndDialog(hDlg, TRUE);
  458.                 return (TRUE);
  459.             }
  460.             break;
  461.     }
  462.     return (FALSE);
  463. }
  464.  
  465. /***********************************************************************
  466.  
  467.   FUNCTION   : AldusHeaderDlgProc
  468.  
  469.   PARAMETERS : HWND hDlg
  470.                unsigned message
  471.                WORD wParam
  472.                LONG lParam
  473.  
  474.   PURPOSE    : show the "extended" header of Aldus Placeable Metafiles.
  475.  
  476.   CALLS      : WINDOWS
  477.                  wsprintf
  478.                  SetDlgItemText
  479.                  EndDialog
  480.  
  481.   MESSAGES   : WM_INITDIALOG
  482.                WM_COMMAND
  483.  
  484.   RETURNS    : BOOL
  485.  
  486.   COMMENTS   : Aldus placeable metafile format
  487.  
  488.                DWORD    key;
  489.                HANDLE   hmf;
  490.                RECT     bbox;
  491.                WORD     inch;
  492.                DWORD    reserved;
  493.                WORD     checksum;
  494.                char     metafileData[];
  495.  
  496.                These fields have the following  meanings:
  497.  
  498.                Field         Definition
  499.  
  500.                key           Binary key that uniquely identifies this
  501.                              file type.  This must be 0x9AC6CDD7L.
  502.  
  503.                hmf           Unused;  must be zero.
  504.  
  505.                bbox          The coordinates of a rectangle that tightly
  506.                              bounds the picture. These coordinates are in
  507.                              metafile units as defined below.
  508.  
  509.                inch          The number of metafile units to the inch.  To
  510.                              avoid numeric overflow in PageMaker, this value
  511.                              should be less than 1440.
  512.  
  513.                reserved      A reserved double word.  Must be zero.
  514.  
  515.                checksum      A checksum of the 10 words that precede it,
  516.                              calculated by XORing zero with these 10 words
  517.                              and putting the result in the checksum field.
  518.  
  519.                metafileData  The actual content of the Windows metafile
  520.                              retrieved by copying the data returned by
  521.                              GetMetafileBits to the file.  The number of
  522.                              bytes should be equal to the MS-DOS file length
  523.                              minus 22.  The content of a PageMaker placeable
  524.                              metafile  cannot currently exceed 64K (this may
  525.                              have changed in 4.0).
  526.  
  527.   HISTORY    : 1/16/91 - created - Dennis Crain
  528.  
  529. ************************************************************************/
  530.  
  531. BOOL FAR PASCAL __export AldusHeaderDlgProc(hDlg, message, wParam, lParam)
  532. HWND hDlg;                                /* window handle of the dialog box */
  533. unsigned message;                         /* type of message                 */
  534. WORD wParam;                              /* message-specific information    */
  535. LONG lParam;
  536. {
  537.     char szBuf[30];
  538.  
  539.     switch (message) {
  540.         case WM_INITDIALOG:
  541.             /* format the key */
  542.             wsprintf((LPSTR)szBuf, "%lx", aldusMFHeader.key);
  543.             SetDlgItemText(hDlg, IDS_KEY, (LPSTR)szBuf);
  544.  
  545.             /* format the x origin of the bounding rectangle */
  546.             wsprintf((LPSTR)szBuf, "%d", aldusMFHeader.bbox.left);
  547.             SetDlgItemText(hDlg, IDS_LEFT, (LPSTR)szBuf);
  548.  
  549.             /* format the x extent of the bounding rectangle */
  550.             wsprintf((LPSTR)szBuf, "%d", aldusMFHeader.bbox.right);
  551.             SetDlgItemText(hDlg, IDS_RIGHT, (LPSTR)szBuf);
  552.  
  553.             /* format the y origin of the bounding rectangle */
  554.             wsprintf((LPSTR)szBuf, "%d", aldusMFHeader.bbox.top);
  555.             SetDlgItemText(hDlg, IDS_TOP, (LPSTR)szBuf);
  556.  
  557.             /* format the y extent of the bounding rectangle */
  558.             wsprintf((LPSTR)szBuf, "%d", aldusMFHeader.bbox.bottom);
  559.             SetDlgItemText(hDlg, IDS_BOT, (LPSTR)szBuf);
  560.  
  561.             /* format the number of metafile units per inch */
  562.             wsprintf((LPSTR)szBuf, "%d", aldusMFHeader.inch);
  563.             SetDlgItemText(hDlg, IDS_INCH, (LPSTR)szBuf);
  564.  
  565.             /* format the checksum */
  566.             wsprintf((LPSTR)szBuf, "%x", aldusMFHeader.checksum);
  567.             SetDlgItemText(hDlg, IDS_CHKSUM, (LPSTR)szBuf);
  568.  
  569.             return (TRUE);
  570.  
  571.         case WM_COMMAND:                      /* message: received a command */
  572.             if (wParam == IDOK) {
  573.                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
  574.                 return (TRUE);
  575.             }
  576.             break;
  577.     }
  578.     return (FALSE);                           /* Didn't process a message    */
  579. }
  580.  
  581. /***********************************************************************
  582.  
  583.   FUNCTION   : ClpHeaderDlgProc
  584.  
  585.   PARAMETERS : HWND hDlg
  586.                unsigned message
  587.                WORD wParam
  588.                LONG lParam
  589.  
  590.   PURPOSE    : show the METAFILEPICT associated with the clipboard
  591.                metafile.  This format is described on page 7-52 of
  592.                the Windows SDK Reference Volume 2.
  593.  
  594.   CALLS      : WINDOWS
  595.                  lstrcpy
  596.                  wsprintf
  597.                  SetDlgItemText
  598.                  EndDialog
  599.  
  600.   MESSAGES   : WM_INITDIALOG
  601.                WM_COMMAND
  602.  
  603.   RETURNS    : BOOL
  604.  
  605.   COMMENTS   : METAFILEPICT format
  606.  
  607.                int    mm;
  608.                int    xExt;
  609.                int    yExt;
  610.                HANDLE hMF;
  611.  
  612.                These fields have the following  meanings:
  613.  
  614.                Field         Definition
  615.  
  616.                mm            specifies the mapping mode in which the picture
  617.                              is drawn.
  618.  
  619.                xExt          specifies the size of the metafile picture for
  620.                              all modes except MM_ISOTROPIC and ANISOTROPIC
  621.                              modes. See SDK reference for more info.
  622.  
  623.                yExt          as above...
  624.  
  625.                hMF           Identifies a memory metafile.
  626.  
  627.   HISTORY    : 1/16/91 - created - Dennis Crain
  628.  
  629. ************************************************************************/
  630.  
  631. BOOL FAR PASCAL __export ClpHeaderDlgProc(hDlg, message, wParam, lParam)
  632. HWND hDlg;
  633. unsigned message;
  634. WORD wParam;
  635. LONG lParam;
  636. {
  637.     char szBuf[30];
  638.  
  639.     switch (message) {
  640.         case WM_INITDIALOG:
  641.             /*format the mapping mode */
  642.             lstrcpy((LPSTR)szBuf, (MFP.mm == MM_TEXT)        ? (LPSTR)"MM_TEXT"     :
  643.                                   (MFP.mm == MM_LOMETRIC)    ? (LPSTR)"MM_LOMETRIC" :
  644.                                   (MFP.mm == MM_HIMETRIC)    ? (LPSTR)"MM_HIMETRIC" :
  645.                                   (MFP.mm == MM_LOENGLISH)   ? (LPSTR)"MM_LOENGLISH":
  646.                                   (MFP.mm == MM_HIENGLISH)   ? (LPSTR)"MM_HIENGLISH":
  647.                                   (MFP.mm == MM_TWIPS)       ? (LPSTR)"MM_TWIPS"    :
  648.                                   (MFP.mm == MM_ISOTROPIC)   ? (LPSTR)"MM_ISOTROPIC":
  649.                                   (MFP.mm == MM_ANISOTROPIC) ? (LPSTR)"MM_ANISOTROPIC":
  650.                                   (LPSTR)"UNKOWN");
  651.             SetDlgItemText(hDlg, IDE_MM, (LPSTR)szBuf);
  652.  
  653.             /* format the xExt */
  654.             wsprintf((LPSTR)szBuf, "%d", MFP.xExt);
  655.             SetDlgItemText(hDlg, IDE_XEXT, (LPSTR)szBuf);
  656.  
  657.             /* format the yExt */
  658.             wsprintf((LPSTR)szBuf, "%d", MFP.yExt);
  659.             SetDlgItemText(hDlg, IDE_YEXT, (LPSTR)szBuf);
  660.  
  661.             return (TRUE);
  662.  
  663.         case WM_COMMAND:
  664.             if (wParam == IDOK) {
  665.                 EndDialog(hDlg, TRUE);
  666.                 return (TRUE);
  667.             }
  668.             break;
  669.     }
  670.     return (FALSE);
  671. }
  672.  
  673. /***********************************************************************
  674.  
  675.   FUNCTION   : ListDlgProc
  676.  
  677.   PARAMETERS : HWND hDlg
  678.                unsigned message
  679.                WORD wParam
  680.                LONG lParam
  681.  
  682.   PURPOSE    :
  683.  
  684.   CALLS      : WINDOWS
  685.                  GetMetaFile
  686.                  GetDC
  687.                  EnumMetaFile
  688.                  MakeProcInstance
  689.                  FreeProcInstance
  690.                  ReleaseDC
  691.                  EndDialog
  692.                  DeleteMetaFile
  693.                  MessageBox
  694.                  SendDlgItemMessage
  695.                  GlobalAlloc
  696.                  GlobalLock
  697.                  DialogBox
  698.                APP
  699.                  PlayIt
  700.  
  701.   MESSAGES   : WM_INITDIALOG
  702.                WM_COMMAND
  703.  
  704.   RETURNS    : BOOL
  705.  
  706.   COMMENTS   :
  707.  
  708.   HISTORY    :
  709.  
  710. ************************************************************************/
  711.  
  712. BOOL FAR PASCAL __export ListDlgProc(hDlg, message, wParam, lParam)
  713. HWND hDlg;
  714. unsigned message;
  715. WORD wParam;
  716. LONG lParam;
  717. {
  718.     HDC hDC;
  719.  
  720.     CurrenthDlg = hDlg;
  721.     switch (message) {
  722.         case WM_INITDIALOG:
  723.             /* initalize the current record number */
  724.             iRecNum = 0;
  725.  
  726.             /* if this metafile is not already in memory then get it*/
  727.             if (!bMetaInRam)
  728.               hMF = GetMetaFile( (LPSTR)OpenName);
  729.  
  730.             /* if hMF is a valid handle */
  731.             if (hMF) {
  732.                 hDC = GetDC(hWndMain);
  733.  
  734.                 /* let the enumeration callback function know that we are
  735.                    enumerating the records to a list */
  736.                 iEnumAction = ENUMMFLIST;
  737.  
  738.                 lpprocEnumMF = MakeProcInstance ((FARPROC) MetaEnumProc, hInst);
  739.                 EnumMetaFile(hDC, hMF, lpprocEnumMF, (LONG) NULL);
  740.                 FreeProcInstance ((FARPROC) lpprocEnumMF);
  741.                 if (!bMetaInRam)
  742.                   hMF = DeleteMetaFile (hMF);
  743.                 ReleaseDC(hWndMain, hDC);
  744.             }
  745.             else
  746.               MessageBox(hWndMain, "GetMetaFile failed",
  747.                         NULL, MB_OK | MB_ICONHAND);
  748.             return (TRUE);
  749.  
  750.         case WM_COMMAND:
  751.             switch(wParam)
  752.             {
  753.               case IDOK:
  754.  
  755.               case IDCANCEL:
  756.                  EndDialog(hDlg, TRUE);
  757.                  return(TRUE);
  758.                  break;
  759.  
  760.               case IDL_PLAY:
  761.  
  762.                  //get the number of selected items
  763.  
  764.                  iNumSel = SendDlgItemMessage(hDlg,
  765.                                               IDL_LBREC,
  766.                                               LB_GETSELCOUNT,
  767.                                               0,
  768.                                               0L);
  769.  
  770.                  //allocate a buffer large enough to save the indexes
  771.  
  772.                  hSelMem = GlobalAlloc(GHND, iNumSel * sizeof(int));
  773.  
  774.                  //lock it down and assign a long ptr to it
  775.  
  776.                  if (hSelMem) {
  777.                     lpSelMem = (int FAR *)GlobalLock(hSelMem);
  778.                     if (!lpSelMem)
  779.                         return(FALSE);
  780.                  }
  781.                  else
  782.                     return(FALSE);
  783.  
  784.                  //get the actual indexes and put in buffer
  785.  
  786.                  iLBItemsInBuf = SendDlgItemMessage(hDlg,
  787.                                                   IDL_LBREC,
  788.                                                   LB_GETSELITEMS,
  789.                                                   (WORD)iNumSel,
  790.                                                   (DWORD)lpSelMem);
  791.  
  792.                  bEnumRange = FALSE;
  793.                  bPlayItAll = FALSE;
  794.                  bPlayList  = TRUE;
  795.                  iCount = 0; //reset index into lpSelMem
  796.  
  797.                  /*dialog to play selected or unselected records*/
  798.  
  799.                  lpPlayFromListDlgProc = MakeProcInstance(PlayFromListDlgProc, hInst);
  800.                  DialogBox(hInst,
  801.                            "PLAYWHAT",
  802.                            hDlg,
  803.                            lpPlayFromListDlgProc);
  804.  
  805.                  FreeProcInstance(lpPlayFromListDlgProc);
  806.  
  807.                  /* end this dialog prematurely to get on with playing of recs */
  808.                  EndDialog(hDlg, TRUE);
  809.  
  810.                  /* play the metafile to the appropriate destination */
  811.                  PlayMetaFileToDest(hWndMain, iDestDC);
  812.  
  813.                  break;
  814.  
  815.               default:
  816.                  return (FALSE);
  817.             }
  818.             break;
  819.  
  820.     }
  821.     return (FALSE);
  822. }
  823.  
  824. /****************************************************************************
  825.  
  826.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  827.  
  828.     PURPOSE:  Processes messages for "About" dialog box
  829.  
  830.     MESSAGES:
  831.  
  832.         WM_INITDIALOG - initialize dialog box
  833.         WM_COMMAND    - Input received
  834.  
  835.     COMMENTS:
  836.  
  837.         No initialization is needed for this particular dialog box, but TRUE
  838.         must be returned to Windows.
  839.  
  840.         Wait for user to click on "Ok" button, then close the dialog box.
  841.  
  842. ****************************************************************************/
  843.  
  844. BOOL FAR PASCAL __export About(hDlg, message, wParam, lParam)
  845. HWND hDlg;                                /* window handle of the dialog box */
  846. unsigned message;                         /* type of message                 */
  847. WORD wParam;                              /* message-specific information    */
  848. LONG lParam;
  849. {
  850.     switch (message) {
  851.         case WM_INITDIALOG:                /* message: initialize dialog box */
  852.             return (TRUE);
  853.  
  854.         case WM_COMMAND:                      /* message: received a command */
  855.             if (wParam == IDOK                /* "OK" box selected?          */
  856.                 || wParam == IDCANCEL) {      /* System menu close command? */
  857.                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
  858.                 return (TRUE);
  859.             }
  860.             break;
  861.     }
  862.     return (FALSE);                           /* Didn't process a message    */
  863. }
  864.