//----------------------------------------------------------------------------*/
#define SECOND 1000 //1000 ms
//----------------------------------------------------------------------------*/
class TFpsCounter
{
private:
int Frames;
int CurrentFPS;
UINT TimerHandle;
VOID CALLBACK TimerP1(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
public:
TFpsCounter(void);
~TFpsCounter(void);
int IncFrames(void);
};
//----------------------------------------------------------------------------*/
int TFpsCounter::IncFrames(void)
{
Frames++;
return CurrentFPS;
}
//----------------------------------------------------------------------------*/
VOID CALLBACK TFpsCounter::TimerP1(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
CurrentFPS=Frames;
Frames=0;
}
//----------------------------------------------------------------------------*/
TFpsCounter::TFpsCounter(void)
{
Frames = 0;
TimerHandle = SetTimer(0, 0, SECOND, (TIMERPROC) TimerP1);
}
//----------------------------------------------------------------------------*/
TFpsCounter::~TFpsCounter(void)
{
KillTimer(NULL, TimerHandle);
}
//----------------------------------------------------------------------------*/
Regards,
David Stubbs
Help with this little code snippet
Help...Generates this error:
[C++ Error] FPSClass.cpp(45): E2235 Member function must be called or its address taken.
I reckon I know why but I don''t know any way to make it work, other than doing it in functions, which defeats the point of what I am trying to achieve.
Regards,Dave
Yeah...
Don''t think you can pass in a member function as a callback. Probably because they need a this pointer on the stack beforehand. A static one might work if thats any help? You could have a static function that passes the timer message on to all instances. But then youre unlikely to have more than one instance of an FPS counter. Why not use a namespace instead?
Couldnt say anything for definate without trying things out for myself.
ro
Don''t think you can pass in a member function as a callback. Probably because they need a this pointer on the stack beforehand. A static one might work if thats any help? You could have a static function that passes the timer message on to all instances. But then youre unlikely to have more than one instance of an FPS counter. Why not use a namespace instead?
Couldnt say anything for definate without trying things out for myself.
ro
Try this...
That''s how I do it... Email me if you need clarification.
Regards,
Jumpster
//----------------------------------------------------------------------------*/#define SECOND 1000 //1000 ms//----------------------------------------------------------------------------*/VOID CALLBACK HandleTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);class TFpsCounter{ private: int Frames; int CurrentFPS; UINT TimerHandle; HWND handle; // public: TFpsCounter(void) { // Create invisible window handle here... Handle = ...; // Add (this) pointer to the handle... SetWindowLong(Handle, GWL_USERDATA, this); } ; ~TFpsCounter(void); int IncFrames(void); friend VOID CALLBACK HandleTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);};//----------------------------------------------------------------------------*/int TFpsCounter::IncFrames(void){ Frames++; return CurrentFPS;}//----------------------------------------------------------------------------*/TFpsCounter::TFpsCounter(void){ Frames = 0; TimerHandle = SetTimer(Handle, 0, SECOND, (TIMERPROC) TimerP1);}//----------------------------------------------------------------------------*/TFpsCounter::~TFpsCounter(void){ KillTimer(NULL, TimerHandle);}//----------------------------------------------------------------------------*///----------------------------------------------------------------------------*/VOID CALLBACK HandleTimer(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime){ TFpsCounter* temp = (TFpsCounter*) GetWindowLong(hwnd, GWL_USERDATA); temp->CurrentFPS=temp->Frames; temp->Frames=0;}
That''s how I do it... Email me if you need clarification.
Regards,
Jumpster
Regards,JumpsterSemper Fi
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement