static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { Win32WindowImpl* windowImpl; if (message == WM_CREATE) { // save instance pointer in userdata field on init windowImpl = (Win32WindowImpl*) ((LPCREATESTRUCT)lParam)->lpCreateParams; SetWindowLong(hwnd, GWL_USERDATA, (long)windowImpl ); } else { // get instance pointer from userdata field windowImpl = (Win32WindowImpl*) GetWindowLong(hwnd, GWL_USERDATA); } // delegate to class method if (windowImpl) return windowImpl->processMessage(hwnd, message, wParam, lParam); else return DefWindowProc(hwnd,message,wParam,lParam); }
// static LRESULT CALLBACK Win32WindowImpl::delegateWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { #if defined (WIN64) || defined(_MSC_VER) Win32WindowImpl* windowImpl = (Win32WindowImpl*) GetWindowLongPtr(hwnd, GWLP_USERDATA); #else Win32WindowImpl* windowImpl = (Win32WindowImpl*) GetWindowLong(hwnd, GWL_USERDATA); #endif return windowImpl->processMessage(hwnd, message, wParam, lParam); }
// static LRESULT CALLBACK Win32WindowImpl::windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_CREATE) { Win32WindowImpl* windowImpl; LPCREATESTRUCT pCreateStruct = reinterpret_cast<LPCREATESTRUCT>(lParam); if (gHandle) { LPMDICREATESTRUCT pMDICreateStruct = reinterpret_cast<LPMDICREATESTRUCT>(pCreateStruct->lpCreateParams); windowImpl = reinterpret_cast<Win32WindowImpl*>( pMDICreateStruct->lParam ); } else { windowImpl = reinterpret_cast<Win32WindowImpl*>( pCreateStruct->lpCreateParams ); } if (windowImpl) { #if defined (WIN64) || defined(_MSC_VER) SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)windowImpl ); SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) delegateWindowProc ); #else SetWindowLong(hwnd, GWL_USERDATA, (long) windowImpl ); SetWindowLong(hwnd, GWL_WNDPROC, (long) delegateWindowProc ); #endif return windowImpl->processMessage(hwnd, message, wParam, lParam); } } return gDefWindowProc(hwnd, message, wParam, lParam); }