现在的位置: 首页 > 综合 > 正文

用VC 6.0写flash播放器——3、使用定时器

2013年08月27日 ⁄ 综合 ⁄ 共 1071字 ⁄ 字号 评论关闭

purpleendurer 原创

2005.11.15 第1

我们已经为作为主窗口的对话框加入了状态栏。为了在状态栏的第二部分动态地显示当前播放的是第几帧,我们使用了定时器。

实现方法如下:

1。在CSwfPlayerDlg类定义中 加入定时器变量的声明,使用定时器的方法以及停止定时器的方法:

class CSwfPlayerDlg : public CDialog
{
....

protected:
 HICON m_hIcon;
 HWND m_hStatusWindow;
 UINT m_Timer1; //定时器变量的声明
.....

private:
 void UseTimer1(); //使用定时器
 void StopTimer1(); //停止定时器
};

2。UseTimer1()的代码为:

void CSwfPlayerDlg::UseTimer1()//使用定时器
{
 if (!m_Timer1)
 {
  SetTimer(m_Timer1, 500, NULL);
 }
}

3。StopTimer1()的代码为:

void CSwfPlayerDlg::StopTimer1()//如果定时器已经启用,则停止它
{
 if (m_Timer1)
 {
  KillTimer(m_Timer1);
  m_Timer1 = 0;
 }
}

4。在CSwfPlayerDlg的OnInitDialog()加初始化定时变量为0,表示未使用:

BOOL CSwfPlayerDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

..........

 m_Timer1 = 0;   //初始化定时器为未用

 return TRUE;  // return TRUE  unless you set the focus to a control
}

5。对定时器消息WM_TIMER的处理

void CSwfPlayerDlg::OnTimer(UINT nIDEvent)
{
 // TODO: Add your message handler code here and/or call default
 
 CDialog::OnTimer(nIDEvent);

 char buf[50];
 char fmt2[] = {"当前为第%d帧"};

 wsprintf(buf, fmt2, m_SwfBox.CurrentFrame());
 ::SendMessage(m_hStatusWindow, SB_SETTEXT, 1, (LPARAM)&buf); 
}

这样在我们需要使用定时器时就调用UseTimer1(),要停止定时器时就调用StopTimer1()。

抱歉!评论已关闭.