I ran into this exact problem a while ago, and found a decent solution. A good person to ask is Ken Fitlike, he's good with classes.
Basically, you need to create two member functions: a static callback procedure, and a normal one, with the same parameters.
In the static one, the first time it is called, you have to obtain a pointer to the instance of the class you want. Then you can forward the messages to the non-static procedure, which has full access to the class members. Compilcated, I know.
Code:
class benny
{
public:
static LRESULT CALLBACK bennyProcA(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK bennyProc(HWND,UINT,WPARAM,LPARAM);
int data;
};
LRESULT CALLBACK benny::bennyProcA(params)
{
if (msg==WM_NCCREATE)
{
LPCREATESTRUCT lpc;
lpc=(LPCREATESTRUCT)lParam;
SetWindowLong(hwnd,GWL_USERDATA,(LONG)lpc->lpCreateParams);
SetWindowLong(hwnd,0,1);
return DefWindowProc(hwnd,msg,wParam,lParam);
}
benny *it;
if (GetWindowLong(hwnd,0))
{
it=(benny *)GetWindowLong(hwnd,GWL_USERDATA);
return it->bennyProc(params);
}
return DefWindowProc(params);
}
LRESULT CALLBACK benny::bennyProc(params)
{
//code
}
It's intensely complicated actually. Basically, the callback procedure has to be static, so that there is an instance to point to from the beginning. But, this means that the procedure CANNOT know where the instance of the CLASS is. So you have to find the class instance yourself, and store that value somewhere permanent. Then you can forward messages all you want. But I don't know how it would be done when not using the window procedure. It just happens that the WM_NCCREATE is the first one to occur, and can contain a pointer to the class.
If that's too complex, I'll try again.