vc6
做篮球24秒倒计时
i的初值为24void CTestDlg::OnTimer(UINT nIDEvent)
{
if(i<=0)
{
MessageBox("OK");
}
i--;
}
void CTestDlg::OnButton1()
{ SetTimer(1,1000,NULL);
OnTimer(1);
}结果按下Button1后立即弹出OK的框子,应该如何修改?
做篮球24秒倒计时
i的初值为24void CTestDlg::OnTimer(UINT nIDEvent)
{
if(i<=0)
{
MessageBox("OK");
}
i--;
}
void CTestDlg::OnButton1()
{ SetTimer(1,1000,NULL);
OnTimer(1);
}结果按下Button1后立即弹出OK的框子,应该如何修改?
这样系统就会自动在你申请了时钟后,按照你所说的间隔,找到OnTimer函数(当然OnTimer函数也需要申明到afx_msg那一代)
这样才可以。
你在申请了时钟后,就不用调用OnTimer(1)。而是等系统调用。
不然,你申请的时候就不管用了。
{
SetTimer(1,1000,NULL);
}
你在OnButton1() 设定SetTimer(1,1000,NULL);肯定是按住BUTTON键的时间里响应定时事件,最好不要这样响应定时吧。不太明白的你的意思,是不是按下BUTTON之后开始计时呢?你试下这样呢?
void CTestDlg::OnTimer(UINT nIDEvent)
{
MessageBox("OK");
}void CTestDlg::OnButton1()
{ SetTimer(1,24000,NULL);
OnTimer(1);
}
文本好说,就是不会用计时器。在宏定义的地方添加宏ON_WM_TIMER() ,还是不能计时,一按Button1就弹出了OK。24小时后一定追加100分!
{
// TODO: Add your control notification handler code here
m_timer=24;
SetTimer(0, 1000, NULL);
}void CTimmDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
--m_timer;
if(m_timer == 0)
{
AfxMessageBox("OK!");
m_timer = 24;
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
是对应的显示跑秒的edit对应的变量
需要你添加ddx语句
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTimmDlg)
DDX_Text(pDX, IDC_EDIT1, m_timer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTimmDlg, CDialog)
//{{AFX_MSG_MAP(CTimmDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CTimmDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_timer = 25;
SetTimer(0, 1000, NULL);
}void CTimmDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
--m_timer;
if(!(m_timer < 0 || m_timer > 24))
{
UpdateData(FALSE);
if(m_timer == 0)
{
AfxMessageBox("OK!");
KillTimer(0);
m_timer = 24;
UpdateData(FALSE);
}
}
CDialog::OnTimer(nIDEvent);
}
Invalidate 在OnTimer函数末尾调用下
Invalidate 在OnTimer函数末尾调用下
HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime
);
//在OnButton1里面这样用
SetTimer(1, 1000, MyTimerProc);