Problem with WndProc

Started by
2 comments, last by rayli1107 18 years, 10 months ago
I'm trying to write a wrapper class for creating generalized window. I was trying to have WndProc as a member function of the class, and then assign WndProc like this: void GLWindow::CreateWindow() { ... WNDCLASS WC; WC.lpfnWndProc = (WNDPROC) (this->WndProc); ... } where WndProc is a member function of GLWindow class However this gave me cast error, saying it cannot cast it that specific type. Can anyone tell me how I can do this? Thanks.
Advertisement
You cannot do this. This is because when you fill WNDCLASSEX it expects a simple function pointer to MsgProc. The function pointer to the MsgProc you supply is Class::Function(). Also note this is un castable (in my experience).

I wrote a wrapper for the window creation years ago and the way i did it was to just have this MsgProc floating arounf in the cpp file. I wasn't and am still not satisfied with this.

E

ace
Why not using a static function ? Look at this :

When you create your window with CreateWindowEx() set lpParam to 'this'. You'll then be able to get it back in your static function.

//
//
//
class cWindow
{
public:
.....
private:
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
}


//
//
//
LRESULT CALLBACK cWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Get back our 'this'
cWindow* pThis = (cWindow*)GetWindowLong(hWnd, GWL_USERDATA);


switch (uMsg)
{
// Window creation
case WM_CREATE:
{
// class pointer
pThis = (cWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams;

// Store it in the window's info
SetWindowLong(hWnd, GWL_USERDATA, (LONG )pThis);
}
break;

......
}

Hope it'll help you..

- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
nice this is what I needed

Thanks.

This topic is closed to new replies.

Advertisement