Thread: Putting WndProc into a class?

  1. #1
    Registered User
    Join Date
    Aug 2001

    Putting WndProc into a class?

    I would like to put my WndProc function into a class.

    I had it like so when it was just a function

    wc.lpfnWndProc = (WNDPROC) WndProc;

    if i do that now i get this error

    C:\Programming\Projects\msvc\OpenGL Helper Library\glh.cpp(151) : error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'

    and if i do it without a typecast

    wc.lpfnWndProc = WndProc;

    I get an error like this.

    C:\Programming\Projects\msvc\OpenGL Helper Library\glh.cpp(152) : error C2440: '=' : cannot convert from 'long (__stdcall glhs::*)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long

    as you can see the only problem is that its in a class, what can i do?

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    As soon as you put a non-static WndProc in a class the signature changes so it can't be used in the WNDCLASS registration. There's a couple of ways around it. One of them is -

    1. Pass a pointer to your Wndproc member function into your CreateWindow() call as the extra data (the last parameter).

    2. Create a static dummy WndProc that just handles the WM_CREATE message. In this dummy WndProc extract the pointer to your real WndProc with GetWindowLong(), using GWL_USERDATA as the parameter.

    3. Pass all other messages and their associated LPARAM and WPARAM onto your real WndProc that was obtained above.

    It's been a while since I had to do it, so I may have missed something. If you can't get it to work do a search on google, I'm pretty sure there's a couple of tutorials somewhere.

    edit - In point 1 just pass the 'this' pointer in as extra data, then you can call the WndProc member like - this->WndProc(/*params*/) in the dummy function.
    Last edited by zen; 12-13-2001 at 05:25 PM.

  3. #3
    Registered User
    Join Date
    Aug 2001
    In my WndProc i pass all unanswered messages to DefWndProc, so i thought i could do this with a dummy WndProc like you said.

    LRESULT CALLBACK WndProc(HWND p_hwn,UINT p_msg,WPARAM p_wparam,LPARAM p_lparam) {
    return glh.WProc(p_hwn, p_msg, p_wparam, p_lparam);

    what sort of overhead would come from that?

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    The overhead of a function call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. linker error
    By tasha302 in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2006, 11:00 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM
Website Security Test