Hello all, I need some opinions from everyone. I've been questioning my approach on handling window events. As you most likely know, the window procedure is very tightly coupled to a winapi window, as is registering the window class.
The way I circumvent this is by using a static MessageRouter(read static WNDPROC) that grabs the pointer to my engine class that is stored in the extra user data of the window. I then call my MessageHandler from my engine inside the MessageRouter and that is how I forward my events.
I do feel as though this is a very suitable solution, however I also feel as though there are better, more elegant ways to handle this. I just wanted to get everyone's input on how they handle this exact problem.
This is an example of my my approach looks;
LRESULT CALLBACK LWindowWin32::MessageRouter(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Lightning *pLightning;
if (msg == WM_NCCREATE)
{
LPCREATESTRUCT lpCreateStruct = reinterpret_cast<LPCREATESTRUCT>(lParam);
pLightning = static_cast<Lightning*>(lpCreateStruc->lpCreateParams);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pLightning));
}
else
{
pLightning = reinterpret_cast<Lightning*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
if (pLightning)
{
pLightning->MessageHandler(/*converted winapi parameters would go here*/)
}
return DefWindowProc(hWnd, msg, wParam, lParam, );
}
Thank you,
BagelBytes