Solved

SetTimer without CWnd but using Class Member as TimerProc

Posted on 2000-04-07
3
1,256 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 110
mapBully challenge 6 155
unix example issues 18 100
Authenticate using sesu from script 7 60
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

820 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