例子定时器事件处理文字颜色变化。
文字颜色随着时间的推移,字体颜色逐渐变化。
1 void CTimerOnTimerDlg::OnTimer(UINT_PTR nIDEvent) 2 { 3 // TODO: 在此添加消息处理程序代码和/或调用默认值 4 CString str; 5 static LONG CNT=0,i=0,j=0,k=255; 6 str.Format(_T("%d"), ++CNT); 7 m_Edit1 = str; 8 SetDlgItemText(IDC_EDIT1, m_Edit1); 9 CDC* pDC = GetDC(); 10 CFont *oldfont = pDC->SelectObject(&font); 11 if (CNT < 255) 12 { 13 pDC->SetTextColor(RGB(++i, 0, --k)); 14 pDC->TextOut(100, 100, _T("hello world.")); 15 } 16 else if (CNT < 255*2) 17 { 18 pDC->SetTextColor(RGB(--i, ++j, 0)); 19 pDC->TextOut(100, 100, _T("hello world.")); 20 } 21 else if (CNT < 255*3) 22 { 23 pDC->SetTextColor(RGB(0, --j, ++k)); 24 pDC->TextOut(100,100,_T("hello world.")); 25 } 26 else 27 { 28 CNT = 0; 29 i = 0; 30 j = 0; 31 } 32 33 34 CDialogEx::OnTimer(nIDEvent); 35 }
谢谢.