How to use CWnd::SetTimer() in a worker thread?

Hi all, first time posting and i am totally new to visual C++.

  I am creating a game and the screen require constant redraw. I implemented the ON_WM_TIMER()function so that it will set off my OnTimer function in my dialog class using SetTimer(...) function. It works fine, just that my game run way too slow.
  I thought of calling the SetTimer in a seperate thread function. Will it help? I can't seems to get it to work. All i did was this:

class CClienttestDlg : public CDialog {


CWinThread*     mThread;
static UINT CClienttestDlg::StartTimer(LPVOID pParam)

BOOL CClienttestDlg::OnInitDialog()

mThread = AfxBeginThread(CClienttestDlg::StartTimer,(LPVOID)myTimerID);

UINT CClienttestDlg::StartTimer(LPVOID pParam) {
          // -- set the timer
     uResult = SetTimer((UINT)pParam, (1000/frame_rate), NULL);
     return 0 ;

the error is that i cannot use a non static function in my thread. is there anyway i can slove my problem? thanks

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.

you can use multimedia timers

The timeSetEvent function starts a specified timer event. The multimedia timer runs in its own thread. After the event is activated, it calls the specified callback function or sets or pulses the specified event object.

MMRESULT timeSetEvent(
 UINT uDelay,                
 UINT uResolution,          
 DWORD dwUser,              
 UINT fuEvent                

or you can create a thread of your own and control a timer there (see link below) 

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
create a structure for passing thread arguments
UINT m_nTimerID;
CClienttestDlg *m_pDlg;

FIll this struct and passs it as arg.

pThreadInfo->m_nTimerID = myTimerID;
pThreadInfo->m_pDlg = this;
mThread = AfxBeginThread(CClienttestDlg::StartTimer,(LPVOID)pThreadInfo);

Then, in therad function

UINT CClienttestDlg::StartTimer(LPVOID pParam) {
         // -- set the timer
THREADINFO *pThreadInfo = static_cast<THREEADINFO*>(pParam);
    uResult = pThreadInfo->m_pDlg->SetTimer((UINT)pThreadInfo->m_nTimerID, (1000/frame_rate), NULL);
delete pThreadInfo;
    return 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.

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.