Jump to content
  • Advertisement


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


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

This topic is 5773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 ...

// do all the magic to create window
// store your this parameter with SetWindowLong

// get this pointer
CWindowClass* windowObject;
GetWindowLong(...) to windowObject - don''t remember the params

// call the actual proc

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!