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

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