home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lrcs30.zip / examples.zip / LHELLO.C < prev    next >
C/C++ Source or Header  |  1994-05-15  |  6KB  |  197 lines

  1. //******************************************************************************
  2. // LHELLO.C
  3. //
  4. // LARC_S "LARC Examples"
  5. // LARC_D "LARC Example Windows-based 'Hello' Program"
  6. // LARC_V "100"
  7. //
  8. // Revision history:
  9. // kbg 03/12/94 100 - Created.
  10. //
  11. //******************************************************************************
  12.  
  13. #include <windows.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "lhello.h"
  17.  
  18. //******************************************************************************
  19. //
  20. // Windows Main Routine
  21. //
  22. //******************************************************************************
  23. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  24.     {
  25.     MSG         msg;
  26.     HANDLE      hAccel;
  27.  
  28.     hInst = hInstance;
  29.  
  30.     if (hPrevInstance)
  31.         {
  32.         MessageBox (NULL, "LARC 'Hello' is already running on your system!", "WARNING", MB_OK | MB_TASKMODAL);
  33.         return (FALSE);
  34.         }
  35.  
  36.     if (!SetUpWindowClass (hInstance))
  37.         return (FALSE);
  38.  
  39.     hWndMain = CreateWindow (szAppName, "LARC Hello Example",
  40.                 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_MAXIMIZE,
  41.                 0, 0, CW_USEDEFAULT, CW_USEDEFAULT,
  42.                 NULL, NULL, hInstance, NULL);
  43.  
  44.     ShowWindow (hWndMain, nCmdShow);
  45.     UpdateWindow (hWndMain);
  46.  
  47.     hAccel = LoadAccelerators( hInst, szAppName);
  48.     if (hAccel == NULL)
  49.         {
  50.         MessageBox (NULL, "Load Accellerators Failed", "WARNING", MB_OK | MB_TASKMODAL);
  51.         return( FALSE);
  52.         }
  53.  
  54.     while (GetMessage (&msg, NULL, 0, 0))
  55.         {
  56.         if (!TranslateAccelerator( hWndMain, hAccel, &msg))
  57.             {
  58.             TranslateMessage( &msg);
  59.             DispatchMessage( &msg);
  60.             }
  61.         }
  62.  
  63.     return msg.wParam;
  64.     }
  65.  
  66. //==============================================================================
  67. //
  68. // FUNCTION:    SetUpWindowClass ()
  69. //
  70. // PURPOSE:     Register the window classes used by this program.
  71. //
  72. // RETURNS:     TRUE    - classes registered OK.
  73. //              FALSE   - class registration failed.
  74. //
  75. //==============================================================================
  76. BOOL SetUpWindowClass( HANDLE hInstance )
  77.     {
  78.     WNDCLASS  wc;
  79.  
  80.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  81.     wc.lpfnWndProc   = WndProc;
  82.     wc.cbClsExtra    = 0;
  83.     wc.cbWndExtra    = 0;
  84.     wc.hInstance     = hInstance;
  85.     wc.hIcon         = LoadIcon (hInstance, szAppName);
  86.     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
  87.     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  88.     wc.lpszMenuName  = szAppName;
  89.     wc.lpszClassName = szAppName;
  90.       
  91.     return (RegisterClass (&wc));
  92.     }
  93.  
  94. //==============================================================================
  95. //
  96. // FUNCTION:    WndProc (hWnd, iMessage, wParam, lParam)
  97. //
  98. // PURPOSE:     Handle messages for main window.
  99. //
  100. //==============================================================================
  101. long FAR PASCAL WndProc( HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam )
  102.     {
  103.     DLGPROC  lpfnDlgProc;
  104.  
  105.     switch (iMessage)
  106.         {
  107.         case WM_CREATE:
  108.             SendMessage (hWnd, WM_USER+1, 0, 0L);
  109.             break;
  110.  
  111.         case WM_USER+1:
  112.             PostMessage (hWnd, WM_COMMAND, IDM_ABOUT, 0L);
  113.             break;
  114.  
  115.         case WM_COMMAND:
  116.             switch (wParam)
  117.                 {
  118.                 case IDM_EXIT:
  119.                     SendMessage (hWnd, WM_CLOSE, 0, 0L);
  120.                     break;
  121.  
  122.                 case IDM_ABOUT:
  123.                     lpfnDlgProc = (DLGPROC)MakeProcInstance((FARPROC)AboutProc, hInst);
  124.                     if (DialogBox (hInst, "ABOUTLHELLO", hWnd, lpfnDlgProc) < 0)
  125.                         MessageBox (NULL, "About LARC Hello Dialog Box Load Failed", "WARNING", MB_OK | MB_TASKMODAL);
  126.                     FreeProcInstance((FARPROC)lpfnDlgProc);
  127.                     break;
  128.  
  129.                 default:
  130.                     return((LONG) DefWindowProc (hWnd, iMessage, wParam, lParam));
  131.                     break;
  132.                 }
  133.             break;
  134.  
  135.         case WM_CLOSE:
  136.             DestroyWindow( hWnd );
  137.             break;
  138.  
  139.         case WM_DESTROY:
  140.             PostQuitMessage (0);
  141.             break;
  142.  
  143.         default:
  144.             return((LONG) DefWindowProc (hWnd, iMessage, wParam, lParam));
  145.         }
  146.  
  147.     return 0L;
  148.     }
  149.  
  150. //==============================================================================
  151. //
  152. // FUNCTION:  AboutProc ( )
  153. //
  154. // PURPOSE:   Function to display and process the WinLarc "about box".
  155. //
  156. //==============================================================================
  157. BOOL FAR PASCAL AboutProc (HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  158.     {
  159.     char szBuffer[50];
  160.  
  161.     switch (iMessage)
  162.         {
  163.         case WM_INITDIALOG:
  164.             GetDlgItemText (hDlg, IDD_VERSION, szBuffer, sizeof(szBuffer));
  165.             if (lstrlen(szBuffer) + lstrlen(szVersion) < sizeof(szBuffer))
  166.                 lstrcat (szBuffer, szVersion);
  167.             SetDlgItemText (hDlg, IDD_VERSION, szBuffer);
  168.            break;
  169.  
  170.         case WM_COMMAND:
  171.             switch (wParam)
  172.                 {
  173.                 case IDOK:
  174.                     EndDialog (hDlg, IDOK);
  175.                     break;
  176.  
  177.                 case IDCANCEL:
  178.                     EndDialog (hDlg, IDOK);
  179.                     break;
  180.  
  181.                 default:
  182.                     return (FALSE);
  183.                 }
  184.             break;
  185.  
  186.         case WM_DESTROY:
  187.             break;
  188.  
  189.         default:
  190.             return (FALSE);
  191.         }
  192.  
  193.     return (TRUE);
  194.     }
  195.  
  196. /* END */
  197.