WindowProc in a class........

Started by
1 comment, last by MainForze 21 years, 7 months ago
Hiya! As you might have read in my previous post, I'm working on a DirectDraw7 wrapper class. This class also contains the code for the window it uses, so I made the WindowProc a member function of my class. The problem is, when filling a WNDCLASSEX struct to create the window, you also need to supply a pointer to the WindowProc. Normally, you would say WndClass.lpfnWndProc = WindowProc; but for some reason this doesn't work. I also tried WndClass.lpfnWndProc = (WNDPROC)WindowProc; but this doesn't help. After that I tried WndClass.lpfnWndProc = ddClass::WindowProc; (ddClass is the name of my class, btw), but still no dice... Can somebody please help me out here? If you need the sourcecode, take a look at my previous post from yesterday. Greetz, MainForze [edited by - MainForze on September 30, 2002 11:35:46 AM]
"It's strange, isn't it? You stand in the middle of a library and go 'AAAAAAAGGHHHH' and everyone just stares at you. But you do the same thing on an airplane, and everyone joins in!"
Advertisement
Take a look at the DX7 framework code for an example of how to do this. Specifically the d3dapp.cpp file, which contains their static vars/functions and application wrapper class to implement this type of functionality. It''s a little bit convoluted, but not bad. If you draw out an event diagram of how the various functions interact, I''m sure you can get a handle on it.
Class member functions cannot simply be used as callbacks. The reason for this is that member functions expect an implicit parameter to the object they are operating on - the ''this'' pointer.

What I usually do is have a static member function in the class. Either just make the WndProc static, or, if you want to have multiple instances, make it a forwarder.

Store the instance variable somewhere in the window data. I.e. (if I remember my windows correctly - not writing much of it nowadays):

class CWindowClass {    static callbackForwarder();    virtual perInstanceCallback();    ... loads of other stuff ...};    CWindowClass::CreateWindow(){    // do all the magic to create window    ...    // store your this parameter with SetWindowLong    SetWindowLong(...}CWindowClass::callbackForwarder(){    // get this pointer    CWindowClass* windowObject;    GetWindowLong(...) to windowObject - don''t remember the params    // call the actual proc    windowObject->perInstanceCallback();} 


This topic is closed to new replies.

Advertisement