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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.