Im not very good at explaining, so let me show you how i did with my game engine
// .h
class CVortez3DEngine {
// some stuffs removed...
public:
virtual void OnChar(UINT Ch){}
virtual void OnKeyDown(UINT KeyPressed){}
virtual void OnKeyUp(UINT KeyReleased){}
public:
virtual void OnMouseDown(int ButtonPressed, int x, int y){}
virtual void OnMouseUp(int ButtonPressed, int x, int y){}
virtual void OnMouseMove(int x, int y);
virtual void OnMouseMove(int x, int y, int XDisp, int YDisp){}
virtual void OnMouseRoll(int RollCount){}
}
class CVortez3DEngineExt : public CVortez3DEngine {
// some stuffs removed...
public:
void OnChar(UINT Ch);
void OnKeyDown(UINT KeyPressed);
void OnKeyUp(UINT KeyReleased);
public:
void OnMouseDown(int ButtonPressed, int x, int y);
void OnMouseUp(int ButtonPressed, int x, int y);
void OnMouseMove(int x, int y);
void OnMouseMove(int x, int y, int XDisp, int YDisp);
void OnMouseRoll(int RollCount);
};
// .cpp
CVortez3DEngine *pVortez3DEngine = NULL;
// ...
//-----------------------------------------------------------------------------
// Process the windows messages
//-----------------------------------------------------------------------------
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
//Process quit message
case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
break;
// some stuffs removed...
// Keyboard messages, for text...
case WM_CHAR:
pVortez3DEngine->OnChar((UINT)wParam);
break;
// Keyboard messages, , for keys...
case WM_KEYDOWN:
if(wParam == VK_ESCAPE && pVortez3DEngine->GetUseEscKeyToQuit()){
PostQuitMessage(0);
break;
}
pKeyState[wParam] = true;
pVortez3DEngine->OnKeyDown((UINT)wParam);
break;
case WM_KEYUP:
pKeyState[wParam] = false;
pVortez3DEngine->OnKeyUp((UINT)wParam);
break;
// Mouse move messages
case WM_MOUSEMOVE:
pVortez3DEngine->OnMouseMove(LOWORD(lParam), HIWORD(lParam));
break;
// Mouse buttons messages
case WM_LBUTTONDOWN:
pMouseBtnState[LEFT_MOUSE_BUTTON] = true;
pVortez3DEngine->OnMouseDown(LEFT_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
case WM_LBUTTONUP:
pMouseBtnState[LEFT_MOUSE_BUTTON] = false;
pVortez3DEngine->OnMouseUp(LEFT_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
case WM_MBUTTONDOWN:
pMouseBtnState[MIDDLE_MOUSE_BUTTON] = true;
pVortez3DEngine->OnMouseDown(MIDDLE_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
case WM_MBUTTONUP:
pMouseBtnState[MIDDLE_MOUSE_BUTTON] = false;
pVortez3DEngine->OnMouseUp(MIDDLE_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
case WM_RBUTTONDOWN:
pMouseBtnState[RIGHT_MOUSE_BUTTON] = true;
pVortez3DEngine->OnMouseDown(RIGHT_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
case WM_RBUTTONUP:
pMouseBtnState[RIGHT_MOUSE_BUTTON] = false;
pVortez3DEngine->OnMouseUp(RIGHT_MOUSE_BUTTON, (int)LOWORD(lParam), (int)HIWORD(lParam));
break;
//Mouse wheel message
case WM_MOUSEWHEEL:
{
int RollCount = (signed short)HIWORD(wParam) / WHEEL_DELTA;
pVortez3DEngine->OnMouseRoll(RollCount);
}
break;
// Process other messages
default:
OnCustomMessage(uMsg, wParam, lParam);
break;
}
//Return result to windows
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// int the file using CVortez3DEngineExt
//-----------------------------------------------------------------------------
// OnKeyDown event...
//-----------------------------------------------------------------------------
void CVortez3DEngineExt::OnKeyDown(UINT KeyPressed)
{
}
//-----------------------------------------------------------------------------
// OnMouseDown event...
//-----------------------------------------------------------------------------
void CVortez3DEngineExt::OnMouseDown(int ButtonPressed, int x, int y)
{
}
//-----------------------------------------------------------------------------
// OnMouseUp event...
//-----------------------------------------------------------------------------
void CVortez3DEngineExt::OnMouseUp(int ButtonPressed, int x, int y)
{
}
//-----------------------------------------------------------------------------
// OnMouseMove event...
//-----------------------------------------------------------------------------
void CVortez3DEngineExt::OnMouseMove(int x, int y, int XDisp, int YDisp)
{
}
All im doing is creating virtual functions, overriding them later with another class, and react to OnMouseMove(), OnKeyDown() ect...
If you don't declare them in the CVortez3DEngineExt class, it will use the default ones (empty functions) supplyed in CVortez3DEngine, so, you don't have to use all the events if you wish, they are optional, that's the great part about it.