/** On window message */
LRESULT RTweakBar::OnWindowMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if(IsActive)
		return TwEventWin(hWnd, msg, wParam, lParam);

	return true;
}
Beispiel #2
0
LRESULT
RenderWindow::callback (HWND window, 
                        UINT msg, 
                        WPARAM wParam, 
                        LPARAM lParam)
{
    if (windowHandle() == nullptr)
        return Window::callback (window, msg, wParam, lParam);
    // Send event message to AntTweakBar
    if (TwEventWin(window, msg, wParam, lParam))
    {
        _rendererHasFocus = false;
        return 0; // Event has been handled by AntTweakBar
    }


    if (msg >= WM_MOUSEFIRST &&
        msg <= WM_MBUTTONDBLCLK)
    {
        _rendererHasFocus = true;
    }

    switch (msg)
    {
        case WM_KEYDOWN:
            if(wParam == VK_ESCAPE)
                DestroyWindow(window);
            break;    
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
    }
    return Window::callback (window, msg, wParam, lParam);
}
// Win32 MessageProc callback
LRESULT CALLBACK MessageProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    // Send event message to AntTweakBar
    if( TwEventWin(wnd, msg, wParam, lParam) )
        return 0;   // Event has been handled by AntTweakBar

    switch( msg )
    {
    case WM_CHAR:       
        if( wParam==VK_ESCAPE )
            PostQuitMessage(0);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    case WM_SIZE:   // Window size has been changed
        // Reset D3D device
        if( g_D3DDev )
        {
            g_D3Dpp.BackBufferWidth  = LOWORD(lParam);
            g_D3Dpp.BackBufferHeight = HIWORD(lParam);
            if( g_D3Dpp.BackBufferWidth>0 && g_D3Dpp.BackBufferHeight>0 )
            {
                g_D3DDev->Reset(&g_D3Dpp);
                InitD3D();  // re-initialize D3D states
            }
            // TwWindowSize has been called by TwEventWin32, 
            // so it is not necessary to call it again here.
        }
        return 0;
    default:
        return DefWindowProc(wnd, msg, wParam, lParam);
    }
}
    virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        (void) hWnd;
        (void) uMsg;
        (void) wParam;
        (void) lParam;

        if(TwEventWin(hWnd, uMsg, wParam, lParam))
        {
            return 0; // Event has been handled by AntTweakBar
        }

        this->camera->HandleMessages( hWnd, uMsg, wParam, lParam );

        if(uMsg == WM_KEYDOWN)
        {
            int iKeyPressed = static_cast<int>(wParam);
            switch( iKeyPressed )
            {
            case VK_TAB:
                g_bRenderHUD = !g_bRenderHUD;
                return 0;
                break;

            case VK_F1:
                PerfTracker::ui_toggle_visibility();
                break;

            default:
                break;
            }
        }
        return 1;
    }
Beispiel #5
0
// windows procedure
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  // send event message to AntTweakBar
  if(TwEventWin(hWnd, uMsg, wParam, lParam))
    return 0; 

  switch(uMsg)
  {
  // prevent activation of screen saver/ turning monitor off
  case WM_SYSCOMMAND:
    {
      switch(wParam)
      {
      case SC_SCREENSAVE: 
      case SC_MONITORPOWER: 
        return 0;
      }
      break;
    }

  // post quit message, when user tries to close window
  case WM_CLOSE:
    {
      PostQuitMessage(0);
      return 0;
    }
  }

  if(Demo::inputManager->GetInputMessages(uMsg, wParam))
    return 0;

  return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // Send event message to AntTweakBar
    if (TwEventWin(hWnd, message, wParam, lParam))
        return 0; // Event has been handled by AntTweakBar

    float newPos;
    switch(message)
    {
        case WM_KEYDOWN:
        {
            if( wParam == VK_ESCAPE )
                DestroyWindow(hWnd);
            return 0;
        }
        case WM_MOUSEWHEEL:
            newPos = GET_WHEEL_DELTA_WPARAM(wParam);
            MOUSEWHEELDELTA = newPos;/* / -WHEEL_DELTA*/;
        break;
        case WM_DESTROY:
        {
                PostQuitMessage(0);
                return 0;
        } 
        break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}
