MFC倒计时设计

新建一个mfc[exe]文件,在View类里添加WM_LBUTTONDOWN和M_TIMER消息。

在OnLButtonDown类里添加定时函数:SetTimer(1,1000,NULL);

在OnTimer(UINT nIDEvent)函数里添加以下代码:

 // TODO: Add your message handler code here and/or call default
 CDC *hdc;
 hdc=GetDC();
 CFont font;
 font.CreatePointFont(1000,   "MyFont");
 LOGFONT pLogFont;
 font.GetLogFont(&pLogFont);
 hdc->SelectObject(font);
 hdc->SetTextColor(RGB(255,0,0));
 CString str;
 char ch[2];
 itoa(m_iCount--,ch,10);
 str=ch;
 CBrush pBrush(RGB(255,255,255));
 CRect rect;
 GetClientRect(&rect);
 hdc->FillRect(rect,&pBrush);
 if(m_iCount>=0)
  hdc->TextOut((rect.left+rect.right)/2-50/*-pLogFont.lfWidth/2*/,(rect.top+rect.bottom)/2-50/*-pLogFont.lfHeight/2*/,str);
 else
 {
  hdc->TextOut((rect.left+rect.right)/2-120,(rect.top+rect.bottom)/2-80,"Boom!");
  KillTimer(1);
 }
 ReleaseDC(hdc);
 CView::OnTimer(nIDEvent);

 

编译运行,点击鼠标左键开始倒计时,呵呵,小小程序。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值