www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to create an elegant class-member window-function?

reply Tal <publictal gmail.com> writes:
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
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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:

Alternatively see those GUI libs to see how it's done.
Dec 27 2011