Beispiel #7
0
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	if (TwEventWin(hWnd, message, wParam, lParam)) // send event message to AntTweakBar
		return 0; 

	switch (message) 
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;		
	case WM_KEYDOWN:
		break;
		//switch (wParam)
		//{
		////case VK_ESCAPE:

		////	#ifdef _DEBUG // This button function only works in debug mode. 
		////		PostQuitMessage(0);
		////	#endif
		////	break;
		//default:
		//	break;
		//}

	
	}

	// if we do not handle the message here, simply call the Default handler function
	return DefWindowProc(hWnd, message, wParam, lParam);
}
HRESULT CALLBACK HookWindowProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
	// Send event message to AntTweakBar
    if( TwEventWin(hWnd, msg, wParam, lParam) ){
        return 0;   // Event has been handled by AntTweakBar
	}

	return oldWndProc(hWnd,msg,wParam,lParam);
}
LRESULT PBRDemo::MsgProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam) {
	// Send event message to AntTweakBar
	if (TwEventWin(hwnd, msg, wParam, lParam)) {
		return 0;    // Event has been handled by AntTweakBar
	}

	// Let the base engine handle any events that we don't handle
	return Engine::HalflingEngine::MsgProc(hwnd, msg, wParam, lParam);
}
Beispiel #10
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    //if(Globals::Get().inputManager.HandleWindowInputMsg(msg, wParam, lParam))  return true;

     if (TwEventWin(hwnd, msg, wParam, lParam))
        return 0; 

    switch( msg )
    {
        //case WM_INPUT:  // raw input msg
        //{
         //   Globals::Get().inputManager.HandleRawInput(lParam);
        //}
        case WM_SIZE:
        {
            Globals::Get().app.OnWmSize(lParam); 
        }
            return 0;
        case WM_MOVE:
            {
                Globals::Get().app.OnWmMove(lParam); 
            }
            return 0;
        case WM_ACTIVATEAPP:
            if (wParam)
                Globals::Get().app.OnFocusGain();
            else
                Globals::Get().app.OnFocusLost();

            return 0;
        case WM_CLOSE:
            {
                SetEvent(g_closeHandlerRawWnd);
                PostQuitMessage(0);
            }
            return 0;
        case WM_CREATE:
            {
                g_closeHandlerRawWnd = CreateEvent(0, 1, 0, 0);
                CreateThread(0, 0, &RawThread, (LPVOID) g_closeHandlerRawWnd, 0, &g_rawThreadId);
            }
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK Window::WindowProc(HWND Handle, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
	TwEventWin(Handle,msg,wParam,lParam);

	switch (msg)
	{
		case WM_SYSCOMMAND:
			{
				if (wParam == SC_CLOSE)
				{
					PostMessage(Handle,WM_DESTROY,0,0);
				}
				break;
			}

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

		case WM_MOUSEWHEEL:
			{
				if(lcMouse::Get())
					lcMouse::Get()->m_uiScrollVal = GET_WHEEL_DELTA_WPARAM(wParam);
				break;
			}

		case WM_DROPFILES:
			{
				HDROP hDrop = (HDROP)wParam;
				int iFileCount = DragQueryFile(hDrop,0xFFFFFFFF, nullptr, MAX_PATH);
				for(int i = 0;i < iFileCount;++i)
				{
					char a_szFileDir[256];
					DragQueryFile(hDrop,i,a_szFileDir,MAX_PATH);
					m_pSingleton->OnDropFile(a_szFileDir);
				}
				DragFinish(hDrop);
				break;
			}

		default:
			return DefWindowProc(Handle,msg,wParam,lParam);
	};

	return 0;
}
Beispiel #12
0
// Called every time the application receives a message
LRESULT CALLBACK DxApp::MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
	assert (_instance);

	if( TwEventWin(wnd, message, wParam, lParam) ) // send event message to AntTweakBar
        return 0; // event has been handled by AntTweakBar

	switch (message) 
	{
		case WM_SIZE: 
			_instance->onResize(LOWORD(lParam), HIWORD(lParam));
			return 0;

		case WM_CHAR:
			if (wParam == VK_ESCAPE)
				PostQuitMessage(0);
			return 0;

		case WM_KEYDOWN:
			if (wParam == VK_ESCAPE) {
				PostQuitMessage(0);
				return 0;
			}
			_instance->onKey(wParam);
			break;

		case WM_LBUTTONDOWN:
			_instance->onLButtonDown();
			break; 

		case WM_LBUTTONUP:
			_instance->onLButtonUp();
			break; 

		case WM_MOUSEMOVE:
			_instance->onMouseMove(lParam);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;

		default:
			return DefWindowProc(wnd, message, wParam, lParam);
	}

	return (DefWindowProc(wnd, message, wParam, lParam));
}
Beispiel #13
0
//--------------------------------------------------------------------------------------
// Called every time the application receives a message
//--------------------------------------------------------------------------------------
LRESULT CALLBACK CScene::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	PAINTSTRUCT ps;
	HDC hdc;
	if( TwEventWin( hWnd, message, wParam, lParam ) ) // send event message to AntTweakBar
		return 0; // event has been handled by AntTweakBar
	switch( message )
	{
		case WM_PAINT:
			hdc = BeginPaint( hWnd, &ps );
			EndPaint( hWnd, &ps );
			break;

		case WM_DESTROY:
			PostQuitMessage( 0 );
			break;

		// These windows messages (WM_KEYXXXX) can be used to get keyboard input to the window
		// This application has added some simple functions (not DirectX) to process these messages (all in Input.cpp/h)
		case WM_KEYDOWN:
			KeyDownEvent( static_cast<EKeyState>(wParam) );
			break;

		case WM_KEYUP:
			KeyUpEvent( static_cast<EKeyState>(wParam) );
			break;
		// catch window resize
		case WM_SIZE:
			RECT rc;
			GetClientRect( hWnd, &rc );
			mViewportWidth = rc.right - rc.left;
			mViewportHeight = rc.bottom - rc.top;
			// pass to camera
			CCamera::SetViewport( mViewportWidth, mViewportHeight );
			break;
		default:
			return DefWindowProc( hWnd, message, wParam, lParam );
	}

	return 0;
}
TW_EXPORT_API int TW_CALL TwEventWin32(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam)
{
    return TwEventWin(wnd, msg, wParam, lParam);
}
Beispiel #15
0
void TweakBar::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	TwEventWin(hWnd, uMsg, wParam, lParam);
}
// Called every time the application receives a message
LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // Send event message to AntTweakBar
    if (TwEventWin(wnd, message, wParam, lParam))
        return 0; // Event has been handled by AntTweakBar

    switch (message) 
    {
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                BeginPaint(wnd, &ps);
                EndPaint(wnd, &ps);
                return 0;
            }
        case WM_SIZE: // Window size has been changed
            if (g_D3DDev) // Resize D3D render target
            {
                // Release render target and depth-stencil view
                ID3D11RenderTargetView *nullRTV = NULL;
                g_D3DDevCtx->OMSetRenderTargets(1, &nullRTV, NULL);
                if (g_RenderTargetView)
                {
                    g_RenderTargetView->Release();
                    g_RenderTargetView = NULL;
                }
                if (g_DepthStencilView)
                {
                    g_DepthStencilView->Release();
                    g_DepthStencilView = NULL;
                }

                if (g_SwapChain)
                {
                    // Resize swap chain
                    g_SwapChainDesc.BufferDesc.Width = LOWORD(lParam);
                    g_SwapChainDesc.BufferDesc.Height = HIWORD(lParam);
                    g_SwapChain->ResizeBuffers(g_SwapChainDesc.BufferCount, g_SwapChainDesc.BufferDesc.Width, 
                                               g_SwapChainDesc.BufferDesc.Height, g_SwapChainDesc.BufferDesc.Format, 
                                               g_SwapChainDesc.Flags);

                    // Re-create a render target and depth-stencil view
                    ID3D11Texture2D *backBuffer = NULL, *dsBuffer = NULL;
                    g_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
                    g_D3DDev->CreateRenderTargetView(backBuffer, NULL, &g_RenderTargetView);
                    backBuffer->Release();
                    g_DepthStencilDesc.Width = g_SwapChainDesc.BufferDesc.Width;
                    g_DepthStencilDesc.Height = g_SwapChainDesc.BufferDesc.Height;
                    g_D3DDev->CreateTexture2D(&g_DepthStencilDesc, NULL, &dsBuffer);
                    g_D3DDev->CreateDepthStencilView(dsBuffer, NULL, &g_DepthStencilView);
                    dsBuffer->Release();
                    g_D3DDevCtx->OMSetRenderTargets(1, &g_RenderTargetView, g_DepthStencilView);

                    // Setup the viewport
                    D3D11_VIEWPORT vp;
                    vp.Width = (float)g_SwapChainDesc.BufferDesc.Width;
                    vp.Height = (float)g_SwapChainDesc.BufferDesc.Height;
                    vp.MinDepth = 0.0f;
                    vp.MaxDepth = 1.0f;
                    vp.TopLeftX = 0;
                    vp.TopLeftY = 0;
                    g_D3DDevCtx->RSSetViewports(1, &vp);
                }

                // TwWindowSize has been called by TwEventWin, so it is not necessary to call it again here.
            }
            return 0;
        case WM_CHAR:
            if (wParam == VK_ESCAPE)
                PostQuitMessage(0);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(wnd, message, wParam, lParam);
    }
}
Beispiel #17
0
LRESULT		CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	// this is the main message handler of the system
	PAINTSTRUCT		ps;	// used in WM_PAINT
	HDC				hdc;	// handle to a device context

	TwEventWin(hwnd, msg, wparam, lparam);


	// what is the message 
	switch(msg)
	{	
	case WM_CREATE: 
		{
			// do initialization stuff here
			return(0);
		} 
	case WM_LBUTTONDOWN:
		{
			addCircle(LOWORD(lparam), HIWORD(lparam));
			break;
		}
		break;

	case WM_RBUTTONDOWN:
		{
			renderer->setAirjetActive(true);
			addAirjet(LOWORD(lparam), HIWORD(lparam));
		}
		break;

	case WM_MOUSEWHEEL:
		{
			float v = ((signed short)HIWORD(wparam) > 0) ? 0.5f : -0.5f;
			renderer->changeZoom(v);
		}
		break;

	case WM_RBUTTONUP:
		{
			renderer->setAirjetActive(false);
		}
		break;
	
	case WM_MOUSEMOVE:
		{
			if (renderer->airjetActive())
				addAirjet(LOWORD(lparam), HIWORD(lparam));
		}
		break;

	case WM_KEYDOWN:
		{
			// Handle any non-accelerated key commands
			switch (wparam)
			{
			case VK_ESCAPE:
			case VK_F12:
				PostMessage(hwnd, WM_CLOSE, 0, 0);
				return (0);
			case VK_RIGHT:
				
				break;
			case VK_SPACE:
				{
					setPause();
				}
				break;

			case 65: // A
				renderer->changePosition(+0.5f, 0);
				break;
			case 66: // B
				toggleSpring();
				break;
			case 67: // C
				addMultipleCircles();
				break;
			case 68: // D
				renderer->changePosition(-0.5f, 0);
				break;
			case 83: // S
				renderer->changePosition(0, +0.5f);
				break;
			case 87: // W
				renderer->changePosition(0, -0.5f);
				break;
			case 82: // R
				renderer->resetView();
				break;
			default:
				break;


			}
			break;
		}

	case WM_PAINT: 
		{
			// validate the window
			hdc = BeginPaint(hwnd,&ps);	 
			EndPaint(hwnd,&ps);
			return(0);
		} 

	case WM_DESTROY: 
		{
			// kill the application			
			PostQuitMessage(0);

			return(0);
		}

	default:
		break;

	} // end switch

	// process any messages that we didn't take care of 
	return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc
Beispiel #18
0
// --------------------------------------------------------------------------------------
// Called every time the application receives a message
//---------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

#ifdef USE_ANTTWBAR_BACKEND
    TwEventWin(hWnd, message, wParam, lParam);
#endif

    switch (message)
    {
    case WM_CLOSE:
        PostQuitMessage(0);
        return 0;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_KEYDOWN:
        if (__keyDownF)
            (__keyDownF)(wParam);
        return 0;
    case WM_KEYUP:
        if (__keyUpF)
            (*__keyUpF)(wParam);
        return 0;
    case WM_MOUSEMOVE:
    {
        if (__mouseMoveF)
            (*__mouseMoveF)
            (
            wParam,
            ((wParam == INPUT_MOUSE_LEFT || wParam == INPUT_MOUSE_MIDDLE || wParam == INPUT_MOUSE_RIGHT) ? 1 : 0),
            LOWORD(lParam),
            HIWORD(lParam)
            );
        return 0;
    }
    case WM_LBUTTONDOWN:
        if (__mouseDownF)
            (*__mouseDownF)(INPUT_MOUSE_LEFT);
        return 0;
    case WM_MBUTTONDOWN:
        if (__mouseDownF)
            (*__mouseDownF)(INPUT_MOUSE_MIDDLE);
        return 0;
    case WM_RBUTTONDOWN:
        if (__mouseDownF)
            (*__mouseDownF)(INPUT_MOUSE_RIGHT);
        return 0;
    case WM_LBUTTONUP:
        if (__mouseUpF)
            (*__mouseUpF)(INPUT_MOUSE_LEFT);
        return 0;
    case WM_MBUTTONUP:
        if (__mouseUpF)
            (*__mouseUpF)(INPUT_MOUSE_MIDDLE);
        return 0;
    case WM_RBUTTONUP:
        if (__mouseUpF)
            (*__mouseUpF)(INPUT_MOUSE_RIGHT);
        return 0;
    case WM_LBUTTONDBLCLK:
        if (__mouseDoubleF)
            (*__mouseDoubleF)(INPUT_MOUSE_LEFT);
        return 0;
    case WM_MBUTTONDBLCLK:
        if (__mouseDoubleF)
            (*__mouseDoubleF)(INPUT_MOUSE_MIDDLE);
        return 0;
    case WM_RBUTTONDBLCLK:
        if (__mouseDoubleF)
            (*__mouseDoubleF)(INPUT_MOUSE_RIGHT);
        return 0;
    case WM_SIZE:
        if(__resizeF)
            (*__resizeF)(LOWORD(lParam), HIWORD(lParam));
        return 0;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }

    return 0;
}
LRESULT CALLBACK WindowProc( HWND   hWnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam )
{
	if( TwEventWin(hWnd, msg, wParam, lParam) ) // send event message to AntTweakBar
	{return 0;} // event has been handled by AntTweakBar
   
	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;
}
Beispiel #20
0
	bool Input::Process(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
	{
		// TODO: Show cursor and block window events from the game, e.g. when some key is down.
		return TwEventWin(hWnd, msg, wParam, lParam) != 0;
	}
bool CDebugHelperImplementation::Update(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	// TODO: mandarle eventos al AntTweakBar
	return TwEventWin(hWnd, msg, wParam, lParam);
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static bool bHasFocus = false;
	if (TwEventWin(hWnd, message, wParam, lParam))
		return 0;
	switch (message)
	{
	case WM_SETCURSOR:
		{
			return DefWindowProc(hWnd, message, wParam, lParam);
			/*WORD ht = LOWORD(lParam);
			static bool hiddencursor = false;
			if (HTCLIENT == ht && !hiddencursor)
			{
			hiddencursor = true;
			ShowCursor(false);
			}
			else if (HTCLIENT != ht && hiddencursor)
			{
			hiddencursor = false;
			ShowCursor(true);
			}*/
		}
		break;

	case WM_CREATE:
		{
			bHasFocus = true;
		}
		break;

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

	case WM_CLOSE:
		{
			DestroyWindow(hWnd);
		}
		break;

	case WM_ACTIVATE:
		{
			if (LOWORD(wParam) != WA_INACTIVE)
			{
				// Unpause game here
				bHasFocus = true;
			}
			else
			{
				// Pause game here
				bHasFocus = false;
			}
			Input::SetKeyboardState(bHasFocus);
		}
		break;

	case WM_PAINT:
		{
			PAINTSTRUCT	ps;
			HDC			hdc;

			hdc = BeginPaint(hWnd, &ps);

			EndPaint(hWnd, &ps);
		}
		break;

	case WM_SYSKEYDOWN:
	case WM_SYSKEYUP:
	case WM_KEYUP:
	case WM_KEYDOWN:
	case WM_SYSCHAR:
	case WM_LBUTTONDOWN:
	case WM_LBUTTONUP:
	case WM_RBUTTONDOWN:
	case WM_RBUTTONUP:
		{
			Input::SetKeyboardState(bHasFocus);
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
// Called every time the application receives a message
LRESULT CALLBACK MessageProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // Send event message to AntTweakBar
    if( TwEventWin(wnd, message, wParam, lParam) ) 
    {
        // Event has been handled by AntTweakBar.
        // Note: TwEventWin send a WM_PAINT in this case and
        //       the window will be repaint next time.
        return 0;
    }

    switch(message) 
    {
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                BeginPaint(wnd, &ps);

                if( g_D3DDevice )
                    Render();

                EndPaint(wnd, &ps);
            }
            return 0;
        case WM_SIZE:   // Window size has been changed
            if( g_D3DDevice )   // Resize D3D render target
            {
                // Release render target
                ID3D10RenderTargetView *nullRTV = NULL;
                g_D3DDevice->OMSetRenderTargets(1, &nullRTV, NULL);
                if( g_RenderTargetView )
                {
                    g_RenderTargetView->Release();
                    g_RenderTargetView = NULL;
                }

                if( g_SwapChain )
                {
                    // Resize swap chain
                    g_SwapChainDesc.BufferDesc.Width = LOWORD(lParam);
                    g_SwapChainDesc.BufferDesc.Height = HIWORD(lParam);
                    g_SwapChain->ResizeBuffers(g_SwapChainDesc.BufferCount, g_SwapChainDesc.BufferDesc.Width, 
                        g_SwapChainDesc.BufferDesc.Height, g_SwapChainDesc.BufferDesc.Format, g_SwapChainDesc.Flags);

                    // Re-create a render target view
                    ID3D10Texture2D *buffer;
                    g_SwapChain->GetBuffer(0, __uuidof( ID3D10Texture2D ), (LPVOID*)&buffer);
                    g_D3DDevice->CreateRenderTargetView(buffer, NULL, &g_RenderTargetView);
                    buffer->Release();
                    g_D3DDevice->OMSetRenderTargets(1, &g_RenderTargetView, NULL);

                    // Setup the viewport
                    D3D10_VIEWPORT vp;
                    vp.Width = g_SwapChainDesc.BufferDesc.Width;
                    vp.Height = g_SwapChainDesc.BufferDesc.Height;
                    vp.MinDepth = 0.0f;
                    vp.MaxDepth = 1.0f;
                    vp.TopLeftX = 0;
                    vp.TopLeftY = 0;
                    g_D3DDevice->RSSetViewports(1, &vp);
                }

                // TwWindowSize has been called by TwEventWin32, so it is not necessary to call it again here.
            }
            return 0;
        case WM_CHAR:
            if( wParam==VK_ESCAPE )
                PostQuitMessage(0);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(wnd, message, wParam, lParam);
    }
}