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