Archived

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

Rahven

WndProc as a member function..

Recommended Posts

Hi, At the moment I''m in the stage of writing a series of classes that can be completely reused for all my future games ie(CTextureManager, CVector, CBoundingBox etc) one thing I can''t get my head around is how to make the WndProc funtion for Win32 code a public member funtion of CGLApp at the moment I have the GLApp object pointer global so it WndProc can call CGLApp:rocessWndMessages(...). Any help would be appreciated. Thanks Rahven

Share this post


Link to post
Share on other sites
Make it static:

  
class CGLApp
{
protected:
static LRESULT CALLBACK WndProc( ... );
public:
...
}


The only thing to remember is that static methods cannot directly access non-static member variables. That means you''ll probably either need to use SetWindowLong to save a pointer to your CGLApp class with the windows you use, then in the WndProc method, use GetWindowLong to retrieve the pointer and access members through that, or you would need to have CGLApp global.


War Worlds - A 3D Real-Time Strategy game in development.

Share this post


Link to post
Share on other sites
I had the same problem until i found this great tutorial which explains in detail how to get WndProc to work as a member of a
class. It also has source code:

http://www.intrepidhero.com/articles/faq/windowclass.html

Share this post


Link to post
Share on other sites
although the above methods are pretty much the standard ways of doing it, things can be made a lot more simple when working with games, after all, you usually only have one window,

storing a global pointer to the window before calling CreateWindow() and using that pointer in your WindowProc() is probably all you need (making it a singleton), it saves you a lot of trouble

this may not look very advanced or flexible but there''s no point in making things complicated when there''s no reason to

Share this post


Link to post
Share on other sites