digitalmars.D.learn - Is there a way to create an elegant class-member window-function?
- Tal (7/7) Dec 27 2011 The Window-Procedure in the Win32 API must be static \ global function s...
- Andrej Mitrovic (7/7) Dec 27 2011 I don't know of any /elegant/ way of doing it, but a hash mapping
The Window-Procedure in the Win32 API must be static \ global function since it cannot take a class-object (the this) parameter. One can of-course use workarounds like a hWnd->object dictionary and such. I wonder if D has a way to elegantly solve it, like create a tiny member function copy for each object (to call the object's real handler) or anonymous function that I can assign to WNDCLASS.lpfnWndProc (I know there are anonymous functions, but I cannot use the extern(Windows) property on them) ?
Dec 27 2011
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.
Dec 27 2011