home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / OWLHELP.ZIP / OWLHELP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.0 KB  |  150 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2. //
  3. // owlhelp.cpp
  4.  
  5. /* -------------------------------------------------------------
  6.  This is an example of an application which implements context
  7.  sensitive help for menu choices.  To use the application, hit
  8.  F1 when a menu item is highlighted.  The program checks for F1
  9.  being down in the WM_ENTERIDLE message.  If it is down, it sets
  10.  a flag and simulates the selection of the menu item.  The help
  11.  is then shown in the command message for that menu item.
  12.  When the command is received, we just check to see if the flag
  13.  has been set which indicates that the user wants help on the command.
  14.  ---------------------------------------------------------------- */
  15.  
  16. #include <owl.h>
  17.  
  18. #include "owlhelpm.h"
  19. #include "owlhelpr.h"
  20.  
  21. #include "owlhelp.h"
  22.  
  23. TOWLHELPApp::TOWLHELPApp( LPSTR lpszNam, HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLn, int nCmdShw )
  24.     : TApplication( lpszNam, hInst, hPrevInst, lpszCmdLn, nCmdShw )
  25. {
  26. }
  27.  
  28. void TOWLHELPApp::InitInstance()
  29. {
  30.     TApplication::InitInstance();
  31.     HAccTable = LoadAccelerators( hInstance, MAKEINTRESOURCE( OWLHELPAPACCEL ) );
  32. }
  33.  
  34. void TOWLHELPApp::InitMainWindow()
  35. {
  36.     MainWindow = new TOWLHELPWnd( NULL, "OWL Help Example" );
  37. }
  38.  
  39. TOWLHELPWnd::TOWLHELPWnd( PTWindowsObject AParent, LPSTR ATitle )
  40.     : TWindow( AParent, ATitle )
  41. {
  42. }
  43.  
  44. LPSTR lpszClientAreaText = "To Get help, press F1 while a menu item is \
  45. highlighted.  WinHelp will be called to show help on that topic.  If help \
  46. is not shown, it is because the mouse button is pressed.  Release the \
  47. mouse button to see help.";
  48.  
  49.  
  50. void TOWLHELPWnd::Paint( HDC hdc, PAINTSTRUCT _FAR &)
  51. {
  52.     RECT rectClient;
  53.     GetClientRect( HWindow , &rectClient );
  54.  
  55.     int nWidth = rectClient.right;        // rectClient.left is 0
  56.     int nHeight = rectClient.bottom;    // rectClient.top is 0
  57.  
  58.     rectClient.left += (nWidth / 4);
  59.     rectClient.top  += (nHeight / 4);
  60.     rectClient.right -= (nWidth / 4);
  61.  
  62.     SetBkMode( hdc, TRANSPARENT );
  63.     DrawText( hdc, lpszClientAreaText, lstrlen( lpszClientAreaText ),
  64.         &rectClient, DT_CENTER | DT_VCENTER | DT_WORDBREAK );
  65. }
  66.  
  67. void TOWLHELPWnd::GetWindowClass( WNDCLASS &AWndClass )
  68. {
  69.     TWindow::GetWindowClass( AWndClass );
  70.     AWndClass.lpszMenuName = MAKEINTRESOURCE( OWLHELPAPMENU );
  71. }
  72.  
  73. LPSTR TOWLHELPWnd::GetClassName()
  74. {
  75.     return "TOWLHELPWnd";
  76. }
  77.  
  78. void TOWLHELPWnd::SetupWindow()
  79. {
  80.     tfF1Pressed = FALSE;
  81. }
  82.  
  83. void TOWLHELPWnd::WMEnterIdle( RTMessage Msg )
  84. {
  85.     if( (Msg.WParam == MSGF_MENU ) && ((GetKeyState( VK_F1 ) & 0x8000) != 0) )
  86.         // if the high bit is set, then the key is pressed
  87.     {
  88.         tfF1Pressed = TRUE;
  89.         PostMessage( HWindow, WM_KEYDOWN, VK_RETURN, 0L );
  90.     }
  91. }
  92.  
  93. void TOWLHELPWnd::CMUMenuItemA( RTMessage )
  94. {
  95.     if( tfF1Pressed == TRUE )
  96.     {
  97.         WinHelp( HWindow, "OWLHELP.HLP", HELP_CONTEXT, HELP_MENUITEMA );
  98.         tfF1Pressed = FALSE;
  99.     } else {
  100.         MessageBox( HWindow, "In Menu Item A command", Title, MB_ICONINFORMATION );
  101.     }
  102. }
  103.  
  104. void TOWLHELPWnd::CMUMenuItemB( RTMessage )
  105. {
  106.     if( tfF1Pressed == TRUE )
  107.     {
  108.         WinHelp( HWindow, "OWLHELP.HLP", HELP_CONTEXT, HELP_MENUITEMB );
  109.         tfF1Pressed = FALSE;
  110.     } else {
  111.         MessageBox( HWindow, "In Menu Item B Command", Title, MB_ICONINFORMATION );
  112.     }
  113. }
  114.  
  115. void TOWLHELPWnd::CMExit( RTMessage Msg )
  116. {
  117.     if ( tfF1Pressed == TRUE )
  118.     {
  119.         WinHelp( HWindow, "OWLHELP.HLP", HELP_CONTEXT, HELP_EXIT );
  120.         tfF1Pressed = FALSE;
  121.     } else {
  122.         TWindow::CMExit( Msg );
  123.     }
  124. }
  125.  
  126. void TOWLHELPWnd::CMUHelpIndex( RTMessage )
  127. {
  128.     WinHelp( HWindow, "OWLHELP.HLP", HELP_INDEX, 0L );
  129. }
  130.  
  131. void TOWLHELPWnd::CMUHelpHelp( RTMessage )
  132. {
  133.     WinHelp( HWindow, "WINHELP.HLP", HELP_HELPONHELP, 0L );
  134. }
  135.  
  136. void TOWLHELPWnd::CMUHelpAbout( RTMessage )
  137. {
  138.         MessageBox( HWindow, "OWLHELP\nWritten using ObjectWindows\nCopyright (c) 1992 Borland",
  139.         "About OWLHELP", MB_ICONINFORMATION );
  140. }
  141.  
  142. int PASCAL WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLn, int nCmdShw )
  143. {
  144.     TOWLHELPApp App( "OWLHELPAP", hInst, hPrevInst, lpszCmdLn, nCmdShw );
  145.  
  146.     App.Run();
  147.     return App.Status;
  148. }
  149.  
  150.