WndProc called from the object
Yo
I''ve created class glwindow and put inside a function:
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
My class has an object-member of type WNDCLASS, and while creating proper window i assign some things to its data-members. Everything goes ok until that line:
wc.lpfnWndProc = ( WNDPROC ) WndProc;
The error is:
''type cast'' : cannot convert from ''overloaded-function'' to ''WNDPROC'' None of the functions with this name in scope match the target type.
When i changed WndProc to a normal global function everything went ok. What''s going on?? Please help!!
o O l_ahriman O o
The WndProc function must be outside of the class definition. There are several articles on how this is done. Here is my implimentation:
When I create the window class, I do:
I make room in the cbWndExtra area that allows me a place to put the ''this'' pointer of the class to receive the windows messages.
When I create the window, I pass ''this'':
Then in my class, I have the function that handles the windows messages:
Let me know if you have any questions.
- onebeer
LRESULT CALLBACK WndProc(HWND hWnd, // Handle For This Window UINT uMsg, // Message For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information{ oglTopWindow *topWindow; // This is the first msg that is received by WndProc // Use it to save the CreateParam, which is the C++ class pointer // into the userdata area of the HWND if (uMsg == WM_NCCREATE) { // Get pointer to window object passed as create param topWindow = reinterpret_cast<oglTopWindow *>(((LPCREATESTRUCT)lParam)->lpCreateParams); // Save the Win32 window handle in the window object topWindow->hWnd = hWnd; // Save pointer to window object in Win32 window class dataspace ::SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<LONG>(topWindow)); } else // Assume the window object pointer is in class dataspace topWindow = reinterpret_cast<oglTopWindow *>(::GetWindowLong(hWnd, GWL_USERDATA)); // If pointer is not null, assume it is valid and let window object process msg if (topWindow != NULL) return topWindow->ProcessWindowMsg(uMsg, wParam, lParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);}
When I create the window class, I do:
memset(&windowClass, 0, sizeof(windowClass)); windowClass.style = CS_OWNDC; // If double clicks are needed, add in the style if (handleDoubleClick) windowClass.style |= CS_DBLCLKS; windowClass.cbClsExtra = 0; // Each window instance will have pointer to the C++ object windowClass.cbWndExtra = sizeof(this); windowClass.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); windowClass.hCursor = WindowsCursor(); windowClass.hIcon = WindowsIcon(); windowClass.hInstance = hInst; windowClass.lpfnWndProc = (WNDPROC)WndProc; windowClass.lpszClassName = winClassName; // Let subclass have a chance at it OnCreateWindowClass(windowClass);
I make room in the cbWndExtra area that allows me a place to put the ''this'' pointer of the class to receive the windows messages.
When I create the window, I pass ''this'':
::CreateWindow(windowClassName.c_str(), windowTitle.c_str(), winStyle, 0, 0, adjustedWinRect.right - adjustedWinRect.left, adjustedWinRect.bottom - adjustedWinRect.top, NULL, NULL, hInst, this);
Then in my class, I have the function that handles the windows messages:
LRESULT oglTopWindow::ProcessWindowMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
Let me know if you have any questions.
- onebeer
- onebeer
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement