Are you having trouble using settimer () for an MFC application

I have set this code so that I have a timer to play with the minesweeper, but I cannot compile it.

    void CALLBACK CMineSweeperBoard::clock(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
    if (t_seconds < 59){ t_seconds++; }
    else{
     t_minutes++;
     t_seconds = 0;
    }   
}

void CMineSweeperBoard::timer(void)
{
    MSG msg;

    SetTimer(NULL, 0, 1000, (TIMERPROC) &clock);
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
}

      

The problem seems to be related to the arguments in the set timer function, but I can't figure out what that is, any help would be appreciated.

+3


source to share


1 answer


You need SetTimer

, KillTimer

and ON_WM_TIMER()

. See the example at the bottom of this page: https://msdn.microsoft.com/en-us/library/49313fdf.aspx

Don't put a message loop there While(GetMessage()...)



You can start a 1 second timer by calling SetTimer(1, 1000, NULL);

Then add ON_WM_TIMER()

to the message map that passes the result to void CMyWnd::OnTimer(UINT nIDEvent)

This way you don't need to define your own TimerProc

Or you can provide your own TimerProc, but the TimerProc function must be declared as . This can be inconvenient because static member functions cannot access the item's data. It would be easier to use . static

WM_TIMER

+4


source







All Articles