home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv7.zip / VACPP / IBMCPP / smarts / PM / PMBASIC.C next >
Text File  |  1995-06-02  |  51KB  |  1,153 lines

  1.  
  2. %PROLOG%
  3.  
  4. /***************************************************************************/
  5. /*                                                                         */
  6. /* %FILE_NAME% - Skeleton of a basic PM application.  It can serve as a        */
  7. /*           starting point for a program that uses Presentation Manager   */
  8. /*           services.                                                     */
  9. /*                                                                         */
  10. /***************************************************************************/
  11.  
  12.  
  13. /*---------------*/
  14. /* Include files */
  15. /*---------------*/
  16. #define INCL_WIN
  17. #define INCL_DOS
  18. #define INCL_DOSFILEMGR
  19. #define INCL_DOSMEMMGR
  20. #define INCL_DOSPROCESS
  21. #define INCL_DOSSESMGR
  22. #define INCL_WINSTDFILE
  23. #define INCL_WINACCELERATORS
  24. #include <os2.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <stdarg.h>
  28. #include <stdio.h>
  29. #include "%FILE_NAME%.h"
  30.  
  31.  
  32. /***************************************************************************/
  33. /* Main - sets up Presentation Manager services; handles command-line      */
  34. /* arguments.                                                              */
  35. /***************************************************************************/
  36. int main(int argc, char * argv[])
  37.  
  38. {
  39.  HAB       hab;                                  /* Anchor block handle */
  40.  HMQ       hmq;                                  /* Message queue handle */
  41.  ULONG     flCreateFlags = FCF_TITLEBAR      |   /* Window creation flags  */
  42.                            FCF_SYSMENU       |
  43.                            FCF_SIZEBORDER    |
  44.                            FCF_MINMAX        |
  45.                            FCF_SHELLPOSITION |
  46.                            FCF_TASKLIST      |
  47.                            FCF_MENU          |
  48.                            FCF_ICON          |
  49.                            FCF_ACCELTABLE;           
  50.  
  51.  QMSG      qmsg;                                 /* Message data structure */
  52.  HWND      hwndClient, hwndFrame;                /* Frame and client window handles */
  53.  TID       tidOpen;                              /* Thread ID of thread to handle file open */
  54.  char      szWinTitle[BUFFERSIZE];               /* String to hold window title */
  55.  PWINDOWINFO pWindowInfo;                        /* Window words */
  56.  
  57.  
  58. /*------------------------------------------------------------------*/
  59. /* Standard PM window creation, message loop, and termination.      */
  60. /*------------------------------------------------------------------*/
  61.  hab = WinInitialize (0);
  62.  
  63.  hmq = WinCreateMsgQueue (hab, 0);
  64.  
  65.  if (!WinRegisterClass (hab, 
  66.                         WIN_CLASS_NAME,        /* Window class name */
  67.                         fnClientWndProc, 
  68.                         CS_SIZEREDRAW,
  69.                         sizeof (PWINDOWINFO))) /* Window instance data */
  70.       exit(EXIT_FAILURE);
  71.  
  72.  WinLoadString (hab,        /* Use Desktop's hab */
  73.                 NULLHANDLE, /* Use own resources file */
  74.                 IDS_TITLE,
  75.                 BUFFERSIZE,
  76.                 szWinTitle);
  77.  WinSetWindowText (hwndFrame, szWinTitle);
  78.  
  79.  if (!(hwndFrame = WinCreateStdWindow (HWND_DESKTOP, 
  80.                                        WS_VISIBLE,       /* Frame window style */
  81.                                        &flCreateFlags,   /* window style */
  82.                                        WIN_CLASS_NAME,   /* Class name */
  83.                                        szWinTitle,      /* Window title */
  84.                                        0,                /* Default client style */
  85.                                        NULLHANDLE,       /* Resources in EXE file */
  86.                                        IDW_FRAME_WINDOW, /* Resource/Window ID */
  87.                                        &hwndClient)))    /* Window handle returned */
  88.       exit(EXIT_FAILURE);
  89.  
  90.  
  91.  SetupHelp (hwndFrame, hab);      /* Call function to do all help setup */
  92.  
  93.  if (argc == 2)       /* If user entered the filename on the command line */
  94.     {
  95.      pWindowInfo = (PWINDOWINFO) malloc (sizeof (WINDOWINFO));  /* Allocate window words */
  96.  
  97.      strcpy (pWindowInfo -> szFileName, argv[1]);   /* Store filename in window words */
  98.      pWindowInfo -> hwnd = hwndClient;              /* Store client window handle */
  99.  
  100.      /* Create secondary thread to handle file open operation */  
  101.      tidOpen = _beginthread (fnOpenThread,         /* Thread function */
  102.                              NULL,                 /* Reserved */
  103.                              THREAD_STACK_SIZE,
  104.                              (PVOID) pWindowInfo); /* Thread argument pointer */
  105.  
  106.     }
  107.  
  108.  while (WinGetMsg (hab, &qmsg, 0, 0, 0))        /* Start message loop */
  109.     WinDispatchMsg (hab, &qmsg);
  110.  
  111.  if (WinIsWindow (hab, hwndFrame))
  112.     WinDestroyWindow (hwndFrame);
  113.  
  114.  WinDestroyMsgQueue (hmq);
  115.  
  116.  WinTerminate (hab);
  117.  
  118.  return 0;
  119. }
  120.  
  121.  
  122. /***************************************************************************/
  123. /* Client window procedure - kicks off a thread to load the user-requested */
  124. /* file.  Also records writes any selected commands to the client area.    */
  125. /* Add other processing as necessary.                                      */
  126. /***************************************************************************/
  127. MRESULT EXPENTRY fnClientWndProc (HWND hwnd, ULONG msg, MPARAM   mp1, MPARAM   mp2)
  128. {
  129.  MRESULT     mr = (MRESULT) FALSE;
  130.  PWINDOWINFO pWindowInfo;    
  131.  
  132.  switch (msg)
  133.  {
  134.      case WM_CREATE:
  135.      /*--------------------------------------------------------------------*/
  136.      /* Upon creation of the window, allocate, initialize, and store the   */
  137.      /* instance data in window words.  Every message case that uses the   */
  138.      /* instance data must retrieve the address first.                     */
  139.      /*--------------------------------------------------------------------*/
  140.         {
  141.          char      szString[BUFFERSIZE];
  142.  
  143.          pWindowInfo = (PWINDOWINFO) malloc (sizeof (WINDOWINFO));
  144.  
  145.          pWindowInfo->hwnd = hwnd;
  146.          strcpy (pWindowInfo->szFileName,"*.*");  /* No file opened yet */
  147.  
  148.          /* Load string resource for general description text */
  149.          WinLoadString (pWindowInfo->hab, NULLHANDLE, IDS_GENERAL_DESC, BUFFERSIZE, szString);
  150.          strcpy (pWindowInfo->szText, szString);
  151.  
  152.          WinSetWindowPtr (hwnd, 0, pWindowInfo);
  153.          break;
  154.         }
  155.  
  156.      case WM_PAINT:
  157.      /*--------------------------------------------------------------------*/
  158.      /* Use this message case to update the window when it needs to be     */    
  159.      /* repainted. Always remember to issue a WinBeginPaint and            */
  160.      /* WinEndPaint. Force this message to be issued by issuing a          */
  161.      /* WinInvalidateRect.                                                 */
  162.      /*--------------------------------------------------------------------*/
  163.         {
  164.          HPS hps;
  165.          RECTL rectClientWindow;
  166.  
  167.          /* Retrieve instance data */
  168.          pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  169.  
  170.          hps = WinBeginPaint (hwnd, 
  171.                               NULLHANDLE,          /* Get a cache presentation space */
  172.                               &rectClientWindow);  /* Receive update rectangle */
  173.  
  174.          WinQueryWindowRect (hwnd, &rectClientWindow);  /* Get window rectangle */
  175.  
  176.          /*======================================================*/
  177.          /* Place program-specific window update processing here */
  178.          /*======================================================*/
  179.  
  180.          /* Draw background colour */   
  181.          WinFillRect (hps,              
  182.                       &rectClientWindow, 
  183.                       SYSCLR_WINDOW);     /* System window color */
  184.  
  185.          /* Draw text */
  186.          WinDrawText (hps, 
  187.                       -1,                  /* NULL-terminated string */
  188.                       pWindowInfo->szText,
  189.                       &rectClientWindow,
  190.                       SYSCLR_WINDOWTEXT,   /* System foreground color */
  191.                       SYSCLR_WINDOW,       /* System background color */       
  192.                       DT_CENTER | DT_VCENTER | DT_ERASERECT);        
  193.  
  194.          WinEndPaint (hps);
  195.          break;
  196.         }
  197.  
  198.      case WM_COMMAND:
  199.  
  200.         switch (SHORT1FROMMP(mp1))
  201.         {
  202.             case IDM_FILE_OPEN:
  203.             /*-------------------------------------------------------------*/
  204.             /* When the user selects the File->Open menu item to open a    */
  205.             /* file, display the standard "File open" dialog using         */
  206.             /* WinFileDlg. This accepts a FILEDLG structure, which is      */
  207.             /* initialized to contain the most previous values of the file */
  208.             /* dialog.  This data is kept in the instance data of the      */
  209.             /* window.  Then, a thread is started to open the file and     */
  210.             /* and perform any other program-specific file processing.     */
  211.             /* The name of the file and the client window's handle is      */
  212.             /* passed to the thread to enable communication via messages.  */
  213.             /*-------------------------------------------------------------*/
  214.                {
  215.                 PFILEDLG  pFileDlgInfo;
  216.                 TID       tidOpen;
  217.                 char      szString[BUFFERSIZE];
  218.  
  219.                 /* Retrieve instance data */
  220.                 pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  221.  
  222.                 /* Load string resources */
  223.                 WinLoadString (pWindowInfo->hab, 
  224.                                NULLHANDLE, IDS_FILE_OPEN, BUFFERSIZE,
  225.                                szString);
  226.  
  227.                 /* Allocate and initialize file dialog structure */
  228.                 pFileDlgInfo = (PFILEDLG) malloc (sizeof (FILEDLG));
  229.  
  230.                 pFileDlgInfo->cbSize = sizeof(FILEDLG);  /* Size of structure */
  231.                 pFileDlgInfo->fl = FDS_CENTER |          /* Behavior flags */
  232.                                    FDS_HELPBUTTON | 
  233.                                    FDS_OPEN_DIALOG;
  234.                 pFileDlgInfo->ulUser = 0;                /* No user data */
  235.                 pFileDlgInfo->lReturn = 0;               /* Result code - returned */
  236.                 pFileDlgInfo->lSRC = 0;                  /* System return code */
  237.                 pFileDlgInfo->pszTitle = szString;       /* Dialog title string */
  238.  
  239.                 WinLoadString (pWindowInfo->hab,
  240.                                NULLHANDLE, IDS_OPEN, BUFFERSIZE,
  241.                                szString);
  242.                 pFileDlgInfo->pszOKButton = szString;    /* "Open" is OK pushbutton text */
  243.  
  244.                 pFileDlgInfo->pfnDlgProc = (PFNWP)fnFileOpenDlgProc; /* Name of subclassing dialog procedure */
  245.                 pFileDlgInfo->pszIType = NULL;           /* No extended attribute type filters */
  246.                 pFileDlgInfo->papszITypeList = NULL;
  247.                 pFileDlgInfo->pszIDrive = NULL;          /* Initial drive */
  248.                 pFileDlgInfo->papszIDriveList = NULL;    /* No specified list of drives */
  249.                 pFileDlgInfo->hMod = (HMODULE) NULL;     /* No custom dialog resources */
  250.  
  251.                 /* Specify the initial fully-qualified file name here; */
  252.                 /* selected filename is also returned here  */
  253.                 strcpy (pFileDlgInfo->szFullFile, pWindowInfo->szFileName);
  254.  
  255.                 pFileDlgInfo->papszFQFilename = NULL;    /* No multiple-file selection */
  256.                 pFileDlgInfo->ulFQFCount = 0;            /* Number of files selected */
  257.                 pFileDlgInfo->usDlgId = 0;               /* No custom dialog id */
  258.                 pFileDlgInfo->x = FDS_CENTER;            /* Display in center of parent */
  259.                 pFileDlgInfo->y = FDS_CENTER;
  260.                 pFileDlgInfo->sEAType = 0;               /* Not used in Open dialog */
  261.  
  262.                 WinFileDlg (HWND_DESKTOP, hwnd, pFileDlgInfo);
  263.  
  264.                 if (pFileDlgInfo->lReturn == DID_OK)  /* If user pressed "OK" */
  265.                    {
  266.                     strcpy (pWindowInfo->szFileName,     /* Store selected file in window words */
  267.                             pFileDlgInfo->szFullFile);
  268.  
  269.                     pWindowInfo->hwnd = hwnd;            /* Store hwnd in window words */
  270.  
  271.                     /* Store text */
  272.  
  273.                     WinLoadString (pWindowInfo->hab,
  274.                                    NULLHANDLE, /* Use own resources file */
  275.                                    IDS_OPEN_FILE,
  276.                                    BUFFERSIZE,
  277.                                    szString);
  278.  
  279.                     sprintf (pWindowInfo->szText, szString, pWindowInfo->szFileName);
  280.  
  281.                     WinInvalidateRect (hwnd, NULL, FALSE);  /* Force a repaint */
  282.  
  283.                     WinSetWindowPtr (hwnd, 0, pWindowInfo); /* Set window words */
  284.  
  285.  
  286.                     /* Create secondary thread to handle file open operation */
  287.                     tidOpen = _beginthread (fnOpenThread,        /* Thread function */
  288.                                             NULL,                /* Reserved */
  289.                                             THREAD_STACK_SIZE,
  290.                                             (PVOID) pWindowInfo); /* Thread argument pointer */
  291.                    }
  292.                 free (pFileDlgInfo);
  293.                }
  294.                break;
  295.  
  296.  
  297.             case IDM_FILE_CLOSE:
  298.             /*-------------------------------------------------------------*/
  299.             /* User chooses to exit by selecting the File->Close menu item.*/
  300.             /* Post WM_CLOSE to get the message box for confirmation.      */
  301.             /*-------------------------------------------------------------*/
  302.                WinPostMsg (hwnd, WM_CLOSE, 0, 0);
  303.                break;
  304.  
  305.  
  306.             case IDM_FILE_SAVE:
  307.             {
  308.                /* Retrieve instance data */
  309.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  310.                WriteText (hwnd, pWindowInfo, IDS_SAVE_FILE, FALSE);
  311.                break;
  312.             }
  313.  
  314.  
  315.             case IDM_FILE_SAVEAS:
  316.             /*-------------------------------------------------------------*/
  317.             /* When the user selects the File->Save as menu item to save a */
  318.             /* file, display the standard "Save as" dialog using           */
  319.             /* WinFileDlg. This accepts a FILEDLG structure, which is      */
  320.             /* initialized to contain the currently open file.             */
  321.             /*-------------------------------------------------------------*/
  322.                {
  323.                 PFILEDLG  pSaveDlgInfo;
  324.                 TID       tidOpen;
  325.                 char      szString[BUFFERSIZE];
  326.  
  327.                 /* Retrieve instance data */
  328.                 pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  329.  
  330.                 /* Allocate and initialize file dialog structure */
  331.                 pSaveDlgInfo = (PFILEDLG) malloc (sizeof (FILEDLG));
  332.  
  333.                 pSaveDlgInfo->cbSize = sizeof(FILEDLG);  /* Size of structure */
  334.                 pSaveDlgInfo->fl = FDS_CENTER |          /* Behavior flags */
  335.                                    FDS_HELPBUTTON |
  336.                                    FDS_SAVEAS_DIALOG;
  337.                 pSaveDlgInfo->ulUser = 0;                /* No user data */
  338.                 pSaveDlgInfo->lReturn = 0;               /* Result code - returned */
  339.                 pSaveDlgInfo->lSRC = 0;                  /* System return code */
  340.  
  341.                 /* Load string resource for dialog title */                             
  342.                 WinLoadString (pWindowInfo->hab,                        
  343.                                NULLHANDLE, /* Use own resources file */ 
  344.                                IDS_SAVEAS,                              
  345.                                BUFFERSIZE,                         
  346.                                szString);                               
  347.                 pSaveDlgInfo->pszTitle = szString;       /* Dialog title string */
  348.                 /* Load string resource for OK button text */                             
  349.                 WinLoadString (pWindowInfo->hab,                        
  350.                                NULLHANDLE, /* Use own resources file */ 
  351.                                IDS_SAVE,                              
  352.                                BUFFERSIZE,                         
  353.                                szString);                               
  354.                 pSaveDlgInfo->pszOKButton = szString;    /* Default OK pushbutton text */
  355.                 pSaveDlgInfo->pfnDlgProc = fnSaveasDlgProc;   /* Use subclassing dialog procedure */
  356.                 pSaveDlgInfo->pszIType = NULL;           /* No extended attribute type filters */
  357.                 pSaveDlgInfo->papszITypeList = NULL;
  358.                 pSaveDlgInfo->pszIDrive = NULL;          /* Initial drive */
  359.                 pSaveDlgInfo->papszIDriveList = NULL;    /* No specified list of drives */
  360.                 pSaveDlgInfo->hMod = (HMODULE) NULL;     /* No custom dialog resources */
  361.  
  362.                 /* Specify the fully-qualified name of the loaded file here; */
  363.                 /* the selected filename is also returned here.              */
  364.                 strcpy (pSaveDlgInfo->szFullFile, pWindowInfo->szFileName);
  365.  
  366.                 pSaveDlgInfo->papszFQFilename = NULL;    /* No multiple-file selection */
  367.                 pSaveDlgInfo->ulFQFCount = 0;            /* Number of files selected - returned */
  368.                 pSaveDlgInfo->usDlgId = 0;               /* No custom dialog id */
  369.                 pSaveDlgInfo->x = FDS_CENTER;            /* Display in center of parent */
  370.                 pSaveDlgInfo->y = FDS_CENTER;
  371.                 pSaveDlgInfo->sEAType = 0;               /* Not used in Open dialog */
  372.  
  373.                 WinFileDlg (HWND_DESKTOP, hwnd, pSaveDlgInfo);
  374.  
  375.                 if (pSaveDlgInfo->lReturn == DID_OK)  /* If user pressed "OK", i.e. "Save" */
  376.                    {
  377.                     
  378.                     /*================================================*/
  379.                     /* Place processing to save file here.            */
  380.                     /*================================================*/
  381.  
  382.                     WinLoadString (pWindowInfo->hab,
  383.                                    NULLHANDLE, /* Use own resources file */
  384.                                    IDS_FILE_SAVED,
  385.                                    BUFFERSIZE,
  386.                                    szString);
  387.  
  388.                     sprintf (pWindowInfo->szText, szString, pWindowInfo->szFileName);
  389.  
  390.                     WinInvalidateRect (hwnd, NULL, FALSE);  /* Force a repaint */
  391.                    }
  392.  
  393.                 free (pSaveDlgInfo);
  394.                }
  395.                break;
  396.  
  397.  
  398.             case IDM_FILE_PRINT:
  399.             {
  400.                /* Retrieve instance data */
  401.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  402.                WriteText (hwnd, pWindowInfo, IDS_PRINT_FILE, FALSE);
  403.                break;
  404.             }
  405.  
  406.  
  407.             case IDM_EDIT_UNDO:       
  408.              {
  409.                /* Retrieve instance data */
  410.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  411.                WriteText (hwnd, pWindowInfo, IDS_UNDO, FALSE);
  412.                break;
  413.              }
  414.  
  415.  
  416.             case IDM_EDIT_COPY:
  417.              {
  418.                /* Retrieve instance data */
  419.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  420.                WriteText (hwnd, pWindowInfo, IDS_COPY, FALSE);
  421.                break;
  422.              }
  423.  
  424.  
  425.             case IDM_EDIT_CUT:        
  426.              {
  427.                /* Retrieve instance data */
  428.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  429.                WriteText (hwnd, pWindowInfo, IDS_CUT, FALSE);
  430.                break;
  431.              }
  432.  
  433.  
  434.             case IDM_EDIT_PASTE:
  435.              {
  436.                /* Retrieve instance data */
  437.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  438.                WriteText (hwnd, pWindowInfo, IDS_PASTE, FALSE);
  439.                break;
  440.              }
  441.  
  442.  
  443.             case IDM_EDIT_FIND:
  444.              {
  445.                /* Retrieve instance data */
  446.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  447.                WriteText (hwnd, pWindowInfo, IDS_FIND, FALSE);
  448.                break;
  449.              }
  450.  
  451.  
  452.             case IDM_EDIT_FINDNEXT:
  453.              {
  454.                /* Retrieve instance data */
  455.                pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  456.                WriteText (hwnd, pWindowInfo, IDS_FINDNEXT, FALSE);
  457.                break;
  458.              }
  459.  
  460.  
  461.             case IDM_HELP_PRODINFO:
  462.             /*------------------------------------------------------------*/
  463.             /* User requests product information by selecting the Product */
  464.             /* Information item from the help pull-down menu.  Display a  */
  465.             /* dialog box with the information.                           */ 
  466.             /*------------------------------------------------------------*/
  467.                WinDlgBox (HWND_DESKTOP,    
  468.                           hwnd,            
  469.                           fnProdInfoWndProc, /* Dialog procedure, below */
  470.                           NULLHANDLE,        /* Resource in EXE */          
  471.                           IDD_PROD_INFO,     /* Dialog id */
  472.                           NULL);             /* No add'l data */
  473.  
  474.               /* Retrieve instance data */
  475.               pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  476.               WriteText (hwnd, pWindowInfo, IDS_HELP_PRODINFO, TRUE);
  477.               break;
  478.  
  479.  
  480.             case IDM_HELP_INDEX:
  481.             /*------------------------------------------------------------*/
  482.             /* Catch "Help index" message and pass the request on to      */
  483.             /* the help window.                                           */
  484.             /*------------------------------------------------------------*/
  485.             {
  486.               HWND hwndHelp;
  487.         
  488.               hwndHelp = WinQueryHelpInstance (hwnd);
  489.               WinSendMsg (hwndHelp, HM_HELP_INDEX, 0L, 0L);
  490.  
  491.               /* Retrieve instance data */
  492.               pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  493.               WriteText (hwnd, pWindowInfo, IDS_HELP_INDEX, TRUE);
  494.               break;
  495.             }
  496.  
  497.  
  498.             case IDM_HELP_GENERAL:
  499.             /*------------------------------------------------------------*/
  500.             /* Catch "General help" message and pass the request on to    */
  501.             /* the help window.                                           */
  502.             /*------------------------------------------------------------*/
  503.             {
  504.               HWND hwndHelp;
  505.               USHORT genHelp = IDH_GENHELP_RESNO;
  506.  
  507.               hwndHelp = WinQueryHelpInstance (hwnd);
  508.  
  509.               WinSendMsg (hwndHelp, 
  510.                           HM_DISPLAY_HELP, 
  511.                           MPFROMSHORT(genHelp), 
  512.                           MPFROMSHORT(HM_RESOURCEID));
  513.  
  514.               /* Retrieve instance data */
  515.               pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  516.               WriteText (hwnd, pWindowInfo, IDS_HELP_GENERAL, TRUE);
  517.               break;
  518.             }
  519.  
  520.  
  521.             case IDM_HELP_USING:
  522.             /*------------------------------------------------------------*/
  523.             /* Catch "Using help" message and pass the request on to      */
  524.             /* the help window.                                           */
  525.             /*------------------------------------------------------------*/
  526.             {
  527.               HWND hwndHelp;
  528.  
  529.               hwndHelp = WinQueryHelpInstance (hwnd);
  530.               WinSendMsg (hwndHelp, HM_DISPLAY_HELP, 0L, 0L);
  531.  
  532.               /* Retrieve instance data */
  533.               pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  534.               WriteText (hwnd, pWindowInfo, IDS_HELP_USING, TRUE);
  535.               break;
  536.             }
  537.  
  538.  
  539.  
  540.             case IDM_HELP_TUTORIAL:
  541.             /*------------------------------------------------------------*/
  542.             /* Send a message to the help manager to handle the tutorial  */
  543.             /* request so that if the Tutorial is requested from the IPF  */
  544.             /* Help window, the same code to invoke the tutorial is       */
  545.             /* called.                                                    */
  546.             /*------------------------------------------------------------*/
  547.              {
  548.                WinSendMsg (hwnd, HM_TUTORIAL, 0L, 0L);
  549.                break;
  550.              }
  551.  
  552.           }  /* end switch WM_COMMAND */
  553.  
  554.           break;  /* WM_COMMAND */
  555.  
  556.  
  557.      case UM_FILEERROR:
  558.      /*--------------------------------------------------------------------*/
  559.      /* UM_FILEERROR is posted by the file thread if the file could        */
  560.      /* not be loaded for whatever reason. Notify the user that an error   */
  561.      /* occurred.                                                          */
  562.      /*--------------------------------------------------------------------*/
  563.      {
  564.        char      szString[BUFFERSIZE];
  565.        char      szError[BUFFERSIZE];
  566.        char      szTitle[BUFFERSIZE];
  567.  
  568.        /* Retrieve instance data */
  569.        pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  570.  
  571.        /* Load string resources */
  572.        WinLoadString (pWindowInfo->hab, NULLHANDLE, IDS_ERROR_OPENING_FILE, 
  573.                       BUFFERSIZE, szString);
  574.        WinLoadString (pWindowInfo->hab, NULLHANDLE, IDS_TITLE,
  575.                       BUFFERSIZE, szTitle);
  576.        sprintf (szError, szString, pWindowInfo->szFileName);
  577.  
  578.        /* Display message box */
  579.        WinMessageBox (HWND_DESKTOP,
  580.                       hwnd,
  581.                       szError,
  582.                       szTitle,
  583.                       IDW_MESSAGE_BOX,
  584.                       MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
  585.         break;
  586.      }
  587.  
  588.  
  589.  
  590.      case HM_TUTORIAL:
  591.      /*--------------------------------------------------------------------*/
  592.      /* This case handles Help manager's, or this program's own request    */
  593.      /* for tutorial.  If the tutorial program is not already running,     */
  594.      /* start it. A message can be sent to this window, from any part of   */
  595.      /* this program, or from another program, requesting that the tutorial*/
  596.      /* be started.                                                        */
  597.      /*--------------------------------------------------------------------*/
  598.       {
  599.        HAB   hab;
  600.  
  601.        hab = WinQueryAnchorBlock(hwnd);
  602.        StartTutorial (hwnd, hab);
  603.  
  604.        /* Retrieve instance data */
  605.        pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  606.        WriteText (hwnd, pWindowInfo, IDS_HELP_TUTORIAL, TRUE);
  607.  
  608.        break;
  609.       }
  610.  
  611.  
  612.      case UM_FILEOPENED:
  613.      {
  614.        CHAR szString[BUFFERSIZE];
  615.  
  616.        /* Retrieve instance data */
  617.        pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  618.  
  619.        /* Save text to display in instance data */
  620.        WinLoadString (pWindowInfo->hab, NULLHANDLE, IDS_FILE_OPENED, BUFFERSIZE, szString);
  621.        sprintf (pWindowInfo->szText, szString, pWindowInfo->szFileName);
  622.        WinInvalidateRect (hwnd, NULL, FALSE);  /* Force a repaint */
  623.  
  624.        break;
  625.      }      
  626.  
  627.  
  628.      case WM_CLOSE:
  629.      /*--------------------------------------------------------------------*/
  630.      /* Under WM_CLOSE, pop up a message box confirming that the user      */
  631.      /* wants to end the program. Then post WM_QUIT to terminate.          */
  632.      /*--------------------------------------------------------------------*/
  633.      {
  634.        HAB   hab;
  635.        char  szExit[BUFFERSIZE];
  636.        char  szTitle[BUFFERSIZE];
  637.  
  638.        hab = WinQueryAnchorBlock(hwnd);
  639.  
  640.        /* Load string resources */
  641.        WinLoadString (hab, NULLHANDLE, IDS_EXIT, BUFFERSIZE, szExit);
  642.        WinLoadString (hab, NULLHANDLE, IDS_TITLE, BUFFERSIZE, szTitle);
  643.  
  644.        if (WinMessageBox (HWND_DESKTOP, 
  645.                           hwnd,
  646.                           szExit,
  647.                           szTitle,
  648.                           IDW_MESSAGE_BOX,
  649.                           MB_YESNO | MB_ICONQUESTION | MB_MOVEABLE)
  650.              == MBID_YES)
  651.               WinPostMsg (hwnd, WM_QUIT, 0, 0);
  652.  
  653.         break;
  654.      }
  655.  
  656.      case WM_DESTROY:
  657.      /*====================================================================*/
  658.      /* Perform any final clean up work here.                              */
  659.      /*====================================================================*/
  660.      {
  661.         /* Destroy and disassociate help instance */
  662.         HWND hwndHelp;
  663.  
  664.         hwndHelp = WinQueryHelpInstance (hwnd);
  665.         WinDestroyHelpInstance (hwndHelp);
  666.         WinAssociateHelpInstance (NULLHANDLE, hwnd);
  667.  
  668.         /* Retrieve and free memory allocated for instance data */
  669.         pWindowInfo = (PWINDOWINFO) WinQueryWindowPtr (hwnd, 0);
  670.         free (pWindowInfo);
  671.  
  672.         break;
  673.       }
  674.  
  675.      default:
  676.  
  677.         mr = WinDefWindowProc (hwnd, msg, mp1, mp2);
  678.         break;
  679.     }   /* Endswitch msg */ 
  680.  
  681.  return mr;
  682. }   /* End of function */
  683.  
  684.  
  685.  
  686. /***************************************************************************/
  687. /* fnOpenThread is the file-open routine. It opens the file, and returns   */
  688. /* with an error if the file could not be opened.  You could add further   */
  689. /* processing like querying the file information, or loading the file into */
  690. /* memory here.  Any file information can be returned to the main thread   */
  691. /* via a message.                                                          */
  692. /* Parameters:                                                             */
  693. /*     PVOID pInfo - Pointer to client window instance data. Thread        */
  694. /*                   function parameters must always be PVOID.             */
  695. /***************************************************************************/
  696. VOID fnOpenThread (PVOID pInfo)
  697. {
  698.  HFILE        hFile;                  /* File handle of file opened */
  699.  ULONG        ulAction;               /* Action taken by DosOpen */
  700.  CHAR         szFileName[CCHMAXPATH]; /* File to open */
  701.  HWND         hwnd;
  702.  ULONG        ulmsg;                  /* Message to send to client window */
  703.  APIRET       rc;                     /* Return code for DosOpen */
  704.  PWINDOWINFO  pOpenInfo;   
  705.  
  706.  pOpenInfo = (PWINDOWINFO)pInfo;
  707.  strcpy (szFileName, pOpenInfo->szFileName); /* Get file name to open */
  708.  hwnd = pOpenInfo->hwnd;                     /* Get calling thread's hwnd */
  709.  
  710.  ulmsg = UM_FILEERROR;                         /* Set message error flag */
  711.  
  712.  /* Open file */
  713.  
  714.  rc = DosOpen (szFileName, 
  715.                &hFile, 
  716.                &ulAction, 
  717.                0L,                         
  718.                0L,
  719.                OPEN_ACTION_FAIL_IF_NEW |    /* Open flags */
  720.                OPEN_ACTION_OPEN_IF_EXISTS,
  721.                OPEN_SHARE_DENYWRITE |       /* Access flags */
  722.                OPEN_ACCESS_READONLY,        
  723.                0L);                /* No extended attributes buffer */
  724.  if (rc) 
  725.     ulmsg = UM_FILEERROR;    /* DosOpen failed. Send error msg to main thread */
  726.  else
  727.  {
  728.     /*==================================*/
  729.     /* Add any further processing here  */
  730.     /*==================================*/
  731.  
  732.     ulmsg = UM_FILEOPENED;   /* DosOpen successful. Send success msg to main thread */
  733.     DosClose (hFile);        /* Close file for now */
  734.  }
  735.  
  736.  /* Post msg to main thread. A pointer to encoded */          
  737.  /* info could be passed as a msg parameter       */          
  738.  WinPostMsg (hwnd, ulmsg, 0, 0);  
  739.                                           
  740.  _endthread();
  741. }
  742.  
  743.  
  744.  
  745. /****************************************************************************/
  746. /* Dialog procedure for the Product Information dialog.  It processes the   */
  747. /* OK push button to dismiss the dialog.  The rest of the messages go to    */
  748. /* default processing.                                                      */
  749. /****************************************************************************/
  750. MRESULT APIENTRY fnProdInfoWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  751. {
  752.  MRESULT mr = 0;      /* Result code */
  753.  HWND hwndOK;         /* Window handle of OK push button */
  754.  BOOL fSucc;
  755.  
  756.  switch (msg)
  757.     {
  758.     /* If the user hits OK, use WinDismissDlg to return TRUE to the main      */
  759.     /* window procedure.  Otherwise, return FALSE.  This value is picked up   */
  760.     /* as the return value of WinDlgBox.                                      */
  761.  
  762.      case WM_COMMAND:
  763.  
  764.         switch (SHORT1FROMMP (mp1))
  765.            {
  766.             case IDP_PRODINFO_OK:
  767.  
  768.                WinDismissDlg (hwnd,   /* Dialog Window Handle */
  769.                               TRUE);  /* OK button is TRUE */  
  770.                break;
  771.  
  772.             default:
  773.                mr = WinDefDlgProc(hwnd, msg, mp1, mp2);
  774.                break;
  775.            }
  776.         break;
  777.  
  778.      /* Let the default dialog box window procedure handle any other messages  */
  779.      /* for this dialog.                                                       */
  780.      default:
  781.         mr = WinDefDlgProc (hwnd, msg, mp1, mp2);
  782.         break;
  783.     }
  784.  return (mr);
  785. }
  786.  
  787.  
  788.  
  789. /********************************************************************/
  790. /* Writes text on the window giving feedback for selected commands  */
  791. /* Parameters:                                                      */
  792. /*     HWND        hwnd        - Window handle of client window     */
  793. /*     PWINDOWINFO pWindowInfo - Instance data for client window    */
  794. /*     ULONG       ulStringID  - Resource ID of string to display   */
  795. /*     BOOL        fHelp       - TRUE if command is a Help command  */
  796. /*                               FALSE otherwise                    */ 
  797. /********************************************************************/
  798. VOID WriteText (HWND hwnd, PWINDOWINFO pWindowInfo, ULONG ulStringID, BOOL fHelp)
  799. {
  800.   CHAR szString[BUFFERSIZE];     /* String buffer to hold loaded string resource */
  801.   RECTL rectClientWindow;
  802.  
  803.   /*---------------------------------------------------------------------------*/ 
  804.   /* If the selected command is a help command, write the text unconditionally.*/
  805.   /* Otherwise, check first whether a file has been loaded before writing the  */
  806.   /* text.  Display an error message if no file has been loaded.               */ 
  807.   /*---------------------------------------------------------------------------*/
  808.   if (strcmp(pWindowInfo->szFileName,"*.*") || fHelp)
  809.    {
  810.      WinLoadString (pWindowInfo->hab,
  811.                     NULLHANDLE, /* Use own resources file */
  812.                     ulStringID,
  813.                     BUFFERSIZE,
  814.                     szString);
  815.  
  816.      sprintf (pWindowInfo->szText, szString, pWindowInfo->szFileName);
  817.  
  818.      WinQueryWindowRect (hwnd, &rectClientWindow);        /* Get window rectangle */
  819.      WinInvalidateRect (hwnd, &rectClientWindow, FALSE);  /* Force a repaint */
  820.     }
  821.    else
  822.     /* Procedure to display error dialog */
  823.     DlgFileNotLoaded (hwnd, pWindowInfo);
  824. }
  825.  
  826.  
  827.  
  828. /*****************************************************************/
  829. /* Display "File not loaded" message box.                        */
  830. /* Parameters:                                                   */
  831. /*     HWND        hwnd        - Window handle of client window  */
  832. /*     PWINDOWINFO pWindowInfo - Instance data for client window */
  833. /*****************************************************************/
  834. VOID DlgFileNotLoaded (HWND hwnd, PWINDOWINFO pWindowInfo)
  835. {
  836.   CHAR  szError[BUFFERSIZE];
  837.   CHAR  szTitle[BUFFERSIZE];
  838.  
  839.   /* Load string resources */
  840.   WinLoadString (pWindowInfo->hab,
  841.                  NULLHANDLE, /* Use own resources file */
  842.                  IDS_ERROR_NO_FILE_LOADED,
  843.                  BUFFERSIZE,
  844.                  szError);
  845.  
  846.   WinLoadString (pWindowInfo->hab,
  847.                  NULLHANDLE, /* Use own resources file */
  848.                  IDS_TITLE,
  849.                  BUFFERSIZE,
  850.                  szTitle);
  851.  
  852.   /* Display message box */
  853.   WinMessageBox (HWND_DESKTOP,
  854.                  hwnd,
  855.                  szError,
  856.                  szTitle,
  857.                  IDW_MESSAGE_BOX,
  858.                  MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
  859. }
  860.  
  861.  
  862.  
  863. /**************************************************************************/     
  864. /* Help manager initialization and preparation. Set up the HELPINIT       */     
  865. /* structure.                                                             */     
  866. /* Parameters:                                                            */
  867. /*   HWND hwnd - Window handle of client window                           */
  868. /*   HAB  hab  - Anchor block handle                                      */
  869. /**************************************************************************/     
  870. VOID SetupHelp (HWND hwnd, HAB hab)
  871. {                                                                                  
  872.  HWND     hwndHelp;
  873.  HELPINIT mainHelp;
  874.  CHAR     szString[BUFFERSIZE];
  875.  CHAR     szTitle[BUFFERSIZE];
  876.  
  877.  mainHelp.cb = sizeof (HELPINIT);      /* Standard size of structure */             
  878.  mainHelp.ulReturnCode = 0;            /* Return code - indicates error if non-zero */
  879.  mainHelp.pszTutorialName = NULL;      /* Tutorial commmand */
  880.  mainHelp.phtHelpTable = (PHELPTABLE)MAKEULONG (IDH_MAIN_HELPTABLE, 0xFFFF); /* Help table ID in resources */ 
  881.  mainHelp.hmodHelpTableModule = NULLHANDLE;  /* Help table resource in EXE */
  882.  mainHelp.hmodAccelActionBarModule = NULLHANDLE; /* No add'l help resources */
  883.  mainHelp.idAccelTable = 0;         /* No add'l help accelerator */
  884.  mainHelp.idActionBar = 0;          /* Use default action bar */
  885.                                                                                   
  886.  WinLoadString (hab, NULLHANDLE, IDS_TITLE, BUFFERSIZE, szTitle); 
  887.  mainHelp.pszHelpWindowTitle = szTitle;     /* Help manager window title */
  888.                                                                                   
  889.  mainHelp.fShowPanelId = CMIC_HIDE_PANEL_ID; /* Don't show panel res numbers */
  890.  mainHelp.pszHelpLibraryName = HELP_FILE_NAME;  /* Name of HLP file */
  891.                                                                                   
  892.  /* Create the help window for this program. If it could not be created,   */     
  893.  /* or if another help error occurred, notify the user.  A failure would   */     
  894.  /* not be fatal; an application can function without help.                */     
  895.                                                                                   
  896.  hwndHelp = WinCreateHelpInstance (hab, &mainHelp);                                 
  897.  
  898.  if (!hwndHelp)   /* Couldn't create help window */
  899.  {
  900.     WinLoadString (hab, NULLHANDLE, IDS_ERROR_CREATING_HELP, BUFFERSIZE, szString);
  901.     WinMessageBox (HWND_DESKTOP, 
  902.                    hwnd, 
  903.                    szString,                      
  904.                    szTitle,
  905.                    IDW_MESSAGE_BOX, 
  906.                    MB_OK | MB_MOVEABLE);                         
  907.  }
  908.  else                                                                             
  909.  {
  910.     if (mainHelp.ulReturnCode)   /* Couldn't initialize help */
  911.        {                                                                          
  912.         WinLoadString (hab, NULLHANDLE, IDS_ERROR_NO_HELP, BUFFERSIZE, szString);
  913.         WinMessageBox (HWND_DESKTOP, 
  914.                        hwnd, 
  915.                        szString,
  916.                        szTitle,
  917.                        IDW_MESSAGE_BOX, 
  918.                        MB_OK | MB_MOVEABLE);                     
  919.  
  920.         WinDestroyHelpInstance (hwndHelp);                                        
  921.         hwndHelp = NULLHANDLE;                                                            
  922.        }                                                                          
  923.     else                                                                          
  924.        WinAssociateHelpInstance (hwndHelp, hwnd);                            
  925.  }                                                                                 
  926. }
  927.  
  928.  
  929.  
  930. /**************************************************************************/
  931. /* Start the tutorial program VIEW.EXE to view the tutorial INF file      */
  932. /* using DosStartSession().                                               */
  933. /* Parameters:                                                            */
  934. /*   HWND hwnd - Window handle of client window                           */
  935. /*   HAB  hab  - Anchor block handle                                      */
  936. /**************************************************************************/
  937. VOID StartTutorial(HWND hwnd, HAB hab)
  938. {
  939.   STARTDATA StartData;                           /* Start session data structure */
  940.   ULONG     SessID;                              /* Session ID - returned */
  941.   PID       PID;                                 /* Process ID - returned */
  942.   CHAR      szString[BUFFERSIZE];                /* String buffer */
  943.   CHAR      szTitle[BUFFERSIZE];                 /* Buffer to hold application title */
  944.   CHAR      bResultBuf[BUFFERSIZE];               /* Result buffers for searches */
  945.   CHAR      bPathBuf1[BUFFERSIZE];                
  946.   CHAR      bPathBuf2[BUFFERSIZE];                
  947.   CHAR      szObjectBuffer[BUFFERSIZE];                /* Object buffer */
  948.   CHAR      szHelpTutorialBuffer[BUFFERSIZE] = {'\0'}; /* Used to build tutorial path for VIEW */
  949.  
  950.   WinLoadString (hab, NULLHANDLE, IDS_TITLE, BUFFERSIZE, szTitle);
  951.  
  952.   /* Check whether tutorial viewer program, VIEW.EXE, and its supporting program, */
  953.   /* VIEWDOC.EXE is present along the PATH.                                       */
  954.   _searchenv (TUTORIAL_PROGRAM, "PATH", bPathBuf1);
  955.   _searchenv (TUTORIAL_PROGRAM2,"PATH", bPathBuf2);
  956.  
  957.   if ( !(strcmp (bPathBuf1,"") && strcmp (bPathBuf2,"")) )
  958.    {
  959.       WinLoadString (hab, NULLHANDLE, IDS_ERROR_VIEW_NOT_FOUND, BUFFERSIZE, szString);
  960.       WinMessageBox (HWND_DESKTOP,
  961.                      hwnd,
  962.                      szString,
  963.                      szTitle,
  964.                      IDW_MESSAGE_BOX,
  965.                      MB_OK | MB_MOVEABLE);
  966.       return;
  967.    }
  968.  
  969.   /* Check whether tutorial INF file is present along the HELP path */
  970.   _searchenv (TUTORIAL_FILE, "HELP", bResultBuf);
  971.   if (!strcmp(bResultBuf, "")) 
  972.    {
  973.       WinLoadString (hab, NULLHANDLE, IDS_ERROR_NO_TUTORIAL, BUFFERSIZE, szString);
  974.       WinMessageBox (HWND_DESKTOP,
  975.                      hwnd,
  976.                      szString,
  977.                      szTitle,
  978.                      IDW_MESSAGE_BOX,
  979.                      MB_OK | MB_MOVEABLE);
  980.       return;
  981.    }
  982.  
  983.   /* Initialize the start session structure */
  984.   StartData.Length   = sizeof(STARTDATA);   /* Length of STARTDATA structure */
  985.   StartData.Related  = SSF_RELATED_CHILD;   /* Child session */
  986.   StartData.FgBg     = SSF_FGBG_FORE;       /* Start child session in foreground */
  987.   StartData.TraceOpt = SSF_TRACEOPT_NONE;   /* Do not trace session */
  988.   WinLoadString (hab, NULLHANDLE, IDS_TUTORIAL_TITLE, BUFFERSIZE, szString);
  989.   StartData.PgmTitle = (PSZ)szString;       /* Session Title string */
  990.   StartData.PgmName  = TUTORIAL_PROGRAM;    /* Tutorial program path name */
  991.  
  992.   /*-----------------------------------------------------------------------------*/
  993.   /* Pass the tutorial INF file name as input arguments to the VIEW program.     */
  994.   /* Single and then double quote the filename in case the file name is specified*/
  995.   /* as a list of files concatenated with plus (+) signs.  Otherwise the VIEW    */
  996.   /* program interprets the file name as one long file name with plus signs.     */
  997.   /*-----------------------------------------------------------------------------*/
  998.   strcpy(szHelpTutorialBuffer,"\'\"");       /* Single followed by double quote */
  999.   strcat(szHelpTutorialBuffer,bResultBuf); /* Fully-qualified tutorial filename found above */
  1000.   strcat(szHelpTutorialBuffer,"\"\'");     /* Double followed by single quote */
  1001.   StartData.PgmInputs   = (PBYTE)szHelpTutorialBuffer;
  1002.  
  1003.   StartData.TermQ       = 0;               /* Assume no termination queue  */
  1004.   StartData.Environment = 0;               /* Assume no environment string */
  1005.  
  1006.   /* Inherit environment and open file handles from parent */
  1007.   StartData.InheritOpt  = SSF_INHERTOPT_PARENT;
  1008.  
  1009.   StartData.SessionType = SSF_TYPE_DEFAULT;    /* Let Shell establish session type */
  1010.   StartData.IconFile    = 0;                   /* No specific icon file provided */
  1011.   StartData.PgmHandle   = 0;                   /* Do not use the installation file */
  1012.   StartData.PgmControl  = SSF_CONTROL_VISIBLE; /* Start program visible and maximized */
  1013.  
  1014.   /* Initial window coordinates and size */
  1015.   StartData.InitXPos    = 30;
  1016.   StartData.InitYPos    = 40;
  1017.   StartData.InitXSize   = 0;
  1018.   StartData.InitYSize   = 0;
  1019.  
  1020.   StartData.Reserved      = 0;                     /* Reserved, must be zero */
  1021.   StartData.ObjectBuffer  = (PSZ)szObjectBuffer;   /* Buffer to hold failure causes */
  1022.   StartData.ObjectBuffLen = sizeof(szObjectBuffer);
  1023.  
  1024.   /*----------------------------------------------------------------------*/
  1025.   /* On successful return, the variable SessID contains the session ID    */
  1026.   /* of the new session, and the variable PID contains the process ID     */
  1027.   /* of the new process.                                                  */
  1028.   /*----------------------------------------------------------------------*/
  1029.   if (DosStartSession(&StartData, &SessID, &PID))
  1030.   {
  1031.     WinLoadString (hab, NULLHANDLE, IDS_ERROR_STARTING_TUTORIAL, BUFFERSIZE, szString);
  1032.  
  1033.     WinMessageBox (HWND_DESKTOP,
  1034.                    hwnd,
  1035.                    szString,
  1036.                    szTitle,
  1037.                    IDW_MESSAGE_BOX,
  1038.                    MB_OK | MB_MOVEABLE);
  1039.     return;
  1040.   }
  1041. }
  1042.  
  1043.  
  1044.  
  1045. /***************************************************************************/
  1046. /* Custom window procedure for FileOpen dialog.  This subclassed procedure */
  1047. /* captures the Help pushbutton message and displays the appropriate help. */
  1048. /***************************************************************************/
  1049. MRESULT EXPENTRY fnFileOpenDlgProc (HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  1050.   MRESULT mr = (MRESULT) TRUE;  /* Result code for dialog procedure */
  1051.  
  1052.   switch (msg) 
  1053.   {
  1054.      case WM_HELP:
  1055.      {
  1056.        HWND   hwndHelp;                      /* Help instance window handle */
  1057.        HWND   hwndOwner;                     /* Window handle of main window */
  1058.        USHORT usResNo = IDH_FILEOPEN_RESNO;  /* Help panel res ID for file open dialog */
  1059.  
  1060.        hwndOwner = WinQueryWindow (hwndDlg, QW_OWNER);  /* Get parent's window handle */
  1061.        hwndHelp = WinQueryHelpInstance (hwndOwner);     /* Get help instance */
  1062.  
  1063.        if (WinAssociateHelpInstance (hwndHelp, hwndDlg))
  1064.           WinSendMsg (hwndHelp,
  1065.                       HM_DISPLAY_HELP,
  1066.                       MPFROMSHORT(usResNo),
  1067.                       MPFROMSHORT(HM_RESOURCEID));
  1068.        else
  1069.        {
  1070.           CHAR szString[BUFFERSIZE];   /* Buffer for message box text */
  1071.           CHAR szTitle[BUFFERSIZE];    /* Buffer for message box title */
  1072.           HAB hab;
  1073.  
  1074.           hab = WinQueryAnchorBlock(hwndDlg);
  1075.           WinLoadString (hab, NULLHANDLE, IDS_ERROR_HELP_ASSOC, BUFFERSIZE, szString);
  1076.           WinLoadString (hab, NULLHANDLE, IDS_FILE_OPEN, BUFFERSIZE, szTitle);
  1077.           WinMessageBox (HWND_DESKTOP,
  1078.                          hwndDlg,
  1079.                          szString,
  1080.                          szTitle,
  1081.                          IDW_MESSAGE_BOX,
  1082.                          MB_OK | MB_MOVEABLE);
  1083.        }
  1084.        break;
  1085.      }
  1086.  
  1087.      default: 
  1088.      {
  1089.        mr = WinDefFileDlgProc(hwndDlg, msg, mp1, mp2);  /* Let default dlg proc handle the rest */
  1090.        break;
  1091.      }
  1092.   } /* endswitch */
  1093.  
  1094.   return mr;
  1095. }    
  1096.  
  1097.  
  1098.  
  1099. /****************************************************************************/
  1100. /* Custom window procedure for "Save as" dialog.  This subclassed procedure */
  1101. /* captures the Help pushbutton message and displays the appropriate help.  */
  1102. /****************************************************************************/
  1103. MRESULT EXPENTRY fnSaveasDlgProc (HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
  1104. {
  1105.   MRESULT mr = (MRESULT) TRUE;      /* Result code for dialog procedure */
  1106.  
  1107.   switch (msg)
  1108.   {
  1109.      case WM_HELP:
  1110.      {
  1111.        HWND   hwndHelp;                   /* Help instance window handle */
  1112.        HWND   hwndOwner;                  /* Window handle of main window */
  1113.        USHORT usResNo = IDH_SAVEAS_RESNO; /* Help panel res ID for file open dialog */
  1114.  
  1115.        hwndOwner = WinQueryWindow (hwndDlg, QW_OWNER);  /* Get parent's window handle */
  1116.        hwndHelp = WinQueryHelpInstance (hwndOwner);     /* Get help instance */
  1117.  
  1118.        if (WinAssociateHelpInstance (hwndHelp, hwndDlg))
  1119.           WinSendMsg (hwndHelp,
  1120.                       HM_DISPLAY_HELP,
  1121.                       MPFROMSHORT(usResNo),
  1122.                       MPFROMSHORT(HM_RESOURCEID));
  1123.        else
  1124.        {
  1125.           CHAR szString[BUFFERSIZE];   /* Buffer for message box text  */
  1126.           CHAR szTitle[BUFFERSIZE];    /* Buffer for message box title */
  1127.           HAB hab; 
  1128.  
  1129.           hab = WinQueryAnchorBlock(hwndDlg);
  1130.           WinLoadString (hab, NULLHANDLE, IDS_ERROR_HELP_ASSOC, BUFFERSIZE, szString);
  1131.           WinLoadString (hab, NULLHANDLE, IDS_SAVEAS, BUFFERSIZE, szTitle);
  1132.           WinMessageBox (HWND_DESKTOP,
  1133.                          hwndDlg,
  1134.                          szString,
  1135.                          szTitle,
  1136.                          IDW_MESSAGE_BOX,
  1137.                          MB_OK | MB_MOVEABLE);
  1138.        }
  1139.        break;
  1140.      }
  1141.      default:
  1142.      {
  1143.        mr = WinDefFileDlgProc(hwndDlg, msg, mp1, mp2);  /* Let default dlg proc handle the rest */
  1144.        break;
  1145.      }
  1146.   } /* endswitch */
  1147.  
  1148.   return mr;
  1149. }
  1150.  
  1151.  
  1152.