• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1333
  • Last Modified:

SetTimer without CWnd but using Class Member as TimerProc

Trying to figure out how to get a call to SetTimer to work with a generic class member function as TimerProc instead of a global TimerProc function.  I do not want to use CWnd and cannot seem to do this with the Windows SDK SetTimer Function.  Any help would be appreciated. Thanks.
0
Pope
Asked:
Pope
  • 2
1 Solution
 
chensuCommented:
That class member function must be a static member function. Otherwise, a non-static member function has a implicit paramter, which is the this pointer. Thus, the function prototype does not comply the one required by SetTimer.
0
 
PopeAuthor Commented:
error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned i
nt,unsigned long)'

this is the error I get. Are you saying that I cannot give SetTimer a Class member function.

so CClass::TimerProc(etc...) will not work? I need the this pointer.
0
 
chensuCommented:
CClass::TimerProc has to be a static member function. If you want to access the this pointer, you may use a static member variable to record the this pointer.

class CClass
{
//...

public:
    static CClass *m_pThis;

//...
};


// Initialization
CClass *CClass::m_pThis = NULL;


// Set m_pThis before calling SetTimer in a member function of CClass.
m_pThis = this;


CClass::TimerProc
{

CClass::m_pThis->...

}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now