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

Setting Callback function inside a class

Apart from setting a callback function as Static inside a class, is there any way to set it inside a class coz I have to access a class function inside the callback function of SetTimer(HWND hWnd, UINT nMsg , UINT nIDEvent, DWORD dwTime);??
  • 2
1 Solution
Unfortunately there is no other way.
But you still can use
CWnd* CWnd::FromHandle( WHND hWnd )
wich is static and thus preventing you from useing it with a certain instance of any CWnd object.
So the decision is:
void CALLBACK CYourWndClass::TimerProc ( HWND hWnd, UING nMsg, UINT idEvent, DWORD dwTime )
  CYourWndClass* pWnd = (CYourWndClass*)CWnd::FromHandle ( hWnd );

  //do whatever you want to do :)

TimerProc is still static method of CYourWndClass and you can do exactly what you whant.
Vinayak KumbarSr Program ManagerCommented:

U can call the class's member function from the call back function. As I have suggested U, say u have callback function MyTimerProc for App class CCallbackApp. Now in the callback function u can call the app class member as

CCallbackApp *pApp = (CCallbackApp *)AfxGetApp();

Where OnEditCut() is the member function for CCallbackApp class.

Try it out.
Vinayak KumbarSr Program ManagerCommented:

Similarly U can access the mainframe's functions also. And to access the members of the different class, I have suggested the method in Ur's different question. Check it out.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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