Ejemplo n.º 1
0
LRESULT CALLBACK GraphicsEngineImp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	GraphicsEngineImp* gfx = NULL;

	if(message == WM_CREATE)
	{
		gfx = (GraphicsEngineImp*)((LPCREATESTRUCT)lParam)->lpCreateParams;
		SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)gfx);
	}
	else
	{
		gfx = (GraphicsEngineImp*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
	}

	switch (message) 
	{
		case WM_KEYDOWN:
			if (gfx) gfx->GetKeyList()->KeyDown(wParam);
			break;
		
		case WM_KEYUP:
			if (gfx) gfx->GetKeyList()->KeyUp(wParam);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		// Left Mouse Pressed
		case WM_LBUTTONDOWN:
			if (gfx) gfx->GetKeyList()->MouseDown(1);
			break;

		case WM_LBUTTONUP:
			if (gfx) gfx->GetKeyList()->MouseUp(1);
			break;

		// Right Mouse Pressed
		case WM_RBUTTONDOWN:
			if (gfx) gfx->GetKeyList()->MouseDown(2);
			break;

		case WM_RBUTTONUP:
			if (gfx) gfx->GetKeyList()->MouseUp(2);
			break;

		// TODO: Handle File Drops
		case WM_DROPFILES:
			{
			HDROP drop = (HDROP)wParam;
			int nrOfFiles = DragQueryFile(drop, 0xFFFFFFFF, NULL, NULL);
			if(nrOfFiles != 1)
				MaloW::Debug("Multiple files not supported, you tried to drop " + MaloW::convertNrToString((float)nrOfFiles) + " files.");

			TCHAR lpszFile[MAX_PATH] = {0};
			lpszFile[0] = '\0';
			if(DragQueryFile(drop, 0, lpszFile, MAX_PATH))
			{
				if(gfx)
					gfx->specialString = string(lpszFile);
			}
			else
				MaloW::Debug("Failed to load a droppped file.");
			}
			break;

		// TODO: Handle Resize
		case WM_SIZE:
			{
				/*
				RECT rc;
				GetClientRect(hWnd, &rc);
				int screenWidth = rc.right - rc.left;;
				int screenHeight = rc.bottom - rc.top;
				if(gfx)
				{
					bool manage = gfx->GetManagingWindow();
					gfx->SetManagingWindow(false);
					gfx->ResizeGraphicsEngine(screenWidth, screenHeight);
					gfx->SetManagingWindow(manage);
				}
					*/

				if ( wParam == SIZE_MAXHIDE )
				{

				}
				else if ( wParam == SIZE_MAXIMIZED )
				{

				}
				else if ( wParam == SIZE_MAXSHOW )
				{

				}
				else if ( wParam == SIZE_MINIMIZED )
				{

				}
				else if ( wParam == SIZE_RESTORED )
				{

				}
			}
			break;
			
			
		case WM_ACTIVATE:
			{
				if(gfx && gfx->GetManagingWindow() && wParam != 0)
				{
					// Confine cursor within program.
					RECT cRect;
					GetClientRect(hWnd, &cRect);
					POINT topLeft;
					topLeft.x = 0;
					topLeft.y = 0;
					ClientToScreen(hWnd, &topLeft);
					RECT screenRect;
					screenRect.left = topLeft.x;
					screenRect.top = topLeft.y;
					screenRect.right = screenRect.left + cRect.right;
					screenRect.bottom = screenRect.top + cRect.bottom;
					ClipCursor(&screenRect);
					//

					POINT np;
					np.x = gfx->GetEngineParams().WindowWidth/2;
					np.y = gfx->GetEngineParams().WindowHeight/2;
					if(ClientToScreen(hWnd, &np))
					{
						SetCursorPos(np.x, np.y);
					}
				}
			}
			break;
			
			/*
		case WM_MOVING:
			break;
		case WM_ENTERSIZEMOVE:
			break;
		case WM_EXITSIZEMOVE:
			break;
			*/

		// Dont send SYSKEY to DefWindowProc to stop ALT-disabling.
		// Alt + keys doesnt work, should be the WM_SYSCHAR thing below...
		// Keydown -> Alt down -> Key up    fails horribly too.
		case WM_SYSKEYDOWN:
			break;
		case WM_SYSKEYUP:
			break;
		case WM_SYSCHAR:
			/*if(gfx)
			{
				if((lParam >> 31) & 1)
					gfx->GetKeyList()->KeyUp(wParam);
				else 
					gfx->GetKeyList()->KeyDown(wParam);
			break;
			}*/
		case WM_MENUCHAR:
			//if (gfx) gfx->GetKeyList()->KeyUp(LOWORD(wParam));
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 2
0
LRESULT CALLBACK GraphicsEngineImp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	GraphicsEngineImp* gfx = NULL;

	if(message == WM_CREATE)
	{
		gfx = (GraphicsEngineImp*)((LPCREATESTRUCT)lParam)->lpCreateParams;
		SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)gfx);
	}
	else
	{
		gfx = (GraphicsEngineImp*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
	}

	switch (message) 
	{
		case WM_KEYDOWN:
			if (gfx) gfx->GetKeyList()->KeyDown(wParam);
			break;
		
		case WM_KEYUP:
			if (gfx) gfx->GetKeyList()->KeyUp(wParam);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		// Left Mouse Pressed
		case WM_LBUTTONDOWN:
			if (gfx) gfx->GetKeyList()->MouseDown(1);
			break;

		case WM_LBUTTONUP:
			if (gfx) gfx->GetKeyList()->MouseUp(1);
			break;

		// Right Mouse Pressed
		case WM_RBUTTONDOWN:
			if (gfx) gfx->GetKeyList()->MouseDown(2);
			break;

		case WM_RBUTTONUP:
			if (gfx) gfx->GetKeyList()->MouseUp(2);
			break;

		// TODO: Handle File Drops
		case WM_DROPFILES:
			{
			HDROP drop = (HDROP)wParam;
			int nrOfFiles = DragQueryFile(drop, 0xFFFFFFFF, NULL, NULL);
			if(nrOfFiles != 1)
				MaloW::Debug("Multiple files not supported, you tried to drop " + MaloW::convertNrToString((float)nrOfFiles) + " files.");

			TCHAR lpszFile[MAX_PATH] = {0};
			lpszFile[0] = '\0';
			if(DragQueryFile(drop, 0, lpszFile, MAX_PATH))
			{
				if(gfx)
					gfx->specialString = string(lpszFile);
			}
			else
				MaloW::Debug("Failed to load a droppped file.");
			}
			break;

		// TODO: Handle Resize
		case WM_SIZE:
			{
				/*
				RECT rc;
				GetClientRect(hWnd, &rc);
				int screenWidth = rc.right - rc.left;;
				int screenHeight = rc.bottom - rc.top;
				if(gfx)
				{
					bool manage = gfx->GetManagingWindow();
					gfx->SetManagingWindow(false);
					gfx->ResizeGraphicsEngine(screenWidth, screenHeight);
					gfx->SetManagingWindow(manage);
				}
					*/
				if ( wParam == SIZE_MAXHIDE )
				{

				}
				else if ( wParam == SIZE_MAXIMIZED )
				{

				}
				else if ( wParam == SIZE_MAXSHOW )
				{

				}
				else if ( wParam == SIZE_MINIMIZED )
				{

				}
				else if ( wParam == SIZE_RESTORED )
				{

				}
			}
			break;

			/*
		case WM_MOVING:
			break;
		case WM_ENTERSIZEMOVE:
			break;
		case WM_EXITSIZEMOVE:
			break;
			*/
				
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}