how to call a callback function?

I want to call a callback function in SetTimer(....). How can I call this and what parameters I should put?
The callback function is:
void CALLBACK EXPORT TimeProc(HWND hWnd,UINT nMsg,UINT nIDEvent,DWORD dwTime);


makoto_liangAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Vinayak KumbarConnect With a Mentor Sr Program ManagerCommented:
Hi,

declare the function as global as
void CALLBACK MyTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime );

Then U Set the timer with this callback as

HWND hWnd;
hWnd = GetActiveWindow();
::SetTimer(hWnd, 500, duration, MyTimerProc);

Then write the call back function as

void CALLBACK MyTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
   hWnd = GetActiveWindow();
   KillTimer(hWnd, 500);
   return ;
}

Thats it.

Hope that helps.
0
 
makoto_liangAuthor Commented:
Can I call the callback function without seting up global callback function?
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

U can do that also. U have to declare that function as static
I have done it in App class.h as
static void CALLBACK MyTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime );

Then setting the timer remains same.
The function will be associated with the class name now

void CALLBACK CCallbackApp::MyTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
      hWnd = GetActiveWindow();
      KillTimer(hWnd, 500);
      return ;
}

where CCallbackApp is my App class.
Try it out.
0
 
makoto_liangAuthor Commented:
Hi, apart from setting the callback function as Static, is there any way to set it inside a class? Coz I have to access another class function in callback function of SetTimer!
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

No Prob. U can acces it. Say I have a dialog os class CMyDlg and I want to display it in CALLBACK function. Then add mydlg.h to the Callback.cpp (class implementation file for which CALLBACK function is a member)file

void CALLBACK CCallbackApp::MyTimerProc(HWND hWnd, UINT uMsg,  UINT idEvent, DWORD dwTime )
{
hWnd = GetActiveWindow();
KillTimer(hWnd, 500);
CMyDlg dlg;
dlg.DoModal();
return ;
}

Thats it. U can access other class functions even if the CALLBACK function is static.

Try it out.
VinExpert
0
All Courses

From novice to tech pro — start learning today.