C++, OOP, my Windowing class structure question.
Posted on 2001-06-20
I've written a class to create windows which can then have OpenGL graphics put in them.
My current project consists of 3 files:
Right now, CWindow.h has a function prototype for LRESULT CALLBACK msgHandler(...), which is my message handling function. The message handler is located in Main.cpp, along with the functions to draw an OpenGL scene. I want to move the message handler into the CWindow file somehow, to encapsulate my windows better. Unfortunately, I can't get this to work, the program just crashes (Gives me a windows messagebox saying program has performed an illegal operation).
It would be nice if I could make the message handler a member function or something. The problem is that because the handler is just a function in CWindow.cpp, it can't access the class members like member functions can.
In my current implementation with the msg handler in Main.cpp, I have created a global CWindow pointer (globWin), and then in the message handler I have code like:
if (globWin->bActive == TRUE)
I don't know what to do if I put the message handler in the class file. Could I make the message handler a friend function and then use the THIS pointer in place of globWin?