home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ipfedit.zip / IPFEDHLP.C < prev    next >
C/C++ Source or Header  |  1993-08-14  |  8KB  |  238 lines

  1. /* File: E:\PMSOURCE\IPFEDIT\IPFEDEMO\IPFEDHLP.C
  2.          (Created by IPF Editor (C) 1992-1993 Bill Perez.)
  3.    Date: Sat Aug 14 16:51:27 1993
  4.    Purpose: This file is  created automatically when the Create C Source menu
  5.       option is selected.  If you edit this file and then rerun the C Source
  6.       command your changes will be lost.
  7. */
  8.  
  9. /* Include Files */
  10. #define INCL_PM
  11. #include <os2.h>
  12. #include  "IPFEDHLP.H"    /* Help panel definitions */
  13.  
  14. /* Global Variables */
  15. BOOL fHelpEnabled = FALSE;
  16. HWND hwndHelpInstance = 0L;
  17.  
  18. /******************************************************
  19.    Function:  HelpInit()
  20.    Author: IPF Editor (C) 1992-1993 Bill Perez.
  21.    Date: Sat Aug 14 16:51:27 1993
  22.    Purpose: Initialize help system
  23.   
  24.    Arguments: 
  25.   
  26.        HWND hwndFrame   Frame of window to associate
  27.                         help instance with.
  28.   
  29.    Returns: 
  30.   
  31.        ULONG ulReturnCode - Result of initialize attempt.
  32.           0 = OK, !0 is OS/2 PM Error Code
  33.  
  34. ******************************************************/
  35. ULONG HelpInit( HWND hwndFrame )
  36. {
  37.     HELPINIT  hini;
  38.  
  39.     /* Reset help enabled in case there is an error  so help will be disabled */
  40.     fHelpEnabled = FALSE;
  41.  
  42.     /* Initialize  help  init structures */
  43.     hini.cb = sizeof( HELPINIT ); 
  44.     hini.ulReturnCode = 0L;
  45.  
  46.     hini.pszTutorialName =  (PSZ) NULL;
  47.  
  48.     hini.phtHelpTable = (PHELPTABLE) MAKELONG( IDD_IPFEDEMO_HELP_TABLE, 0xFFFF  );
  49.     hini.hmodHelpTableModule = (HMODULE) 0L;
  50.     hini.hmodAccelActionBarModule = (HMODULE) 0L;
  51.     hini.idAccelTable = 0;
  52.     hini.idActionBar = 0;
  53.  
  54.     hini.pszHelpWindowTitle = (PSZ) "IPF Editor Demo Program";
  55.  
  56.     /* If debugging help text, show panel ID's */
  57. #ifdef DEBUG
  58.     hini.fShowPanelId  = CMIC_SHOW_PANEL_ID;
  59. #else
  60.     hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  61. #endif
  62.  
  63.     hini.pszHelpLibraryName = (PSZ)  "IPFEDEMO.HLP";
  64.  
  65.     hwndHelpInstance =
  66.         WinCreateHelpInstance(
  67.             WinQueryAnchorBlock( hwndFrame ),
  68.             &hini );
  69.  
  70.     /* Did help get initialized correctly? */
  71.     if( !hwndHelpInstance || hini.ulReturnCode )
  72.         return hini.ulReturnCode;
  73.  
  74.     /* Associate help instance with window frame */
  75.     if( !WinAssociateHelpInstance( hwndHelpInstance, hwndFrame )  )
  76.         return ERRORIDERROR( WinGetLastError( WinQueryAnchorBlock( hwndFrame ) ) );
  77.  
  78.     return 0;
  79.  
  80. }
  81.  
  82.  
  83. /******************************************************
  84.    Function:  HelpDestroyInstance()
  85.    Author: IPF Editor (C) 1992-1993 Bill Perez.
  86.    Date: Sat Aug 14 16:51:27 1993
  87.    Purpose: Destroy help instance
  88.   
  89.    Arguments: none.
  90.   
  91.    Returns: none.
  92.   
  93. ******************************************************/
  94. VOID HelpDestroyInstance( VOID )
  95. {
  96.     if( hwndHelpInstance )
  97.         WinDestroyHelpInstance( hwndHelpInstance );
  98.  
  99. }
  100.  
  101.  
  102. /******************************************************
  103.    Function:  HelpProcessMessages()
  104.    Author: IPF Editor (C) 1992-1993 Bill Perez.
  105.    Date: Sat Aug 14 16:51:27 1993
  106.    Purpose: Processes help menu messages
  107.   
  108.    Arguments: Standard PM Message format
  109.   
  110.    Returns: Varies Based on Message
  111.   
  112.    Call:  Call this when processing WM_ACTIVATE, WM_COMMAND,
  113.           and WM_INITMENU messages.
  114.  
  115. ******************************************************/
  116. MRESULT HelpProcessMessages( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  117. {
  118.     switch( msg )
  119.     {
  120.         case WM_COMMAND:
  121.             switch( SHORT1FROMMP( mp1 ) )
  122.             {
  123.                 case IDM_HELP_USING:
  124.                     if( WinQueryHelpInstance( hwnd ) )
  125.                         return WinSendMsg( WinQueryHelpInstance( hwnd ), HM_DISPLAY_HELP, 0L, 0L );
  126.                     break;
  127.  
  128.                 case IDM_HELP_INDEX:
  129.                     if( WinQueryHelpInstance( hwnd ) )
  130.                         return WinSendMsg( WinQueryHelpInstance( hwnd ), HM_HELP_INDEX, 0L, 0L );
  131.                     break;
  132.  
  133.                 case IDM_HELP_CONTENTS:
  134.                     if( WinQueryHelpInstance( hwnd ) )
  135.                         return WinSendMsg( WinQueryHelpInstance( hwnd ), HM_HELP_CONTENTS, 0L, 0L );
  136.                     break;
  137.  
  138.                 case IDM_HELP_GENERAL:
  139.                     if( WinQueryHelpInstance( hwnd ) )
  140.                         return WinSendMsg( WinQueryHelpInstance( hwnd ), HM_GENERAL_HELP, 0L, 0L );
  141.                     break;
  142.  
  143.             }
  144.             return (MRESULT) 0L;
  145.  
  146.         case WM_ACTIVATE:
  147.             if( SHORT1FROMMP( mp1 ) )
  148.             {
  149.                 WinSendMsg(
  150.                     WinQueryHelpInstance( hwnd ),
  151.                     HM_SET_ACTIVE_WINDOW,
  152.                     MPFROMLONG( WinQueryWindow( hwnd, QW_PARENT ) ),
  153.                     MPFROMLONG( WinQueryWindow( hwnd, QW_PARENT ) ) );
  154.             }
  155.             else
  156.             {
  157.                 WinSendMsg(
  158.                     WinQueryHelpInstance( hwnd ),
  159.                     HM_SET_ACTIVE_WINDOW,
  160.                     0L,
  161.                     0L );
  162.             }
  163.             return (MRESULT) 0L;
  164.  
  165.         case WM_INITMENU:
  166.             WinSendMsg( 
  167.                 WinQueryHelpInstance( hwnd ),
  168.                 HM_SET_ACTIVE_WINDOW,
  169.                 MPFROMLONG( WinQueryWindow( hwnd, QW_PARENT ) ),
  170.                 MPFROMLONG( WinQueryWindow( hwnd, QW_PARENT ) ) );
  171.             return (MRESULT) 0L;
  172.  
  173.         case HM_ERROR:
  174.             {
  175.                 CHAR szOut[ 128 ];
  176.  
  177.                 sprintf(
  178.                     szOut,
  179.                     "IPF Help error (HM_ERROR: %lx)",
  180.                     LONGFROMMP( mp1 ) );
  181.  
  182.                 WinMessageBox(
  183.                     HWND_DESKTOP,
  184.                     hwnd,
  185.                     szOut,
  186.                     "IPF Editor Demo Program",
  187.                     0,
  188.                     MB_OK | MB_WARNING );
  189.             }
  190.             return (MRESULT) 0L;
  191.  
  192.         case HM_GENERAL_HELP_UNDEFINED:
  193.             WinMessageBox(
  194.                 HWND_DESKTOP,
  195.                 hwnd,
  196.                 "General help requested not defined.  Sorry.",
  197.                 "IPF Editor Demo Program",
  198.                 0,
  199.                 MB_OK | MB_WARNING );
  200.             return (MRESULT) 0L;
  201.  
  202. /* You may want to remove the following handling from your final 
  203.    code when all help handling has been implemented.  If this returns
  204.    FALSE the extended help page is displayed */
  205.         case HM_HELPSUBITEM_NOT_FOUND:
  206.             /* Don't intercept general help */
  207.             if( SHORT1FROMMP( mp1 ) != 1 && SHORT2FROMMP( mp2 ) != 2 )
  208.             {
  209.                 CHAR szOut[ 128 ];
  210.  
  211.                 sprintf(
  212.                     szOut,
  213.                     "IPF Help error.  Topic %lx (subtopic %lx) not found for %s.",
  214.                     (ULONG) SHORT1FROMMP( mp2 ),
  215.                     (ULONG) SHORT2FROMMP( mp2 ),
  216.                     LONGFROMMP( mp1 ) == HLPM_WINDOW ? "application window" :
  217.                         (LONGFROMMP( mp1 ) == HLPM_FRAME ? "frame window" : "menu window" ) );
  218.  
  219.                 WinMessageBox(
  220.                     HWND_DESKTOP,
  221.                     hwnd,
  222.                     szOut,
  223.                     "IPF Editor Demo Program",
  224.                     0,
  225.                     MB_OK | MB_WARNING );
  226.  
  227.                 return (MRESULT) TRUE;
  228.             }
  229.  
  230.             /* For HLPM_WINDOW or HLPM_FRAME return FALSE
  231.                 for no action or TRUE for extended help */
  232.             return (MRESULT) TRUE;
  233.     }
  234.     return (MRESULT) 0L;
  235. }
  236.  
  237.  
  238.