title: SetTimer vs CWnd::SetTimer
body: <h3>Background</h3>
  
  <p>MFC's <code>CWnd::SetTimer</code> calls WinAPI's <code>SetTimer</code> simply.</p>
  
  <pre><code>_AFXWIN_INLINE UINT_PTR CWnd::SetTimer(UINT_PTR nIDEvent, UINT nElapse,
          void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD))
      { ASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse,
          lpfnTimer); }
  </code></pre>
  
  <p>But <a href="https://msdn.microsoft.com/en-us/library/ms644906(v=vs.85).aspx" rel="nofollow noreferrer">SetTimer</a> and <a href="https://docs.microsoft.com/en-us/cpp/mfc/reference/cwnd-class#settimer" rel="nofollow noreferrer">CWnd::SetTimer</a> documents are not same.</p>
  
  <h3>1. <code>nIDEvent</code> parameter</h3>
  
  <blockquote>
    <p><code>SetTimer</code>:<br>
    If the <em>hWnd</em> parameter is not <strong>NULL</strong> and the window specified by <em>hWnd</em> already has a timer with the value <em>nIDEvent</em>, then the existing timer is replaced by the new timer. When <strong>SetTimer</strong> replaces a timer, the timer is reset.</p>
    
    <p><code>CWnd::SetTimer</code>:<br>
    Specifies a nonzero timer identifier. If the timer identifier is unique, this same value is returned by <code>SetTimer</code>. Otherwise, <code>SetTimer</code> determines a new unique value and returns that. For a window timer (which has a NULL callback function), the value must be unique only for other windows timers that are associated with the current window. For a callback timer, the value must be unique for all timers in all processes. Therefore, when you create a callback timer, it is more likely that the returned value might differ from the value you specify.</p>
  </blockquote>
  
  <p><code>SetTimer</code> does not depend on callback parameter and always replaces the existing timer. But <code>CWnd::SetTimer</code> depends on callback parameter, and if callback specified, a new timer ID may be generated because <strong>the value must be unique for all timers in all processes</strong>.</p>
  
  <h3>2. Return value</h3>
  
  <blockquote>
    <p><code>SetTimer</code>:<br>
    If the function succeeds and the <em>hWnd</em> parameter is not <strong>NULL</strong>, then the return value is a nonzero integer. An application can pass the value of the <em>nIDEvent</em> parameter to the <strong>KillTimer</strong> function to destroy the timer.</p>
    
    <p><code>CWnd::SetTimer</code>:<br>
    The timer identifier of the new timer if the function is successful. This value may or may not be equal to the value passed in through the <code>nIDEvent</code> parameter. An application should always pass the return value to the KillTimer member function to kill the timer.</p>
  </blockquote>
  
  <p><code>SetTimer</code> does not generate new timer id and does not return timer id, so call <code>KillTimer</code> with <code>nIDEvent</code> parameter. But <code>CWnd::SetTimer</code> generates new timer id in some case, so call <code>KillTimer</code> with the returned value.</p>
  
  <p>Thus, which document is correct?</p>
  
  <hr>
  
  <p>I want to use WinAPI <code>SetTimer</code> with a callback and it works on my pc. But if some platform does not replace the existing timer, I could not accept the callback timer.</p>