0

Possible Duplicate:
Best method for storing this pointer for use in WndProc

I'm trying to write a generic class that handles Win32 controls, the problem is, the WndProc message handler function is static so I cannot access important local class members such as the hWnd from the function unless I make them static too and instantiate them in the global namespace.

Now I did try that but quickly discovered the minute I created another instance of the control class, the previously created instance got its static member values over written by the new one. Does anybody have an idea about how to go about implementing this class? Is it possible to somehow have multiple instances of a static member?

Thanks,

Community
  • 1
  • 1
Walter
  • 664
  • 1
  • 6
  • 19
  • It's been a while since I've dealt with this, but MFC and OWL both implemented a form of dynamic-dispatch which the WndProc used to map the HWND of the message onto the object, and then do a normal method call. – Mike C Jun 05 '12 at 17:39
  • ah, found the article in that link very enlightening, thank you kindly James – Walter Jun 05 '12 at 18:00

1 Answers1

3

Use the static WndProc as proxy function that calls into a specific object instance passed to the static WndProc. I usually use the GetWindowLongPtr and SetWindowLongPtr API to store a pointer to instance that created the window.

pag3faul7
  • 428
  • 2
  • 7