home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / HELPTEST.ZIP / TESTBED.C next >
C/C++ Source or Header  |  1990-09-14  |  10KB  |  353 lines

  1. /* testbed.c  -- Test program */
  2.  
  3. /*
  4.   This test program has been my attempt to demonstrate ways to make the
  5.   Help manager work for me.  My needs are to have more than one "main" window,
  6.   and to have modeless dialog boxes, plus buttons in windows and dialog
  7.   boxes and lots of menus.
  8.  
  9.   The real challenge, and what they don't bother to say in the book, is that
  10.   the ID's for main windows have to be PUT THERE manually.  Then things
  11.   really begin to work well.  The ID of the FRAME window is the key to
  12.   having the help manager figure out what HELPITEM to choose from the
  13.   HELPTABLE, and the ID of the CONTROL window or MENUITEM is used to
  14.   pick a HELPSUBITEM from the HELPSUBTABLE.
  15.  
  16.   I found no way around doing a WinAssociateHelpInstance() call for
  17.   each frame window, though I'm very interested in this.  I tried setting
  18.   the OWNER of the "other" main window to be the "base" window, but then
  19.   I got some strange effects:  When calling up help from the "other"
  20.   window, the help would come up, and then when exited
  21.   the active window would be the base window, even though the focus
  22.   was still on the "other" window.  This looked weird, and was totally
  23.   non-functional.  So I gave in.  Anybody know what I did wrong?
  24.  
  25.   To keep complexity to a minimum, I devised a numbering scheme for
  26.   windows, buttons, menu items, etc. that I could live with.  I re-used
  27.   the same ID for the resources and the Window ID and the help resources.
  28.   This seemed to limit confusion.
  29.  
  30.   The other thing that isn't obvious from what they give you is that 
  31.   in the IPF file you can't (I think!), put constants, only "hard-coded"
  32.   numbers (the bane of a programmer's existence).  So, my advice is to
  33.   get over the revulsion you feel about this and just do it their way.
  34.   (They do talk about ways to call up help panels using string identifiers,
  35.   but that doesn't work for the "automatic" way.
  36.  
  37. */
  38. #define INCL_WIN
  39. #include <os2.h>
  40. #include "testbed.h"
  41.  
  42.  
  43.  
  44. void winpanic( void );
  45.  
  46.  
  47. HAB hab;
  48.  
  49. HWND hwndHelp;
  50. HELPINIT helpinit = {
  51.     sizeof( HELPINIT),
  52.     0L,
  53.     NULL,
  54.     MAKEP(0xFFFF, ID_BASE_RESOURCE),
  55.     0,
  56.     0,
  57.     0,
  58.     0,
  59.     "Help for Testbed Program",
  60.     CMIC_SHOW_PANEL_ID,
  61.     "c:\\test\\testbed.hlp"
  62.     };
  63.  
  64. HWND hwndBaseFrame;
  65. HWND hwndBaseClient;
  66. MRESULT EXPENTRY BaseWndProc( HWND, USHORT, MPARAM, MPARAM);
  67. CHAR szBaseClass[] = "BASE";
  68. ULONG flBaseFrFlags =     FCF_TITLEBAR      | FCF_SYSMENU       |
  69.                           FCF_SIZEBORDER    | FCF_MINMAX        |
  70.                           FCF_SHELLPOSITION | FCF_TASKLIST      |
  71.                           FCF_ICON          | FCF_MENU          ;
  72.  
  73. HWND hwndOtherFrame;
  74. HWND hwndOther;
  75. MRESULT EXPENTRY OtherWndProc( HWND, USHORT, MPARAM, MPARAM);
  76. CHAR szOtherClass[] = "OTHER";
  77. ULONG flOtherFrFlags =    FCF_TITLEBAR      | FCF_SYSMENU       |
  78.                           FCF_SIZEBORDER    | FCF_MINMAX        |
  79.                           FCF_SHELLPOSITION |
  80.                           FCF_ICON          | FCF_MENU          ;
  81.  
  82. MRESULT EXPENTRY Box1DlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  83.  
  84.  
  85. void main(void)
  86. {
  87.   HMQ hmq;
  88.   QMSG qmsg;
  89.   BOOL ef;
  90.   BOOL          winRes;
  91.  
  92.   hab = WinInitialize( 0);
  93.   if (hab==0) winpanic();
  94.   hmq = WinCreateMsgQueue( hab, 50);
  95.   if (hmq==0) winpanic();
  96.  
  97.   hwndHelp = WinCreateHelpInstance( hab, &helpinit);
  98.   if (hwndHelp == NULL) winpanic();
  99.  
  100.   ef = WinRegisterClass ( hab, szBaseClass, BaseWndProc, CS_SIZEREDRAW, 0);
  101.   if (!ef) winpanic();
  102.   hwndBaseFrame = WinCreateStdWindow (  HWND_DESKTOP, WS_VISIBLE,
  103.                                     &flBaseFrFlags, szBaseClass,
  104.                                     " - Testbed Program", 0L,
  105.                                     0, ID_BASE_RESOURCE,
  106.                                     &hwndBaseClient);
  107.   if( hwndBaseFrame==0) winpanic();
  108.   WinSetWindowUShort( hwndBaseFrame, QWS_ID, ID_BASE_RESOURCE);
  109.   winRes = WinAssociateHelpInstance( hwndHelp, hwndBaseFrame);
  110.   if (!winRes) winpanic();
  111.  
  112.   ef = WinRegisterClass( hab, szOtherClass, OtherWndProc, CS_SIZEREDRAW, 0);
  113.   if (!ef) winpanic();
  114.   hwndOtherFrame = WinCreateStdWindow (  HWND_DESKTOP, WS_VISIBLE,
  115.                                     &flOtherFrFlags, szOtherClass,
  116.                                     "Testbed Program -- Other Window", 0L,
  117.                                     0, ID_OTHER_RESOURCE,
  118.                                     &hwndOther);
  119.   if( hwndOtherFrame==0) winpanic();
  120.   WinSetWindowUShort( hwndOtherFrame, QWS_ID, ID_OTHER_RESOURCE);
  121.   //  would have liked to delete these next two lines.  See comment above.
  122.   winRes = WinAssociateHelpInstance( hwndHelp, hwndOtherFrame);
  123.   if (!winRes) winpanic();
  124.  
  125.   while (WinGetMsg( hab, &qmsg, NULL, 0, 0))
  126.     WinDispatchMsg( hab, &qmsg);
  127.  
  128.   ef = WinDestroyWindow( hwndBaseFrame);
  129.   if (!ef) winpanic();
  130.  
  131.   winRes = WinDestroyHelpInstance( hwndHelp);
  132.   if (!winRes) winpanic();
  133.  
  134.   ef = WinDestroyMsgQueue( hmq);
  135.   if (!ef) winpanic();
  136.  
  137.   ef = WinTerminate( hab);
  138.   if (!ef) winpanic();
  139. }
  140.  
  141.  
  142. void winpanic( void )
  143. {
  144.   ERRORID errid;
  145.   ERRINFO *pe;
  146.  
  147.   errid = WinGetLastError(hab);
  148.   pe = WinGetErrorInfo(hab);
  149. }
  150.  
  151.  
  152.  
  153. MRESULT EXPENTRY BaseWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  154. {
  155.   HPS           hps;
  156.   RECTL         rectl;
  157.  
  158.   switch(msg)
  159.     {
  160.   case WM_CREATE:
  161.     return 0;
  162.     break;
  163.  
  164.   case WM_PAINT:
  165.     hps = WinBeginPaint (hwnd, NULL, &rectl);
  166.     WinQueryWindowRect( hwnd, &rectl);
  167.     WinFillRect( hps, &rectl, CLR_WHITE);
  168.     WinDrawText( hps, -1, "Client Window", &rectl,
  169.         CLR_NEUTRAL, CLR_WHITE, DT_CENTER | DT_VCENTER);
  170.     WinEndPaint (hps) ;
  171.     break;
  172.  
  173.   case WM_COMMAND:
  174.     switch (SHORT1FROMMP(mp1) )
  175.       {
  176.     case IDM_BFI_EXIT:
  177.       WinPostMsg( hwnd, WM_CLOSE, 0, 0);
  178.       return 0;
  179.  
  180.     case IDM_ABOUT:
  181.     case IDM_BFI_ABOUT:
  182.       WinMessageBox( HWND_DESKTOP, hwnd,
  183.           "Copyright (c) 1990,  X O Technologies, Inc. ",
  184.           "Testbed Program", 0, MB_OK | MB_ICONASTERISK);
  185.       return 0;
  186.  
  187.     case IDM_HELPFORHELP:
  188.       WinSendMsg( hwndHelp, HM_DISPLAY_HELP, 0L, 0L);
  189.       break;
  190.     case IDM_EXTENDEDHELP:
  191.       WinSendMsg( hwndHelp, HM_EXT_HELP, 0L, 0L);
  192.       break;
  193.     case IDM_KEYSHELP:
  194.       WinSendMsg( hwndHelp, HM_KEYS_HELP, 0L, 0L);
  195.       break;
  196.     case IDM_HELPINDEX:
  197.       WinSendMsg( hwndHelp, HM_HELP_INDEX, 0L, 0L);
  198.       break;
  199.       }
  200.     break;
  201.  
  202.   case WM_HELP:
  203.     break;  /* let the default handle it */
  204.  
  205.   case HM_QUERY_KEYS_HELP:
  206.     return (MRESULT) IDM_KEYSHELP;
  207.  
  208.   case HM_ERROR:
  209.     WinMessageBox( HWND_DESKTOP, hwnd,
  210.           "A Help Manager Error was reported, report to Product Support.",
  211.           "Help Manager Error", 0, MB_OK | MB_ICONEXCLAMATION);
  212.       return 0;
  213.  
  214.   case HM_ACTIONBAR_COMMAND:
  215.     break;
  216.   case HM_EXT_HELP_UNDEFINED:
  217.     break;
  218.   case HM_HELPSUBITEM_NOT_FOUND:
  219.     break;
  220.   case HM_INFORM:
  221.     break;
  222.   case HM_TUTORIAL:
  223.     break;
  224.   case WM_CLOSE:
  225.     break;   /* now let the default handler do its thing */
  226.  
  227.     }
  228.  
  229.   return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  230. }
  231.  
  232.  
  233. MRESULT EXPENTRY OtherWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  234. {
  235.   HPS           hps;
  236.   RECTL         rectl;
  237.  
  238.   switch(msg)
  239.     {
  240.   case WM_CREATE:
  241.     WinCreateWindow( hwnd, WC_BUTTON, "Help",
  242.       WS_VISIBLE | BS_PUSHBUTTON | BS_HELP | BS_NOPOINTERFOCUS,
  243.         10,  10,  80,  25,
  244.       hwnd, HWND_TOP, IDC_BUTTON, NULL, NULL);
  245.     WinCreateWindow( hwnd, WC_BUTTON, "Boop", WS_VISIBLE | BS_PUSHBUTTON,
  246.       110,  10,  80,  25,
  247.       hwnd, HWND_TOP, IDC_BUTTON, NULL, NULL);
  248.     WinCreateWindow( hwnd, WC_BUTTON, "Dialog Box 2", WS_VISIBLE | BS_PUSHBUTTON,
  249.       210,  10,  120,  25,
  250.       hwnd, HWND_TOP, IDC_DIALOGBOX2, NULL, NULL);
  251.     return 0;
  252.     break;
  253.  
  254.   case WM_PAINT:
  255.     hps = WinBeginPaint (hwnd, NULL, &rectl);
  256.     WinQueryWindowRect( hwnd, &rectl);
  257.     WinFillRect( hps, &rectl, CLR_WHITE);
  258.     WinDrawText( hps, -1, "The Other Window", &rectl,
  259.         CLR_NEUTRAL, CLR_WHITE, DT_CENTER | DT_VCENTER);
  260.     WinEndPaint (hps) ;
  261.     break;
  262.  
  263.   case WM_COMMAND:
  264.     switch (SHORT1FROMMP(mp1) )
  265.       {
  266.     case IDM_OT_1:
  267.       DosBeep( 1000, 250);
  268.       return 0;
  269.  
  270.     case IDM_OT_2:
  271.       DosBeep( 2000, 250);
  272.       return 0;
  273.  
  274.     case IDM_OT_3:
  275.       DosBeep( 4000, 250);
  276.       return 0;
  277.  
  278.     case IDM_OS_1:
  279.       DosBeep( 1000, 1250);
  280.       return 0;
  281.  
  282.     case IDM_OS_2:
  283.       DosBeep( 2000, 1250);
  284.       return 0;
  285.  
  286.     case IDM_OS_3:
  287.       DosBeep( 4000, 1250);
  288.       return 0;
  289.  
  290.     case IDC_BUTTON:
  291.       DosBeep( 250, 1250);
  292.       return 0;
  293.  
  294.     case IDM_DIALOGBOX1:
  295.     case IDC_DIALOGBOX2:
  296.       WinDlgBox( HWND_DESKTOP, hwnd, Box1DlgProc, 0, IDD_DIALOGBOX1, NULL);
  297.       return 0;
  298.  
  299.       }
  300.     WinSendMsg( hwndBaseClient, msg, mp1, mp2);  /* any mis-understood WM_COMMANDs
  301.                                                     get bumped back to the base */
  302.     break;
  303.  
  304.   case WM_HELP:
  305.     break;  /* let WinDefWindowProc() handle it */
  306.  
  307.   case HM_QUERY_KEYS_HELP:
  308.     return (MRESULT) IDH_OTHER_KEYSHELP;
  309.  
  310.   case WM_CLOSE:
  311.     break;   /* now let the default handler do its thing */
  312.  
  313.     }
  314.  
  315.   return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  316. }
  317.  
  318. MRESULT EXPENTRY Box1DlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  319. {
  320.   BOOL wr;
  321.  
  322.   switch (msg)
  323.     {
  324.   case WM_INITDLG:
  325.     wr = WinAssociateHelpInstance( hwndHelp, hwnd);
  326.     if ( !wr) winpanic();
  327.     return 0;
  328.  
  329.   case WM_COMMAND:
  330.     switch (COMMANDMSG(&msg)->cmd)
  331.       {
  332.     case DID_SOSO:
  333.       DosBeep( 200, 500);  /* and let fall through */
  334.     case DID_DIALOGBOX1_OK:
  335.       DosBeep( 100, 500);  /* and let fall through */
  336.     case DID_CANCEL:
  337.       WinDismissDlg( hwnd, TRUE);
  338.       return 0;
  339.       }
  340.  
  341.   case WM_HELP:
  342.     break;  /* let WinDefDlgProc() handle it */
  343.  
  344.  
  345.   case WM_CLOSE:
  346.     wr = WinAssociateHelpInstance( hwndHelp, NULL);
  347.     if ( !wr) winpanic();
  348.     break;
  349.     }
  350.   return WinDefDlgProc( hwnd, msg, mp1, mp2);
  351. }
  352.  
  353.