home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / prtsampl.zip / PRTMENU.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  27KB  |  809 lines

  1. /************************************************************************
  2.  * OS/2 Sample Print Application PRTSAMP
  3.  *
  4.  *  File name  :  prtmenu.c
  5.  *
  6.  *  Description:  This file contains functions which respond to selections
  7.  *                the user makes at the menu bar or the pulldown menus on it.
  8.  *
  9.  *                This source file contains the following functions:
  10.  *
  11.  *                Menu(hwnd, msg, mp1, mp2)
  12.  *                GetEAFileType(hfile, hab)
  13.  *                FileTypeDlgProc(hwnd, msg, mp1, mp2)
  14.  *                MyFileDlgProc(hwnd, msg, mp1, mp2)
  15.  *                MyFontDlgProc(hwnd, msg, mp1, mp2)
  16.  *                ProdInfoDlgProc(hwnd, msg, mp1, mp2)
  17.  *                SetSysMenu(hdlg)
  18.  *                ValidateFilename(pmp, pszFilename, hwndOwner)
  19.  *
  20.  *  Concepts   :  standard dialogs
  21.  *
  22.  *  API's      :  WinQueryWindowULong
  23.  *                WinFileDlg
  24.  *                WinFontDlg
  25.  *                WinDlgBox
  26.  *                WinSendMsg
  27.  *                WinPostMsg
  28.  *                WinCheckMenuItem
  29.  *                GpiSetDefaultViewMatrix
  30.  *                WinAlarm
  31.  *                DosQueryFileInfo
  32.  *                WinCheckButton
  33.  *                WinSetFocus
  34.  *                WinQueryButtonCheckstate
  35.  *                WinDismissDlg
  36.  *                DosOpen
  37.  *                DosRead
  38.  *                DosClose
  39.  *                WinLoadString
  40.  *                WinMessageBox
  41.  *                WinDefFileDlgProc
  42.  *                WinDefFontDlgProc
  43.  *                WinDefDlgProc
  44.  *                WinEnableMenuItem
  45.  *                WinWindowFromID
  46.  *
  47.  *    Files    :  OS2.H, PRTSAMP.H, PRTSDLG.H, PRTSHLP.H, PMASSERT.H
  48.  *
  49.  *  Copyright (C) 1991-1993 IBM Corporation
  50.  *
  51.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  52.  *      sample code created by IBM Corporation. This sample code is not
  53.  *      part of any standard or IBM product and is provided to you solely
  54.  *      for  the purpose of assisting you in the development of your
  55.  *      applications.  The code is provided "AS IS", without
  56.  *      warranty of any kind.  IBM shall not be liable for any damages
  57.  *      arising out of your use of the sample code, even if they have been
  58.  *      advised of the possibility of such damages.
  59.  *************************************************************************/
  60.  
  61. /* os2 includes */
  62. #define INCL_DEV
  63. #define INCL_DOSFILEMGR
  64. #define INCL_GPITRANSFORMS
  65. #define INCL_SPL
  66. #define INCL_SPLDOSPRINT
  67. #define INCL_WINBUTTONS
  68. #define INCL_WINDIALOGS
  69. #define INCL_WINERRORS
  70. #define INCL_WINFRAMEMGR
  71. #define INCL_WINHELP
  72. #define INCL_WININPUT
  73. #define INCL_WINMENUS
  74. #define INCL_WINSTDFILE
  75. #define INCL_WINSTDFONT
  76. #define INCL_WINWINDOWMGR
  77. #include <os2.h>
  78.  
  79. /* c language includes */
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include <string.h>
  83. #include <ctype.h>
  84. #include <stddef.h>
  85. #include <process.h>
  86. #include <memory.h>
  87. #include <sys\types.h>
  88. #include <sys\stat.h>
  89.  
  90. /* application includes */
  91. #include "prtsamp.h"
  92. #include "prtsdlg.h"
  93. #include "prtshlp.h"
  94. #include "pmassert.h"
  95.  
  96. /**************************************************************************
  97.  *
  98.  *  Name       : Menu()
  99.  *
  100.  *  Description: Processes commands initiated from the menu bar.
  101.  *
  102.  *  Concepts:    pull-down menus
  103.  *
  104.  *  API's      :  WinQueryWindowULong
  105.  *                WinFileDlg
  106.  *                WinFontDlg
  107.  *                WinDlgBox
  108.  *                WinSendMsg
  109.  *                WinPostMsg
  110.  *                WinCheckMenuItem
  111.  *                GpiSetDefaultViewMatrix
  112.  *                WinAlarm
  113.  *
  114.  *  Parameters :  hwnd = window handle
  115.  *                msg  = message code
  116.  *                mp1  = first message parameter
  117.  *                mp2  = second message parameter
  118.  *
  119.  *  Return     :  depends on message sent
  120.  *************************************************************************/
  121. MRESULT Menu( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  122. {
  123.    PMAIN_PARM pmp;
  124.    ULONG      rc;
  125.    BOOL       bOK;
  126.    FIXED      fxWork;
  127.    CHAR       szWork[ LEN_WORKSTRING ];
  128.  
  129.    /* obtain the main parameter pointer from window words */
  130.    pmp = (PMAIN_PARM)WinQueryWindowULong( hwnd, QWL_USER );
  131.  
  132.    switch( msg )
  133.    {
  134.    case WM_COMMAND:
  135.       switch(SHORT1FROMMP(mp1))
  136.       {
  137.       case IDM_OPEN:
  138.         /* filedlg structure initialized in create.c.
  139.          * See function MyFileDlgProc() which operates while file dialog is up.
  140.          */
  141.          WinFileDlg( HWND_DESKTOP, hwnd, &pmp->filedlg );
  142.          return (MRESULT)NULL;
  143.  
  144.       case IDM_PAGESETUP:
  145.          /*
  146.           * Check if any printer details changed since the last time the
  147.           * page setup dialog was displayed and then display the dialog.
  148.           */
  149.          QueryPrintQueue( pmp, FALSE );
  150.          QueryForm( pmp, TRUE );
  151.          return (MRESULT)NULL;
  152.  
  153.       case IDM_PAGEDOWN:
  154.          /* preview the next page of text */
  155.          WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, (MPARAM)0L, (MPARAM)0L );
  156.          WinPostMsg( pmp->hwndObject, WM_USER_PAGINATE, (MPARAM)hwnd,
  157.                      (MPARAM)FLAGS_SCREEN );
  158.          return (MRESULT)NULL;
  159.  
  160.       case IDM_PRINT:
  161.          Print(hwnd, pmp);
  162.          return (MRESULT)NULL;
  163.  
  164.       case IDM_HELPINDEX:
  165.          rc = (ULONG)WinSendMsg(pmp->hwndHelp, HM_HELP_INDEX, MPVOID, MPVOID);
  166.          pmassert( pmp->hab, rc == 0L );
  167.          break;
  168.  
  169.       case IDM_HELPEXTENDED:
  170.          rc = (ULONG)WinSendMsg(pmp->hwndHelp, HM_EXT_HELP, MPVOID, MPVOID);
  171.          pmassert( pmp->hab, rc == 0L );
  172.          break;
  173.  
  174.       case IDM_USINGHELP:
  175.          rc = (ULONG)WinSendMsg(pmp->hwndHelp, HM_DISPLAY_HELP, MPVOID, MPVOID);
  176.          pmassert( pmp->hab, rc == 0L );
  177.          break;
  178.  
  179.       case IDM_PRODINFO:
  180.          rc = WinDlgBox( HWND_DESKTOP,
  181.                         hwnd,
  182.                         (PFNWP)ProdInfoDlgProc,
  183.                         (HMODULE)NULLHANDLE,
  184.                         IDD_PRODINFO,
  185.                         (PVOID)pmp );
  186.          pmassert( pmp->hab, rc != DID_ERROR );
  187.          return (MRESULT)NULL;
  188.  
  189.       case IDM_SETFONT:
  190.         /* let user pick a font */
  191.         pmassert( pmp->hab, pmp->ulMode == MODE_TEXT );
  192.  
  193.         /* reassign hpsPrinter because it could have changed */
  194.         pmp->fontdlg.hpsPrinter   = pmp->hpsPrinterInfo;
  195.  
  196.  
  197.         WinFontDlg( HWND_DESKTOP, hwnd, &pmp->fontdlg );
  198.         if( pmp->fontdlg.lReturn == DID_OK )
  199.         {
  200.            /*
  201.             * Store an indicator that the font dialog was recently visited.
  202.             * This indicator is referenced in PRTSAMP.C under the
  203.             * WM_NACK_DEFAULT_FONT case where the user is warned that
  204.             * the pagination routine is using a default font.
  205.             */
  206.            pmp->fVisitedFontDialog = TRUE;
  207.  
  208.            /* requested vector (outline) fonts only */
  209.            pmassert( pmp->hab,
  210.                      pmp->fontdlg.fAttrs.fsFontUse & FATTR_FONTUSE_OUTLINE )
  211.  
  212.            if( pmp->f )
  213.            {
  214.               /* seek top of file to display document in new font */
  215.               fseek( pmp->f, 0, SEEK_SET );
  216.               /* re-paginate for the screen */
  217.               WinSendMsg( hwnd, WM_USER_DISABLE_CLIENT, 0, 0 );
  218.               WinPostMsg( pmp->hwndObject, WM_USER_PAGINATE, (MPARAM)hwnd,
  219.                           (MPARAM)FLAGS_SCREEN );
  220.            }
  221.         }
  222.  
  223.          return (MRESULT)NULL;
  224.  
  225.  
  226.       case IDM_SETUP:
  227.         /*
  228.          * Present queue selection dialog to user (parm 2 == TRUE);
  229.          * Returns TRUE if queue/printer options changed.
  230.          * If changed, then check the form and reset the program with the
  231.          * NEW_MODE processing. See * prtsamp.c for the WM_USER_NEW_MODE case.
  232.          */
  233.         if( QueryPrintQueue( pmp, TRUE ))
  234.         {
  235.             QueryForm( pmp, FALSE );
  236.         }
  237.         return (MRESULT)NULL;
  238.  
  239.  
  240.       case IDM_VIEWHALF:
  241.       case IDM_VIEWFULL:
  242.          switch ( SHORT1FROMMP (mp1) )
  243.          {
  244.          case IDM_VIEWHALF:
  245.             WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, FALSE );
  246.             WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, TRUE  );
  247.             fxWork = MAKEFIXED( 0, 32768 );
  248.             pmp->floatScale = 0.50;
  249.             break;
  250.  
  251.         case IDM_VIEWFULL:
  252.             WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWFULL, TRUE  );
  253.             WinCheckMenuItem( pmp->hwndMenubar, IDM_VIEWHALF, FALSE );
  254.             fxWork = MAKEFIXED( 1, 0 );
  255.             pmp->floatScale = 1.00;
  256.             break;
  257.         }
  258.  
  259.         if( pmp->matlfDefView.fxM11 != fxWork )
  260.         {
  261.           /* apply the new scaling with no Y translation for now */
  262.           pmp->matlfDefView.fxM11 = fxWork;
  263.           pmp->matlfDefView.fxM22 = fxWork;
  264.           pmp->matlfDefView.lM31 = 0;
  265.           pmp->matlfDefView.lM32 = 0;
  266.           bOK = GpiSetDefaultViewMatrix( pmp->hpsClient, 9,
  267.                                  &pmp->matlfDefView, TRANSFORM_REPLACE );
  268.           pmassert( pmp->hab, bOK );
  269.  
  270.           /*
  271.            * Still need x and Y translation to "home" the document in the
  272.            * client window. "Home" means to position the document such that
  273.            * the top-left corner of the document appears in the top-left
  274.            * corner of the client window.
  275.            *
  276.            * The WM_SIZE case in prtsamp.c sets a proper Y translation so it
  277.            * homes the document
  278.            *
  279.           */
  280.           WinSendMsg( hwnd, WM_SIZE, (MPARAM)0L, (MPARAM)0L );
  281.         }
  282.         else
  283.         {
  284.           /* viewmatrix ok already */
  285.           WinAlarm( HWND_DESKTOP, WA_NOTE );
  286.         }
  287.         return (MRESULT)NULL;
  288.  
  289.       case IDM_AUTHORS:
  290.         /* display message box with list of program's authors */
  291.         WinLoadString(pmp->hab, (HMODULE)NULLHANDLE,
  292.                       PROGRAM_AUTHORS, LEN_WORKSTRING, szWork);
  293.         WinMessageBox( HWND_DESKTOP,
  294.                        HWND_DESKTOP,
  295.                        szWork,
  296.                        pmp->pszTitle,
  297.                        (USHORT)0,
  298.                        MB_OK | MB_MOVEABLE | MB_CUANOTIFICATION | MB_APPLMODAL);
  299.         return (MRESULT)NULL;
  300.  
  301.       }
  302.       break;
  303.  
  304.    }
  305.    return (MRESULT)NULL;
  306. }   /*  end of Menu()  */
  307.  
  308.  
  309. /**************************************************************************
  310.  *
  311.  *  Name       : GetEAFileType
  312.  *
  313.  *  Description: Gets the value for the extended attribute called ".TYPE".
  314.  *               For more information, see the EA Sample Program and
  315.  *               BSEDOS.H.
  316.  *
  317.  *  Concepts:    extended attributes
  318.  *
  319.  *  API's      : DosQueryFileInfo
  320.  *
  321.  *  Parameters :  hfile = file handle to query
  322.  *
  323.  *  Return     :  the extended attribute file type MODE_* as a ULONG
  324.  *************************************************************************/
  325. ULONG GetEAFileType( HFILE hfile, HAB hab)
  326. {
  327.    ULONG       ulMode;
  328.    EAOP2       eaop2;
  329.    PGEA2LIST   pgea2list;
  330.    PFEA2LIST   pfea2list;
  331.    PGEA2       pgea2;
  332.    PFEA2       pfea2;
  333.    PBYTE       pEA;
  334.  
  335.    /* default to unknown */
  336.    ulMode = MODE_UNKNOWN;
  337.  
  338.    /* create one list item in GEA list */
  339.    pgea2 = (PGEA2) calloc ( 1, 10 );
  340.    pgea2->oNextEntryOffset = 0;
  341.    pgea2->cbName           = 5;
  342.    memcpy( pgea2->szName, ".TYPE", 5 );
  343.  
  344.    /* create the list with one GEA item */
  345.    pgea2list = (PGEA2LIST) calloc ( 1, 14 );
  346.    pgea2list->cbList = 10;
  347.    memcpy( &pgea2list->list, pgea2, 10 );
  348.  
  349.    /* create the list where DosQueryFileInfo places result */
  350.    pfea2list = (PFEA2LIST) calloc ( 1, 64 );
  351.    pfea2list->cbList = 64;
  352.  
  353.    /* put both lists in a eaop2 structure */
  354.    eaop2.fpGEA2List = pgea2list;
  355.    eaop2.fpFEA2List = pfea2list;
  356.  
  357.    /* get info */
  358.    if( 0 == DosQueryFileInfo( hfile, FIL_QUERYEASFROMLIST, &eaop2, 64 ) )
  359.    {
  360.      /* is there a ".TYPE" EA? */
  361.       pfea2 = pfea2list->list;
  362.       if( pfea2->cbValue > 0 )
  363.       {
  364.          /* check that EA is .TYPE */
  365.          pEA = pfea2->szName;
  366.          pmassert(hab, !strcmp((PSZ)pEA, ".TYPE") );
  367.  
  368.          /* set pointer to EA value - increment over EA name, null and flags */
  369.          pEA = pfea2->szName + pfea2->cbName + 1 + 10;
  370.  
  371.          /* try to set filemode from EA value */
  372.          if (! strcmp( pEA, "Assembler Code" ))     ulMode = MODE_TEXT;
  373.          if (! strcmp( pEA, "BASIC Code" ))         ulMode = MODE_TEXT;
  374.          if (! strcmp( pEA, "Bitmap" ))             ulMode = MODE_BITMAP;
  375.          if (! strcmp( pEA, "C Code" ))             ulMode = MODE_TEXT;
  376.          if (! strcmp( pEA, "COBOL Code" ))         ulMode = MODE_TEXT;
  377.          if (! strcmp( pEA, "DOS Command File" ))   ulMode = MODE_TEXT;
  378.          if (! strcmp( pEA, "FORTRAN Code" ))       ulMode = MODE_TEXT;
  379.          if (! strcmp( pEA, "Icon" ))               ulMode = MODE_BITMAP;
  380.          if (! strcmp( pEA, "OS/2 Command File" ))  ulMode = MODE_TEXT;
  381.          if (! strcmp( pEA, "Pascal Code" ))        ulMode = MODE_TEXT;
  382.          if (! strcmp( pEA, "Pointer" ))            ulMode = MODE_BITMAP;
  383.          if (! strcmp( pEA, "Metafile" ))           ulMode = MODE_METAFILE;
  384.          if (! strcmp( pEA, "Plain Text" ))         ulMode = MODE_TEXT;
  385.       }
  386.    }
  387.    free( pfea2list );
  388.    free( pgea2list );
  389.    free( pgea2 );
  390.    return ulMode;
  391. }     /*  end of GetEAFileType()  */
  392.  
  393.  
  394. /**************************************************************************
  395.  *
  396.  *  Name       : FileTypeDlgProc
  397.  *
  398.  *  Description: Window procedure for the dialog that lets the user
  399.  *               indicate the file type, presented as a child dialog
  400.  *               of the standard file dialog.
  401.  *
  402.  *  Concepts:    window words
  403.  *
  404.  *  API's      : WinSetWindowULong
  405.  *               WinCheckButton
  406.  *               WinSetFocus
  407.  *               WinQueryButtonCheckstate
  408.  *               WinDismissDlg
  409.  *               WinDefDlgProc
  410.  *
  411.  *  Parameters : sets check according to pmp->ulNextMode, defaults to
  412.  *               text type
  413.  *               pmp is passed to this dialog at WM_INITDLG time and stored
  414.  *               in dialog window words.
  415.  *
  416.  *  Return     : sets pmp->ulNextMode according to user's selection
  417.  *************************************************************************/
  418. ULONG APIENTRY FileTypeDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  419. {
  420.    PMAIN_PARM  pmp;
  421.    ULONG       id;
  422.  
  423.    switch( msg )
  424.    {
  425.    case WM_INITDLG:
  426.       pmp = (PMAIN_PARM) mp2;
  427.       WinSetWindowULong( hwnd, QWL_USER, (ULONG)mp2 );
  428.  
  429.     /* set check according to pmp->ulNextMode */
  430.       switch( pmp->ulNextMode )
  431.       {
  432.       case MODE_BITMAP:
  433.          id = IDC_CK_BITMAP;
  434.          break;
  435.       case MODE_METAFILE:
  436.          id = IDC_CK_METAFILE;
  437.          break;
  438.       default:
  439.          id = IDC_CK_TEXT;
  440.          break;
  441.       }
  442.  
  443.       WinCheckButton( hwnd, id, TRUE );
  444.       WinSetFocus( HWND_DESKTOP, hwnd );
  445.       return 1L;
  446.  
  447.    case WM_COMMAND:
  448.       pmp = (PMAIN_PARM) WinQueryWindowULong( hwnd, QWL_USER );
  449.       switch( SHORT1FROMMP( mp1 ))
  450.       {
  451.       case DID_OK:
  452.       /* get checked button */
  453.          if( WinQueryButtonCheckstate( hwnd, IDC_CK_TEXT ))
  454.          {
  455.             pmp->ulNextMode = MODE_TEXT;
  456.          }
  457.          if( WinQueryButtonCheckstate( hwnd, IDC_CK_BITMAP ))
  458.          {
  459.             pmp->ulNextMode = MODE_BITMAP;
  460.          }
  461.          if( WinQueryButtonCheckstate( hwnd, IDC_CK_METAFILE ))
  462.          {
  463.             pmp->ulNextMode = MODE_METAFILE;
  464.          }
  465.          WinDismissDlg( hwnd, DID_OK );
  466.          break;
  467.  
  468.     case DID_CANCEL:
  469.       /* return */
  470.         WinDismissDlg( hwnd, DID_CANCEL );
  471.         break;
  472.       }
  473.       return 0L;
  474.  
  475.    }
  476.    return (ULONG)WinDefDlgProc( hwnd, msg, mp1, mp2 );
  477. }  /*  end of FileTypeDlgProc()  */
  478.  
  479.  
  480. /************************************************************************
  481.  *
  482.  * Name:     MyFileDlgProc
  483.  *
  484.  * Description: Window procedure that subclasses the WinFileDlg window
  485.  *              procedure, processes/validates filenames the user picked
  486.  *              from the WinFileDlg.
  487.  *              The address of this function has been specified in the
  488.  *              pmp->FILEDLG structure before invoking WinFileDlg().
  489.  *              Handle WM_HELP from font dialog.
  490.  *
  491.  *  Concepts:    open/saveas file dialog
  492.  *
  493.  *  API's      : WinQueryWindowULong
  494.  *               WinDlgBox
  495.  *               WinPostMsg
  496.  *               DosOpen
  497.  *               DosRead
  498.  *               DosClose
  499.  *               WinLoadString
  500.  *               WinMessageBox
  501.  *               WinSendMsg
  502.  *               WinDefFileDlgProc
  503.  *
  504.  * Parameters:  Regular window procedure arguments.
  505.  *              Can get pmp from filedlg.ulUser.
  506.  *              Can get to filedlg structure by getting its pointer
  507.  *              from dialog window words.
  508.  *
  509.  * Result:      presents the filetype dialog as a child of the filedlg
  510. **************************************************************************/
  511. MRESULT APIENTRY MyFileDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  512. {
  513.    ULONG       ulPanel;
  514.    PMAIN_PARM  pmp;
  515.    PFILEDLG    pfiledlg;
  516.  
  517.    switch( msg )
  518.    {
  519.    case FDM_VALIDATE:
  520.       /* get pointer to fontdlg structure from window words of this dialog */
  521.       pfiledlg = (PFILEDLG)WinQueryWindowULong( hwnd, QWL_USER );
  522.       /* filedlg structure has a pmp pointer stored in the user dword */
  523.       pmp = (PMAIN_PARM)pfiledlg->ulUser;
  524.       /* validate filename and use if ok */
  525.       return ( (MRESULT)ValidateFilename( pmp, (PSZ)mp1, hwnd) );
  526.  
  527.  
  528.    case WM_HELP:
  529.      /* get pointer to fontdlg structure from window words of this dialog */
  530.       pfiledlg = (PFILEDLG) WinQueryWindowULong( hwnd, QWL_USER );
  531.      /* filedlg structure has a pmp pointer stored in the user dword */
  532.       pmp = (PMAIN_PARM) pfiledlg->ulUser;
  533.  
  534.       if( pmp->hwndHelp )
  535.       {
  536.          ulPanel = PANEL_FILEDIALOG;
  537.          WinSendMsg( pmp->hwndHelp, HM_DISPLAY_HELP,
  538.                    (MPARAM)&ulPanel, (MPARAM)HM_RESOURCEID );
  539.          return (MRESULT)NULL;
  540.       }
  541.       break;
  542.  
  543.    default:
  544.       break;
  545.    }
  546.    return WinDefFileDlgProc( hwnd, msg, mp1, mp2 );
  547. }   /*  end of MyFileDlgProc()  */
  548.  
  549.  
  550.  
  551. /************************************************************************
  552. *
  553. * Name: MyFontDlgProc
  554. *
  555. * Description:  Window procedure that subclasses the WinFontDlg window
  556. *               procedure.  Exists to handle WM_HELP message from the
  557. *               standard font dialog.
  558. *
  559. * Parameters:   Regular window procedure arguments.
  560. *               Can get pmp from fontdlg.ulUser.  Can get to fontdlg
  561. *               structure by getting its pointer from dialog window words.
  562. *
  563. * returns: depends on message sent
  564. *
  565. **************************************************************************/
  566. MRESULT APIENTRY MyFontDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  567. {
  568.    PMAIN_PARM  pmp;
  569.    PFONTDLG    pfontdlg;
  570.    ULONG       ulPanel;
  571.  
  572.    switch( msg )
  573.    {
  574.    case WM_HELP:
  575.      /* get pointer to filedlg structure from window words of this dialog */
  576.       pfontdlg = (PFONTDLG) WinQueryWindowULong( hwnd, QWL_USER );
  577.      /* fontdlg structure has a pmp pointer stored in the user dword */
  578.       pmp = (PMAIN_PARM) pfontdlg->ulUser;
  579.  
  580.       if( pmp->hwndHelp )
  581.       {
  582.          ulPanel = PANEL_FONTDIALOG;
  583.          WinSendMsg( pmp->hwndHelp, HM_DISPLAY_HELP,
  584.                    (MPARAM)&ulPanel, (MPARAM)HM_RESOURCEID );
  585.          return (MRESULT)NULL;
  586.       }
  587.       break;
  588.    }
  589.    return WinDefFontDlgProc( hwnd, msg, mp1, mp2 );
  590. }   /*  end of MyFontDlgProc()  */
  591.  
  592.  
  593. /*********************************************************************
  594. *  Name : ProdInfoDlgProc
  595. *
  596. *  Description : Processes all messages sent to the Product
  597. *                Information dialog box.
  598. *
  599. *  Concepts : Called for each message sent to the Product
  600. *             Information dialog box.  The Product
  601. *             Information box only has a button control so
  602. *             this routine only processes WM_COMMAND
  603. *             messages.  Any WM_COMMAND posted must have come
  604. *             from the Ok button so we dismiss the dialog
  605. *             upon receiving it.
  606. *
  607. *  API's : WinDismissDlg
  608. *          WinDefDlgProc
  609. *
  610. * Parameters   : hwnd - Window handle to which message is addressed
  611. *                msg - Message type
  612. *                mp1 - First message parameter
  613. *                mp2 - Second message parameter
  614. *
  615. *  Returns : Dependent upon message sent
  616. ****************************************************************/
  617. MRESULT EXPENTRY ProdInfoDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  618. {
  619.    switch(msg)
  620.    {
  621.       case WM_INITDLG:
  622.          SetSysMenu(hwnd);       /* system menu for this dialog  */
  623.          return MRFROMSHORT(FALSE);
  624.  
  625.       case WM_COMMAND:
  626.          /*
  627.           * No matter what the command, close the dialog
  628.           */
  629.          WinDismissDlg(hwnd, TRUE);
  630.          break;
  631.  
  632.       default:
  633.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  634.    }
  635.    return (MRESULT)NULL;
  636. }   /*  end of ProdInfoDlgProc()  */
  637.  
  638.  
  639. /**************************************************************************
  640.  *
  641.  *  Name       : SetSysMenu(hDlg)
  642.  *
  643.  *  Description: Sets only the Move and Close items of the system menu
  644.  *
  645.  *  Concepts:  Any dialog box is free to call this routine, to edit
  646.  *             which menu items will appear on its System Menu pulldown.
  647.  *
  648.  *  API's      :  WinWindowFromID
  649.  *                WinSendMsg
  650.  *
  651.  *  Parameters :  hDlg     = window handle of the dialog
  652.  *
  653.  *  Return     :  [none]
  654.  *
  655.  *************************************************************************/
  656. VOID SetSysMenu(HWND hDlg)
  657. {
  658.     HWND     hSysMenu;
  659.     MENUITEM Mi;
  660.     ULONG    Pos;
  661.     MRESULT  Id;
  662.     SHORT    cItems;
  663.  
  664.     /******************************************************************/
  665.     /*  We only want Move and Close in the system menu.               */
  666.     /******************************************************************/
  667.  
  668.     hSysMenu = WinWindowFromID(hDlg, FID_SYSMENU);
  669.     WinSendMsg( hSysMenu, MM_QUERYITEM
  670.               , MPFROM2SHORT(SC_SYSMENU, FALSE), MPFROMP((PCH) & Mi));
  671.     Pos = 0L;
  672.     cItems=(SHORT)WinSendMsg(Mi.hwndSubMenu, MM_QUERYITEMCOUNT, MPVOID, MPVOID);
  673.     while (cItems--)
  674.     {
  675.         Id = WinSendMsg( Mi.hwndSubMenu, MM_ITEMIDFROMPOSITION
  676.                           , MPFROMLONG(Pos), MPVOID);
  677.         switch (SHORT1FROMMR(Id))
  678.         {
  679.         case SC_MOVE:
  680.         case SC_CLOSE:
  681.             Pos++;  /* Don't delete that one. */
  682.             break;
  683.         default:
  684.             WinSendMsg( Mi.hwndSubMenu, MM_DELETEITEM
  685.                       , MPFROM2SHORT((USHORT)Id, TRUE), MPVOID);
  686.         }
  687.     }
  688. }   /*  End of SetSysMenu  */
  689.  
  690.  
  691. /************************************************************************
  692.  *
  693.  * Name:     ValidateFilename
  694.  *
  695.  * Description: Validates a filename, gets the type and uses it
  696.  *
  697.  *  API's      : DosOpen
  698.  *               DosRead
  699.  *               DosClose
  700.  *               WinLoadString
  701.  *               WinMessageBox
  702.  *               WinSendMsg
  703.  *
  704.  * Parameters:  PMAIN_PARM       pointer to global data structure
  705.  *              PSZ              file name to validate
  706.  *              HWND             owner window, if NULL do not show type dialog
  707.  *
  708.  * Result:      TRUE if file is ok and used, otherwise FALSE
  709. **************************************************************************/
  710. BOOL ValidateFilename( PMAIN_PARM pmp, PSZ pszFilename, HWND hwndOwner)
  711. {
  712.    BOOL        bOK, bResult;
  713.    HFILE       hfile;
  714.    ULONG       ulAction, rc, ulMode, ulBytes;
  715.    PCHAR       pch;
  716.    char        szWork[ LEN_WORKSTRING ];
  717.  
  718.    /* check file exists */
  719.    rc = DosOpen(  pszFilename,
  720.                   &hfile,
  721.                   &ulAction,
  722.                   0,
  723.                   FILE_NORMAL,
  724.                   FILE_OPEN,
  725.                   OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  726.                   NULL );
  727.    if( rc == 0 )
  728.    {
  729.      /* file exists; what kind of file is this according to the EAs? */
  730.      ulMode = GetEAFileType( hfile, pmp->hab );
  731.  
  732.      if( ulMode == MODE_UNKNOWN )
  733.      {
  734.        /* not sure. Look at file extension to determine file type. */
  735.        pch = pszFilename + strlen( pszFilename );
  736.        pch = max( pszFilename, pch-4 );
  737.        if( 0 == stricmp( pch, ".BMP" )) ulMode = MODE_BITMAP;
  738.        if( 0 == stricmp( pch, ".TXT" )) ulMode = MODE_TEXT;
  739.        if( 0 == stricmp( pch, ".MET" )) ulMode = MODE_METAFILE;
  740.        if( 0 == stricmp( pch, ".SPL" )) ulMode = MODE_METAFILE;
  741.      }
  742.  
  743.      if( ulMode == MODE_UNKNOWN )
  744.      {
  745.        /* still not sure; peek at data in the file */
  746.        if( 0 == DosRead( hfile, szWork, 16, &ulBytes ))
  747.        {
  748.          if( 0==strncmp(szWork,"BM",2 ) || 0==strncmp(szWork,"BA", 2 ))
  749.          {
  750.             ulMode = MODE_BITMAP;
  751.          }
  752.          else if( szWork[3] == 0xA8  &&  szWork[4] == 0xA8  )
  753.          {
  754.             ulMode = MODE_METAFILE;
  755.          }
  756.        }
  757.      }
  758.  
  759.      /* set "best-guess" mode into main params for FileTypeDlgProc() */
  760.      pmp->ulNextMode = ulMode;
  761.  
  762.      /* show dialog only if a owner window handle is given */
  763.      rc = DID_OK;
  764.      if (hwndOwner)
  765.      {
  766.         /* confirm file type with user via the file type dialog */
  767.         rc = WinDlgBox( HWND_DESKTOP,
  768.                         hwndOwner,
  769.                         (PFNWP)FileTypeDlgProc,
  770.                         (HMODULE)NULLHANDLE,
  771.                         IDD_FILETYPE,
  772.                         (PVOID)pmp );
  773.         pmassert( pmp->hab, rc != DID_ERROR );
  774.      }
  775.  
  776.      if( rc == DID_OK )
  777.      {
  778.         /* set up for new operating mode on new file */
  779.         strcpy( pmp->szNextFilename, pszFilename );
  780.         WinPostMsg( pmp->hwndClient, WM_USER_NEW_MODE, MPVOID, MPVOID);
  781.         bResult = TRUE;
  782.      }
  783.      else
  784.      {
  785.         bResult = FALSE;
  786.      }
  787.      DosClose( hfile );
  788.    }
  789.    else
  790.    {
  791.      /* file not found */
  792.      bOK = WinLoadString( pmp->hab, (HMODULE)NULLHANDLE,
  793.                           ERRMSG_FILE_NOT_FOUND, LEN_WORKSTRING, szWork );
  794.      pmassert( pmp->hab, bOK );
  795.  
  796.      WinMessageBox( HWND_DESKTOP,
  797.                     pmp->hwndFrame,
  798.                     szWork,
  799.                     pmp->pszTitle,
  800.                     (USHORT)0,
  801.                     MB_OK | MB_MOVEABLE | MB_CUACRITICAL | MB_APPLMODAL);
  802.  
  803.      bResult = FALSE;
  804.    }
  805.    return bResult;
  806. } /* end of ValidateFilename */
  807.  
  808. /***************************  End of prtmenu.c  ****************************/
  809.