0

i'm mainly focused on how this example uses wndproc as friend... im a little confused how it works and im just trying to figure out if and how this would work with more than one window

http://www.uta.fi/~jl/pguibook/api2oo.html

gizmo
  • 1
  • 2

1 Answers1

0

Yes, it will work with more than one window because it stores a pointer to the C++ object with the corresponding HWND:

Window *wPtr;
...
SetWindowLongPtr(hWnd, 0, (LONG_PTR) wPtr);

and the global WndProc then retrieves that pointer and calls the object's methods through it:

wPtr = (Window*) ::GetWindowLongPtr(hWnd, 0);
wPtr->WndProc(message, wParam, lParam);

(Note that the original code uses SetWindowLong, and hence won't work in a 64-bit program - I've changed the code above to use SetWindowLongPtr.)

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Please change to SetWindowLongPtr - it works for 32 and 64 bit apps. SetWindowLong docs will tell you to change. – Boofhead May 05 '11 at 22:44
  • @Boofhead: I was quoting verbatim the code that @gizmo pointed at. But you're right, code here on StackOverflow should be correct, so I've changed it. – RichieHindle May 06 '11 at 08:27