will this OO win32API example work with multiple windows?
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 wor开发者_开发知识库k with more than one window
http://www.uta.fi/~jl/pguibook/api2oo.html
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
.)
精彩评论