Solved

SetTimer without CWnd but using Class Member as TimerProc

Posted on 2000-04-07
3
1,233 Views
Last Modified: 2013-11-20
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
Comment
Question by:Pope
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 2694953
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
 

Author Comment

by:Pope
ID: 2695013
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
 
LVL 23

Expert Comment

by:chensu
ID: 2695127
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now