home *** CD-ROM | disk | FTP | other *** search
/ VRML Tools for 3D Cyberspace / VRML_Tools_For_3D_Cyberspace.iso / amber / demos / children / children.cpp next >
C/C++ Source or Header  |  1996-07-01  |  3KB  |  144 lines

  1.  
  2.  
  3. #include <windows.h>
  4.  
  5. #include "amber.hpp"
  6. #include "mouse.hpp"
  7.  
  8. #include "children.h"
  9. #include "resource.h"
  10. #include "demo.hpp"
  11.  
  12. /**************************************************************************\
  13. *
  14. *  function:  WinMain()
  15. *
  16. *  input parameters:  c.f. generic sample
  17. *
  18. \**************************************************************************/
  19. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  20.                          LPSTR lpCmdLine, int nCmdShow)
  21. {
  22.     HANDLE hInst;
  23.     HWND   hwndMain;
  24.     MSG   msg;
  25.  
  26.     UNREFERENCED_PARAMETER( lpCmdLine );
  27.  
  28.  
  29.     /* Check for previous instance.  If none, then register class. */
  30.     if (!hPrevInstance) {
  31.         WNDCLASS  wc;
  32.  
  33.         wc.style = CS_VREDRAW;
  34.         wc.lpfnWndProc = (WNDPROC)MainWndProc;
  35.  
  36.         wc.cbClsExtra = 0;
  37.         wc.cbWndExtra = 0;
  38.         wc.hInstance = hInstance;
  39.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  40.         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  41.           wc.lpszMenuName =  "SIMPLE_MENU";
  42.           wc.lpszClassName = "simple";
  43.  
  44.         if (!RegisterClass(&wc)) return (FALSE);
  45.     }  /* class registered o.k. */
  46.  
  47.  
  48.     /* Create the main window.  Return false if CreateWindow() fails */
  49.     hInst = hInstance;
  50.  
  51.     hwndMain = CreateWindow(
  52.         "simple",
  53.           "Simple",
  54.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  55.         CW_USEDEFAULT,
  56.         CW_USEDEFAULT,
  57.           CW_USEDEFAULT,
  58.           CW_USEDEFAULT,
  59.         NULL,
  60.         NULL,
  61.         hInstance,
  62.         NULL);
  63.  
  64.     if (!hwndMain) return (FALSE);
  65.     ShowWindow(hwndMain, nCmdShow);
  66.     UpdateWindow(hwndMain);
  67.  
  68.  
  69.     /* Loop getting messages and dispatching them. */
  70.     while (GetMessage(&msg,NULL, 0,0)) {
  71.         TranslateMessage(&msg);
  72.           DispatchMessage(&msg);
  73.      }
  74.  
  75.     return (msg.wParam);
  76. }
  77.  
  78.  
  79. LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  80. {
  81. static channelClass *ch;
  82. universeClass *univ;
  83. static mouseClass *mouse;
  84. V3 pos;
  85.  
  86.   switch (message) {
  87.  
  88.  
  89.      /**********************************************************************\
  90.      *  WM_CREATE
  91.      *
  92.      * Initialize the static variables.
  93.      *  Then create three pens for drawing with later.
  94.      \**********************************************************************/
  95.      case WM_CREATE:
  96.           amber = new amberClass();
  97.           univ = new universeClass();
  98.           ch = new channelClass(hwnd);
  99.           V3_set(pos, 0.0, 0.0, 10.0);
  100.           ch->setPosition(pos);
  101.           mouse = new mouseClass(hwnd);
  102.           mouse->attachChannel(ch);
  103.           init(ch);
  104.      break;
  105.  
  106.  
  107.     /**********************************************************************\
  108.      *  WM_DESTROY
  109.      *
  110.      * Complement of the WM_CREATE message.  Delete the pens that were
  111.      *  created and then call postquitmessage.
  112.      \**********************************************************************/
  113.      case WM_DESTROY:
  114.         cleanup();
  115.         delete mouse;
  116.         delete amber;
  117.         PostQuitMessage(0);
  118.      break;
  119.  
  120.     case WM_KEYDOWN:
  121.         processChar(wParam);
  122.         break;
  123.  
  124.     case WM_SIZE:
  125.         if (!ch || !IsWindowVisible(hwnd)) break;
  126.         ch->resetPerspective();
  127.         break;
  128.  
  129.     case WM_COMMAND:  // message: command from application menu
  130.         switch(wParam)
  131.         {
  132.             case ID_PROGRAM_EXIT:
  133.                 cleanup();
  134.                 delete mouse;
  135.                 delete amber;
  136.                 PostQuitMessage(0);
  137.                 break;
  138.         }
  139.         break;
  140.  
  141.   } /* end switch */
  142.   return (DefWindowProc(hwnd, message, wParam, lParam));
  143. }
  144.