Skip to main content
gamedev.net
🔒 Locked

Altering windows message handler parameters?

Started by SiDtheTurtle 0 replies 400+ views
Original Post
SiDtheTurtle
SiDtheTurtle
I'm trying to deal with an Directshow events, all encapsulated in a class called LDS. When I want the windows message handler to respond to these messages, I want it to call a prodcedure handleEvent which is a member function of LDS. I cannont, however, pass in an instance of the class to the message procedure, as whenever I alter the parameters, it won't work. Is is possible to alter the parameters? They are currently: LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) I want to append LDS &pLDS to the end, but it won't let me.
Evil Steve
Evil Steve
Nope, it's not possible to alter the parameters. However, you can use SetWindowLong() and GetWindowLong() to set the 32-bit user data value associated with a HWND.

E.g:
// At startup...LPLDS pLDS;CreateWindowEx(...,pLDS);// Your window procedure...LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){LPLDS pLDS;   if(uMsg == WM_CREATE)   {      pLDS = (pLDS*)((LPCREATESTRUCT)lParam)->lpCreateParams;      SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG_PTR)pLDS);   }   else      pLDS = (pLDS*)GetWindowLongPtr(hWnd,GWL_USERDATA);   // Do something with pLDS here   return DefaultWndProc(hWnd,uMsg,wParam,lParam);}

You can use a similar tecnique to wrap your window procedure in a class, for example, from my code:
LRESULT CALLBACK CStateMachine::StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){CStateMachine* pParent;	// Get pointer to app //	if(uMsg == WM_CREATE)	{		pParent = (CStateMachine*)((LPCREATESTRUCT)lParam)->lpCreateParams;		SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG_PTR)pParent);	}	else	{		pParent = (CStateMachine*)GetWindowLongPtr(hWnd,GWL_USERDATA);		if(!pParent) return DefWindowProc(hWnd,uMsg,wParam,lParam);	}	pParent->m_hWnd = hWnd;	return pParent->WndProc(uMsg,wParam,lParam);}LRESULT CStateMachine::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam){   // Code here   return DefWindowProc(m_hWnd,uMsg,wParam,lParam);}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.