more on creating a Win32 Window wrapper class...

WTF again. This version of Firefox decided that the gamedev.net edit fields were not good enough targets to copy the content of the clipboard. This is very annoying, as it happens only on this machine. It is painfull, as I have to type URL instead of just copy them.

This is a simple followup to Oluseyi's article. Some of you might ask how to add non-static message handlers to his nifty Window class - here is the solution!

Oluseyi's version of tyMessageHandler is a pointer to function, meaning that it can handle only static member functions and non-member functions. This is the key difference between my code and Oluseyi's. The other big difference lies in the MsgRouter() method:

if(wnd) { tyMessageIterator it; it = wnd->GetMessageHandler(message); if(it != NULL) { // this is the main difference: // it->second is a pointer to a member function, not a // pointer to a function. We also get rid of *wnd (pretty useless) // and hwnd (pretty useless too, since we'll call this->GetHWND()) return ((*wnd).*(it->second))(wparam, lparam); } } return DefWindowProc(hwnd, message, wparam, lparam);}

There is only one remaining difference between Oluseyi's version and mine, and it copes with the way we register the handlers. While the RegsiterMessagehandler() method don't change at all, the way we call it change.

// how to register a handler: RegisterMessageHandler(WM_CLOSE, &Window::OnClose);

Don't forget the '&', the class name and the scope resolution operator - they are mandatory in this case.

I left the easy part for the end - the message handler method signatures are now far simpler:

Voila. Once it has been registered, your member function will be automagically called if the message is triggered. It was rather easy, isn't it?

One can add more complexity by using marshallers objects that will first decode both wparam and lparam then call your message handler using the right arguments (for example, a POINT object and a flag value for a mouse message). This is beyond the scope of this journal entry - but be quiet, and I'll give some hints to you ;)