Quantcast
Channel: CodeGuru Forums - C++ and WinAPI
Viewing all articles
Browse latest Browse all 583

how change SetTimer() interval?

$
0
0
the gif animation can have a diferent delay between the frames. the SetTimer() makes a non Multimedia Timers.... the KillTimer() destroy the timer: https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx but: "The KillTimer function does not remove WM_TIMER messages already posted to the message queue." so.... how can i destroy the timer correctly?
Code:

//creating the timer using an invisible window:
timerid=SetTimer(WindowTimer, (UINT_PTR)this, intInterval,NULL);

//window procedure:
HANDLE myEvent = CreateEvent(NULL, TRUE, FALSE, NULL);     

static LRESULT CALLBACK TimerWindow(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)   
{       
      switch(msg)       
      {           
              case WM_TIMER:           
              {               
                        Timer* obj=(Timer*)wParam;               
                        if(obj->timerprocedure!=nullptr)               
                        {                   
                                  obj->timerprocedure();                   
                                  SetEvent(obj->myEvent);               
                        }               
                        else                   
                              DebugText("no timer");             
              }           
              break;           
              default:               
                      return DefWindowProc(hwnd, msg, wParam, lParam);       
      }       
      return DefWindowProc(hwnd, msg, wParam, lParam);   

//destroying the timer:
MsgWaitForMultipleObjects(1, &myEvent,FALSE, INFINITE, QS_TIMER);               
CloseHandle(myEvent);               
KillTimer(WindowTimer,(UINT_PTR)timerid);

i see some problems:
1 - when the window wins the focus, i lose 1 timer that change the window icon;
2 - another timer isn't executed. (if i use the same delay between the frames, no timers stops) so. how can i destroy a timer correctly? (for then create a new timer with a new interval)

(finally i edit the post.... i'm so sorry to all. i didn't these before because i was getting very problems)

Viewing all articles
Browse latest Browse all 583

Trending Articles