title: Win32: Test if mouse has hovered for a second
body: <p>I'm trying to make a function that only runs when the mouse has stayed in the same place for an increment of time without stalling the program (so no <code>Sleep(1000)</code> functions). What I tried to do was have the callback run a function in paint when the mouse moves. In that function, there would be a while loop that makes sure the mouse didn't move since the last frame and break if clicked or moved. </p>
  
  <p>In the callback:</p>
  
  <pre><code>case WM_MOUSEMOVE:
      POINT pt;
      GetCursorPos(&amp;pt);
      ScreenToClient(hWnd, &amp;pt);
      iPosX = pt.x;
      iPosY = pt.y;
  
      if (!mouseMoved) {
          mouseMoved = true;
          period = 0;
          InvalidateRect(hWnd, 0, FALSE);
      }
      break;
  </code></pre>
  
  <p>In the Paint:</p>
  
  <pre><code>       if (mouseMoved &amp;&amp; !MouseClicked) {
  
              test.newBit(1, 100, 0, hdc); //Draws a picture as a test
  
              oldx = iPosX;
              oldy = iPosY;
  
              period = 0;
  
              while (period &lt;= 1000000 &amp;&amp; !MouseClicked) {
  
                  oldx = iPosX;
                  oldy = iPosY;
  
                  POINT pt;
                  GetCursorPos(&amp;pt);
                  ScreenToClient(hWnd, &amp;pt);
                  iPosX = pt.x;
                  iPosY = pt.y;
  
                  if (iPosX != oldx || iPosY != oldy) {
                      mouseMoved = false;
                      period = 0;
                      break;
                  }
  
                  period++;
              }
  
              if (period &lt;= 1000000) {
                  period = 0;
                  test.newBit(0, 0, 0, hdc); //Draws a picture as a test
                  mouseMoved = false;
              }
  
          }
  </code></pre>
  
  <p>This generates a random flashing when you move the mouse and click. Any insight into what I'm doing wrong would be appreciated.</p>