home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PMHELP.ZIP / HELPSAMP.C < prev    next >
Text File  |  1989-07-05  |  7KB  |  206 lines

  1. /*-----------------------------------------------------------
  2.    HELPSAMP.C -- Demonstration of HELPLIB.DLL
  3.   -----------------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7. #include "helpsamp.h"
  8.  
  9.  
  10. /*   GLOBALS   */
  11. HWND hwndFrame;
  12. CHAR szHelpFile[] = "c:\\os2\\system\\helpsamp.hlp";
  13.  
  14.  
  15. /* **************************************************************************/
  16.  
  17. int main (void)
  18. {
  19.      static CHAR  szClientClass[] = "HelpSamp" ;
  20.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  21.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  22.                                  FCF_SHELLPOSITION | FCF_TASKLIST |
  23.                                  FCF_MENU          | FCF_ICON ;
  24.      HAB          hab ;
  25.      HMQ          hmq ;
  26.      HWND         hwndClient ;
  27.      QMSG         qmsg ;
  28.  
  29.      hab = WinInitialize (0) ;
  30.      hmq = WinCreateMsgQueue (hab, 0) ;
  31.  
  32.      WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
  33.  
  34.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  35.                                      &flFrameFlags, szClientClass, NULL,
  36.                                      0L, NULL, ID_RESOURCE, &hwndClient) ;
  37.  
  38.      /* install the help hook    */
  39.      WinSetHook(hab, hmq, HK_HELP, (PFN)HelpHook, NULL);
  40.  
  41.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  42.           WinDispatchMsg (hab, &qmsg) ;
  43.  
  44.  
  45.      /* release the help hook */
  46.      WinReleaseHook(hab, hmq, HK_HELP, (PFN)HelpHook, NULL);
  47.  
  48.      WinDestroyWindow (hwndFrame) ;
  49.      WinDestroyMsgQueue (hmq) ;
  50.      WinTerminate (hab) ;
  51.      return 0;
  52. }
  53.  
  54. /* **************************************************************************/
  55.  
  56. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  57.      {
  58.      switch (msg)
  59.           {
  60.           case WM_COMMAND:
  61.                switch (COMMANDMSG(&msg)->cmd)
  62.                     {
  63.                     case IDM_NEW:
  64.                     case IDM_OPEN:
  65.                     case IDM_SAVE:
  66.                     case IDM_SAVEAS:
  67.                          WinAlarm (HWND_DESKTOP, WA_NOTE) ;
  68.                          return 0 ;
  69.  
  70.                     case IDM_ABOUT:
  71.                     case IDM_DIALOG:
  72.                          WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc,
  73.                                     NULL, IDD_ABOUT, NULL) ;
  74.                          return 0 ;
  75.  
  76.                     case IDM_MESSAGE_1:
  77.                          WinMessageBox(HWND_DESKTOP, hwnd,
  78.                              (PSZ)"Press F1 for help on Message Box 1",
  79.                              (PSZ)"Message Box 1", (USHORT)MSGBOX_ID1,
  80.                              MB_OK|MB_HELP);
  81.                          return 0;
  82.  
  83.                     case IDM_MESSAGE_2:
  84.                          WinMessageBox(HWND_DESKTOP, hwnd,
  85.                              (PSZ)"Press F1 for help on Message Box 2",
  86.                              (PSZ)"Message Box 2", (USHORT)MSGBOX_ID2,
  87.                              MB_OK|MB_HELP);
  88.                          return 0;
  89.  
  90.                     }
  91.                break ;
  92.      
  93.           case WM_ERASEBACKGROUND:
  94.                return 1 ;
  95.           }
  96.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  97.      }
  98.  
  99. /* **************************************************************************/
  100.  
  101. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  102.      {
  103.      switch (msg)
  104.           {
  105.           case WM_COMMAND:
  106.                switch (COMMANDMSG(&msg)->cmd)
  107.                     {
  108.                     case DID_OK:
  109.                     case DID_CANCEL:
  110.                          WinDismissDlg (hwnd, TRUE) ;
  111.                          return 0 ;
  112.                     }
  113.                break ;
  114.  
  115.           case WM_HELP:    /* process HELP msg only if F1 was pressed */
  116.              if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR)  /* means F1 was pressed */
  117.              {
  118.                  /* Force focus to HELP button */
  119.                  WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_ABOUT_HELP));
  120.  
  121.                  /* pass on the message modified for button */
  122.                  return(WinDefDlgProc(hwnd,
  123.                               WM_HELP,
  124.                               MPFROMSHORT((SHORT)IDD_ABOUT_HELP),
  125.                               MPFROM2SHORT((SHORT)CMDSRC_PUSHBUTTON, FALSE)));
  126.              }
  127.              break;
  128.  
  129.           }
  130.  
  131.  
  132.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  133.      }
  134.  
  135. /* **************************************************************************/
  136. BOOL CALLBACK HelpHook(hab, usMode, idTopic, idSubTopic, prcPosition)
  137. HAB hab;
  138. USHORT usMode;
  139. USHORT idTopic;
  140. USHORT idSubTopic;
  141. PRECTL prcPosition;
  142. {
  143.      CHAR pszHelpTopic[256];
  144.      USHORT usStringNum = DEFAULT_HELP;
  145.  
  146.      switch(usMode)
  147.      {
  148.          case HLPM_MENU:
  149.              switch(idTopic)
  150.              {
  151.                  case IDM_FILE:
  152.                  case IDM_BOXES:
  153.                      switch(idSubTopic)                     
  154.                      {
  155.                          case 0xFFFF:        /* menu bar itself highlighted */
  156.                              usStringNum = idTopic;
  157.                              break;
  158.  
  159.                          default:
  160.                              usStringNum = idSubTopic;
  161.                      }        
  162.                      break;
  163.  
  164.                  default:
  165.                      usStringNum = DEFAULT_HELP;
  166.                      break;
  167.              }
  168.              break;
  169.  
  170.          case HLPM_FRAME:
  171.              break;
  172.  
  173.          case HLPM_WINDOW:
  174.              switch(idTopic)
  175.              {
  176.                  /* dialog boxes with help buttons */
  177.                  case IDD_ABOUT:
  178.                      switch(idSubTopic)
  179.                      {
  180.                          case IDD_ABOUT_HELP:
  181.                              usStringNum = idSubTopic;
  182.                              break;
  183.  
  184.                          default:
  185.                              usStringNum = DEFAULT_HELP;
  186.                      }
  187.                      break;
  188.  
  189.                  /* Message Boxes with help Buttons */
  190.                  case MSGBOX_ID1:
  191.                  case MSGBOX_ID2:
  192.                      usStringNum = idTopic;
  193.                      break;
  194.  
  195.                  default:
  196.                      usStringNum = DEFAULT_HELP;
  197.              }
  198.              break;
  199.      }
  200.  
  201.      WinLoadString(hab, NULL, usStringNum, sizeof(pszHelpTopic), pszHelpTopic); 
  202.      HelpBox(hwndFrame, WinQueryActiveWindow(HWND_DESKTOP, FALSE),
  203.              hab, (PSZ)szHelpFile, (PSZ)pszHelpTopic);
  204.      return(FALSE);
  205. }
  206.