高精度多媒体时钟应用类
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
//多媒体高精度时钟应用类 ///////////////////////////////////////////// #include <MMSYSTEM.H> #pragma comment(lib, "WINMM.LIB") class CHighResolutionTimer { typedef void (*TIMERCALLBACK)(DWORD); private: DWORD m_dwUser; MMRESULT m_nIDTimer; UINT m_uDelay; TIMERCALLBACK m_pfnCallback; void KillTimer() { if(m_nIDTimer != NULL) { timeKillEvent(m_nIDTimer); m_nIDTimer = NULL; } } public: CHighResolutionTimer() { m_nIDTimer = NULL; m_uDelay = 0; m_pfnCallback = 0; } virtual ~CHighResolutionTimer() { KillTimer(); } static void CALLBACK TimeProc(UINT uID,UINT uMsg,DWORD dwUser,DWORD dw1, DWORD dw2) { // dwUser contains ptr to Timer object CHighResolutionTimer * ptimer = (CHighResolutionTimer *) dwUser; // Call user-specified callback and pass back user specified data (ptimer->m_pfnCallback) (ptimer->m_dwUser); } BOOL CreateTimer(DWORD dwUser,UINT uDelay,TIMERCALLBACK lpTimeProc) { ASSERT(dwUser); ASSERT(lpTimeProc); m_dwUser = dwUser; m_pfnCallback = lpTimeProc; BOOL ret = FALSE; KillTimer(); m_nIDTimer = timeSetEvent (uDelay, 0, TimeProc, (DWORD)this, TIME_PERIODIC | TIME_CALLBACK_FUNCTION); if(m_nIDTimer != NULL) ret = TRUE; return(ret); } }; CHighResolutionTimer mm_Timer; static void TimerCallback (DWORD dwUser); //应用 .cpp 定时器回调 void CMy_TimerDlg::TimerCallback (DWORD dwUser) { CMy_TimerDlg *pThis = (CMy_TimerDlg *)dwUser; // static long count = 0; CString str; str.Format("%d",count++); pThis->GetDlgItem(IDC_BUTTON1)->SetWindowText(str); Beep(1000,1); } //启动2毫秒定时器 void CMy_TimerDlg::OnButton1() { // TODO: Add your control notification handler code here // mm_Timer.CreateTimer((DWORD)this,2,TimerCallback); } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=810