Example #1
0
LRESULT GEN::GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	// Route Windows messages to game engine member functions
	switch (msg)
	{
	case WM_SETFOCUS:
		// Activate the game and update the Sleep status
		GameActivate(hWindow);
		SetSleep(FALSE);
		return 0;
	case WM_KILLFOCUS:
		// Deactivate the game and update the Sleep status
		GameDeactivate(hWindow);
		SetSleep(TRUE);
		return 0;
	case WM_PAINT:
		HDC         hDC;
		PAINTSTRUCT ps;
		hDC = BeginPaint(hWindow, &ps);

		// Paint the game
		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;
	case MM_MCINOTIFY:
		if (LOWORD(wParam) == MCI_NOTIFY_SUCCESSFUL)
		{
			if (GetMIDIPlayer() != nullptr)
				GetMIDIPlayer()->Restart(hWindow);
		}
		return 0;
		// Mouse Input Cases
	case WM_LBUTTONDOWN:
		// handle mouse button 
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;
	case WM_LBUTTONUP:
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;
	case WM_RBUTTONDOWN:
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;
	case WM_RBUTTONUP:
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;
	case WM_MOUSEMOVE:
		MouseMove(LOWORD(lParam), HIWORD(lParam));
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}
LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	//Route Windows messages to game engine member fucntions
	switch (msg)
	{
	case WM_CREATE:
		//Set the game window and start the game
		SetWindow(hWindow);
		GameStart(hWindow);
		return 0;

	case WM_ACTIVATE:
		//Activate and deactivate the game and update the Sleep status
		if (wParam != WA_INACTIVE)
		{
			GameActivate(hWindow);
			SetSleep(FALSE);
		}
		else
		{
			GameDeactivate(hWindow);
			SetSleep(TRUE);
		}
		return 0;

	case WM_PAINT:
		HDC			hDC;
		PAINTSTRUCT	ps;
		hDC = BeginPaint(hWindow, &ps);

		//Paint the game
		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;

	case WM_LBUTTONDOWN:
		//Handle left mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_LBUTTONUP:
		//Handle left mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_RBUTTONDOWN:
		//Handle right mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_RBUTTONUP:
		//Handle right mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_MOUSEMOVE:
		//Handle mouse movement
		MouseMove(LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_DESTROY:
		//End the game and exit the application
		GameEnd();
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}
Example #3
0
LONG T_Engine::GameEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	HDC hdc;
	switch (msg) 
	{	
	case WM_SETFOCUS:
		SetSleep(FALSE);
		return 0;
	case WM_KILLFOCUS:
		SetSleep(TRUE);
		return 0;
	case WM_CREATE:
		m_hWnd = hWnd;
		GameInit();
		return 0;
	case WM_LBUTTONDOWN:
		GameMouseAction(LOWORD(lParam), HIWORD(lParam), MOUSE_LCLICK);
		return 0;
	case WM_MOUSEMOVE:
		GameMouseAction(LOWORD(lParam), HIWORD(lParam), MOUSE_MOVE);
		return 0;
	case WM_KEYDOWN:
		keys[wParam] = true;
		GameKeyAction(KEY_DOWN);
		SubKeyAction(wParam);
		return 0;
	case WM_KEYUP:
		keys[wParam] = false;
		GameKeyAction(KEY_UP);
		return 0;
	case WM_NCLBUTTONDBLCLK: 
		if(HTCAPTION==wParam)   
		{   
			return 0;   
		}  
	case WM_SYSCOMMAND:
		if(wParam == SC_MAXIMIZE)
		{
			m_bFullScreen=!m_bFullScreen;
			if(m_bFullScreen)
			{
				GetWindowRect(hWnd, &m_rcOld);
				style = GetWindowLong(hWnd,GWL_STYLE); 
				ex_style = GetWindowLong(hWnd, GWL_EXSTYLE); 
				p_disp->SaveMode();
				//全屏幕显示
				HWND hDesktop;   
				RECT rc;  
				hDesktop = GetDesktopWindow();
				GetWindowRect(hDesktop, &rc);
				p_disp->ChangeMode(wndWidth, wndHeight);
				SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_WINDOWEDGE);
				SetWindowLong(hWnd, GWL_STYLE, WS_BORDER);
				SetWindowPos(hWnd, HWND_TOP, -1, -1, rc.right, rc.bottom, SWP_SHOWWINDOW);
			}
		}
		else if(wParam == SC_CLOSE)
		{
			if(IDOK==MessageBox(NULL,L"你确定要退出吗?", 
				wndTitle, MB_OKCANCEL|MB_ICONQUESTION))
			{
				DestroyWindow(hWnd);
			}
		}
		else
		{
			return DefWindowProc(hWnd, WM_SYSCOMMAND, wParam,lParam); 
		}
		return 0;
	case WM_CLOSE:
		DestroyWindow(hWnd);
		return 0;
	case WM_PAINT:
		PAINTSTRUCT ps;
		hdc=BeginPaint(hWnd,&ps);
		GamePaint(hdc);
		EndPaint(hWnd,&ps);	
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);	
}