WndProc as a member function..

Started by
3 comments, last by Rahven 22 years, 10 months ago
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
Advertisement
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.
Look here
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
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

This topic is closed to new replies.

Advertisement