コード例 #1
0
ファイル: main.cpp プロジェクト: iqabsent/cge-lsystem
int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow )
{

	// local
  WNDCLASSEX winClass;
  MSG	uMsg;
	char*	winClassName = "RTVS";

	// initialise message
  memset(&uMsg,0,sizeof(uMsg));

	// init
  winClass.lpszClassName = (LPCWSTR)winClassName;
  winClass.cbSize        = sizeof(WNDCLASSEX);
  winClass.style         = CS_HREDRAW | CS_VREDRAW;
  winClass.lpfnWndProc   = WindowProc;
  winClass.hInstance     = hInstance;
  winClass.hIcon         = NULL;
  winClass.hIconSm       = NULL;
  winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  winClass.lpszMenuName  = NULL;
  winClass.cbClsExtra    = 0;
  winClass.cbWndExtra    = 0;

	// IF register class fails THEN end
  if( !RegisterClassEx(&winClass) ) return E_FAIL;

	// create window
  g_hWnd = CreateWindowEx( NULL, (LPCWSTR)winClassName, 
                           (LPCWSTR)"Willem L-System",
                           WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                           0, 0, 1200, 800, NULL, NULL, hInstance, NULL );

	// IF create window fails THEN end
  if( g_hWnd == NULL ) return E_FAIL;

	// housekeeping
  ShowWindow( g_hWnd, nCmdShow );
  UpdateWindow( g_hWnd );

	// create application
	g_app = new RTVS();

	// non-device one time application setup 
	g_app->setup();

	// non-device one time setup
  setup();

	// device dependent setup
  setupDX();

	// WHILE NOT quit, handle messages and display
  while( uMsg.message != WM_QUIT )
  {
      if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
      { 
          TranslateMessage( &uMsg );
          DispatchMessage( &uMsg );
      }
      else
          display();
  }

	// unregister windows class
  UnregisterClass(
		(LPCWSTR)winClassName,
		winClass.hInstance
  );

  return uMsg.wParam;
}
コード例 #2
0
LRESULT CALLBACK WindowProc( HWND   hWnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam )
{
    static POINT ptLastMousePosit;
    static POINT ptCurrentMousePosit;
    static bool bMousing;
    
    switch( msg )
    {
        case WM_KEYDOWN:
        {
            switch( wParam )
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;

				case VK_F1:
					g_bHandleWindowResize = !g_bHandleWindowResize;
					break;
            }
        }
        break;

        case WM_LBUTTONDOWN:
        {
            ptLastMousePosit.x = ptCurrentMousePosit.x = LOWORD (lParam);
            ptLastMousePosit.y = ptCurrentMousePosit.y = HIWORD (lParam);
            bMousing = true;
        }
        break;

        case WM_LBUTTONUP:
        {
            bMousing = false;
        }
        break;

        case WM_MOUSEMOVE:
        {
            ptCurrentMousePosit.x = LOWORD (lParam);
            ptCurrentMousePosit.y = HIWORD (lParam);

            if( bMousing )
            {
				float spinX, spinY;
				g_app->getSpin (&spinX, &spinY);
                spinX -= (ptCurrentMousePosit.x - ptLastMousePosit.x);
                spinY -= (ptCurrentMousePosit.y - ptLastMousePosit.y);
				g_app->setSpin(spinX, spinY);
            }

            ptLastMousePosit.x = ptCurrentMousePosit.x;
            ptLastMousePosit.y = ptCurrentMousePosit.y;
        }
        break;

        case WM_SIZE:
        {
			if( g_bHandleWindowResize == true )
			{
				// If the device is not NULL and the WM_SIZE message is not a
				// SIZE_MINIMIZED event, resize the device's swap buffers to match
				// the new window size.
				if( g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED )
				{
					cleanupDX();

					g_d3dpp.BackBufferWidth  = LOWORD(lParam);
					g_d3dpp.BackBufferHeight = HIWORD(lParam);

					HRESULT hr = g_pd3dDevice->Reset( &g_d3dpp );

                    if( hr == D3DERR_INVALIDCALL )
                    {
                        MessageBox( NULL,
							"Call to Reset() failed with D3DERR_INVALIDCALL!",
                            "ERROR", MB_OK | MB_ICONEXCLAMATION );
                    }

					setupDX();
				}
			}
        }
        break;

        case WM_CLOSE:
        {
            PostQuitMessage(0); 
        }
        
        case WM_DESTROY:
        {
            PostQuitMessage(0);
        }
        break;

        default:
        {
            return DefWindowProc( hWnd, msg, wParam, lParam );
        }
        break;
    }

	// done
    return 0;
}