title: C++/Win32 How to load a function every second
body: <p>I am writing a program in which I want to call a function every second. I use GetSystemTime() to get the time and I have stated an if to check whether the previous second is equal to the current second or not, and if it isn't, load the function. Here's the code:</p>
  
  <pre><code>int prevsec = cursec;
  SYSTEMTIME systime;
  GetSystemTime(&amp;systime);
  cursec = systime.wSecond;
  curmsec = systime.wMilliseconds;
  if ( curmsec - prevmsec &gt; 100 )
  {
      prevmsec = curmsec;
      startgame();
  }
  if ( prevsec != cursec )
  {
      prevmsec = 0;
      startfunction();
  }
  </code></pre>
  
  <p>My only problem is, I don't know where to put it; if I put it at the beginning of my Windows Procedure, as I currently have, it will check if it should load the function every time a new message is sent, therefore when the window is open and you aren't doing anything, it won't check if the time has changed and therefore it won't work properly. I want to know if there is a place where I can put the code so it just keeps on checking the time (like in a infinite while loop) without seeing the "not responding" message. I hope you understood the question, thank you :)</p>