This one's driving me nuts. I have a FormView app that contains a "Suspend" button. When "Suspend" is pressed, I want the title bar to flash a message, 500 msec on, 500 msec off. Which it does, for a while (several minutes to several hours).

But then the flashing stops. Indications are that the interval timer isn't firing for several seconds. Has anybody run into this sort of problem before?

Here's the relevant portion of my OnSuspendButton routine:
Code:
for( m_FlashTimer = 1; m_FlashTimer < 100; ++m_FlashTimer )
{
  if( SetTimer( m_FlashTimer, 500, NULL ) break;
}
if( m_FlashTimer >= 100 ) m_FlashTimer = 0;    // No timers available
And the OnTimer routine:
Code:
void CMyView::OnTimer(UINT nIDEvent) 
{
  if( nIDEvent == m_FlashTimer )
  {
    // DEBUG - Find out if the timer is failing to fire
    static CTime old_time = CTime::GetCurrentTime();
    CTime new_time = CTime::GetCurrentTime();
    if( new_time - old_time > 1 )
    {
      Log.Write( "Timer interrupt is late.", 2 );
    }
    old_time = CTime::GetCurrentTime();

    // Flash the title bar for "suspend"
    m_bToggleFlash = !m_bToggleFlash;
    CMainFrame *pFrame = (CMainFrame *)GetParentFrame();
    if( pFrame == NULL )
    {
      Log.Write( "GetParentFrame has failed.", 2 );
    }
    else
    {
      if( pFrame->SendMessage( WM_NCPAINT, 1 ) != 0 )
        Log.Write( "SendMessage( WM_NCPAINT ) has failed.", 2 );
    }
    return;
  }
And, finally, CMainFrm's OnNcPaint:
Code:
void CMainFrame::OnNcPaint() 
{
  CWindowDC	dc( this );
  CRect		TitleBar;
  int		nTitleHeight;

  // Find the size of the title bar
  GetWindowRect( &TitleBar );		// The total window size

  // Paint the non-title bar
  HRGN hRgnTitle = ::CreateRectRgnIndirect( &TitleBar );
  DefWindowProc( WM_NCPAINT, (WPARAM)hRgnTitle, NULL );
  DeleteObject( hRgnTitle );

  if( ((CMyView *)GetActiveView())->m_bToggleFlash )
  {
    Log.Write( "Display normal title bar", 2 );
    return;
  }

  // Paint the title bar
  nTitleHeight = ::GetSystemMetrics( SM_CYSIZE ) + ::GetSystemMetrics( SM_CYFRAME );
  TitleBar = CRect( ::GetSystemMetrics( SM_CXFRAME ), ::GetSystemMetrics( SM_CYFRAME ), TitleBar.right - TitleBar.left - ::GetSystemMetrics( SM_CXFRAME ), nTitleHeight );

  CFont Font;
  Font.CreateFont( TitleBar.Height(), 0, 0, 0, FW_BOLD, FALSE, FALSE, NULL, NULL, NULL, NULL, NULL, NULL, "Arial" );
  CFont *pOldFont = dc.SelectObject( &Font );
  if( pOldFont == NULL )
  {
    Log.Write( "SelectObject failed", 2 );
    return;
  }
  CString szText = "OPERATION SUSPENDED";
  dc.SetBkColor( RGB( 255, 255, 0 ) );
  dc.SetTextColor( RGB( 255, 0, 0 ) );
  CPoint pt = dc.GetTextExtent( szText );
  int x = TitleBar.left + ( TitleBar.Width() - pt.x ) / 2;
  int y = TitleBar.top + ( TitleBar.Height() - pt.y ) / 2;
  if( !dc.ExtTextOut( x, y, ETO_OPAQUE, &TitleBar, szText, NULL ) )
  {
    Log.Write( "ExtTextOut failed.", 2 );
  }
  dc.SelectObject( pOldFont );
  return;
}