Advertisement

WndProc called from the object

Started by March 03, 2004 11:38 AM
3 comments, last by l_ahriman 21 years ago
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:

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
Advertisement
It''s nearly working I quess... there is no error anymore, but I can''t draw anything in a window could you give some link to the one of the article you have mentioned about ( if u have one )??
anyway greeeaaat thanx
o O l_ahriman O o
Try this article.

Enigma
quote:
Original post by Enigma
Try this article.

Enigma


Thanx a looot - this is exactly what i needed.
o O l_ahriman O o

This topic is closed to new replies.

Advertisement