home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_09 / 1109064a < prev    next >
Text File  |  1993-07-08  |  9KB  |  208 lines

  1. /*                                                                                          */
  2. //  NAME = HELPDEMO.C    
  3. //  Turbo C++ version of a Windows program to demonstrate how
  4. //  to call the Microsoft Help Engine, WINHELP.EXE.  This
  5. //  program creates a window w/menu bar having two options -
  6. //  Exit and Help.  Click on Help to activate the sample help file
  7. //  using WINHELP.
  8. //  Programmers:  Keith E. Bugg and Jack Tackett
  9. //
  10.  
  11. #include "helpdemo.h"
  12. #include "context.h"        // indices for help subjects
  13. long FAR PASCAL _export DemoProc(HWND hWnd, 
  14. WORD message, WORD wParam, LONG lParam)
  15. {
  16.         
  17.         switch (message)         // process messages here
  18.         {
  19.                 case WM_PAINT:              // message to update screen
  20.                         dopaint(hWnd);             // function to repaint screen
  21.                         break;
  22.  
  23.  
  24.                 case WM_KEYDOWN:    // trap F1 function key
  25.                         switch(wParam)
  26.                         {
  27.                                 case VK_F1: // go to main index
  28.                                         WinHelp(hWnd,"HELPDEMO.HLP", HELP_CONTENTS,0);
  29.                                         break;
  30.                                 default:
  31.                                         break;
  32.                         }
  33.                         break;
  34.  
  35.         case WM_COMMAND:    // check for system message
  36.                 switch(wParam)
  37.                 {
  38.                         case GEN_EXIT:      // Exit from Menu bar
  39.                            PostQuitMessage(0);
  40.                            break;
  41.  
  42.                 case SC_MINIMIZE:   
  43.                          // system menu click on minimize
  44.                         ShowWindow(hWnd,SW_SHOWMINIMIZED);
  45.                         break;
  46.  
  47.                 case SC_MAXIMIZE:   
  48.                         // system menu click on maximize
  49.                         ShowWindow(hWnd,SW_SHOWMAXIMIZED);
  50.                         break;
  51.  
  52.                 case SC_RESTORE:    
  53.                         // system menu click on restore
  54.                                 ShowWindow(hWnd,SW_SHOW);
  55.                                 break;
  56.  
  57.                         //
  58.                         //  this case brings up the table of contents
  59.                         //
  60.  
  61.                 case HELP_TOPICS:
  62.                         WinHelp(hWnd,"HELPDEMO.HLP", HELP_CONTENTS,0);
  63.                                                 break;
  64.                         //
  65.                         //  next cases are for specific topics
  66.                         //
  67.                 case HELP_MERCURY:
  68.                         WinHelp(hWnd,"HELPDEMO.HLP",HELP_CONTEXT,GO_MERCURY);
  69.                         break;
  70.  
  71.                 case HELP_VENUS:
  72.                         WinHelp(hWnd,"HELPDEMO.HLP",HELP_CONTEXT,GO_VENUS);
  73.                         break;
  74.  
  75.                 case HELP_EARTH:
  76.                         WinHelp(hWnd,"HELPDEMO.HLP",HELP_CONTEXT,GO_EARTH);
  77.                         break;
  78.  
  79.                 case HELP_MARS:
  80.                         WinHelp(hWnd,"HELPDEMO.HLP",HELP_CONTEXT,GO_MARS);
  81.                         break;
  82.  
  83.                 default:
  84.                         break;
  85.                 }
  86.                 break;
  87.                 
  88.                 case WM_CLOSE:     // User wants to Exit via sys menu
  89.                 case WM_QUIT:       // QUIT & DESTROY messages 
  90.                 case WM_DESTROY:
  91.                          PostQuitMessage(0);
  92.                          break;
  93.  
  94.                 default:            // message of no interest to program..
  95.                          return (DefWindowProc(hWnd, message, 
  96.                            wParam, lParam));
  97.         }               // end switch on all messages
  98.  
  99.         return (NULL);
  100. }       /* end MainWndProc()    */
  101.  
  102. #pragma argsused        // TURBO C++ pragma
  103. /**************************************************************/
  104. int PASCAL WinMain(HINSTANCE hInstance, 
  105.         HINSTANCE hPrevInstance,  LPSTR lpCmdLine,
  106.          int nCmdShow)
  107. {
  108.         
  109.          WNDCLASS  wc;
  110.          static HWND hWnd;
  111.          MSG msg;
  112.         
  113.         if (!hPrevInstance) // Other instances of app running?
  114.         {
  115.                 // Fill in window class structure with parameters that 
  116.                 // describe the main window.
  117.  
  118.                 wc.style = CS_HREDRAW | CS_VREDRAW  ;   // Class style(s).
  119.                 //  Declare function to retrieve messages for this class
  120.                 wc.lpfnWndProc = (long (FAR PASCAL*)())DemoProc;
  121.  
  122.                 wc.cbClsExtra = 0;          // No per-class extra data.
  123.                 wc.cbWndExtra = 0;          // No per-window extra data.
  124.                 wc.hInstance = hInstance;   // Application that owns the class.
  125.                 wc.hIcon = LoadIcon(hInstance, "HELPDEMO");
  126.                 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  127.                 //
  128.                 // create a cyan background
  129.                 //
  130.                 wc.hbrBackground = CreateSolidBrush(RGB(100,255,255)); 
  131.  
  132.                 wc.lpszMenuName = "mainmenu";
  133.                 wc.lpszClassName = "HELPDEMO";    // Name used for CreateWindow()
  134.  
  135.                 /* Register the window class and return success/failure code. */
  136.  
  137.                 if(!RegisterClass(&wc))
  138.                         return 0;                   // FAILED TO REGISTER!!
  139.  
  140.                 /* Create a main window for this application instance.  */
  141.  
  142.                 hWnd = CreateWindow(
  143.                         "HELPDEMO",               // See RegisterClass() call.
  144.                         "HELPDEMO Development",   // Text for window title bar.
  145.                         WS_MAXIMIZE | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME
  146.                         | WS_SYSMENU | WS_OVERLAPPEDWINDOW,   // Window style.
  147.                         0,                      // Default horizontal position.
  148.                         0,                      // Default vertical position.
  149.                         600,                    // Default width.
  150.                         400,                    // Default height.
  151.                         NULL,                   // Overlapped windows have no parent.
  152.                         NULL,                   // No menu bar
  153.                         hInstance,              // This instance owns this window.
  154.                         NULL                    // Pointer not needed.
  155.                         );               
  156.  
  157.                 if (!hWnd)   /* If window could not be created, return "failure" */
  158.                 {        
  159.                         MessageBeep(0);
  160.                         MessageBox(hWnd,"Could not create window!","ERROR",MB_OK);
  161.                         return 0;
  162.                 }
  163.         
  164.  
  165.                 /* Make the window visible; update its client area   */
  166.  
  167.                 nCmdShow= SW_SHOWNORMAL;     // Show window normal MAX size
  168.                 ShowWindow(hWnd,nCmdShow ); // Show the window
  169.                 UpdateWindow(hWnd);         // Sends WM_PAINT message
  170.                 
  171.         }
  172.         /* Acquire and dispatch messages until a WM_QUIT message is received. */
  173.  
  174.         while (GetMessage(&msg, // message structure
  175.                 NULL,               // handle of window receiving the message
  176.                 NULL,               // lowest message to examine
  177.                 NULL))              // highest message to examine
  178.         {
  179.                 TranslateMessage(&msg); // Translates virtual key codes
  180.                 DispatchMessage(&msg);  // Dispatches message to window
  181.         }
  182.         return (msg.wParam);    // Returns the value from PostQuitMessage
  183.  
  184. }               /* end WinMain()    */
  185.  
  186. void dopaint(HWND hWnd)         // handles any Windows PAINT messages
  187. {
  188.         PAINTSTRUCT ps;             // Paint Struct for BeginPaint call
  189.         HDC hDC;
  190.  
  191.         BeginPaint(hWnd,&ps);
  192.         hDC= GetDC(hWnd);           // get handle to display context
  193.                 
  194.         SetBkMode(hDC,TRANSPARENT);
  195.         SetTextColor(hDC,RGB(0,0,0));       /* write instructions in black  */
  196.         TextOut(hDC,100,310,
  197.                 "Click on Help to see a demonstration of WINHELP.EXE...",54 
  198. );
  199.  
  200.         EndPaint(hWnd,&ps);                 // END OF THE PAINT PROCEDURE
  201.         ReleaseDC(hWnd,hDC);                // release the Display Context
  202.  
  203. }       // end dopaint()
  204.  
  205. //
  206. //  end HELPDEMO.c
  207. //
  208.