Archived

This topic is now archived and is closed to further replies.

MainForze

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();
}



Share this post


Link to post
Share on other sites