I don't know of any /elegant/ way of doing it, but a hash mapping HWND's to Objects is usually how it's done. This is how DFL, DGUI, and Harmonia work.
You can check out the function "winDispatch" in my sample win32_window_framework here: https://github.com/AndrejMitrovic/cairoDSamples Alternatively see those GUI libs to see how it's done.