您当前的位置 :首页 > 学习资料 > 非滞后式延迟执行
投稿

非滞后式延迟执行

2021-03-22 00:13:48 来源: 作者: 责任编辑:cncml

方法如下
建立 xsleep.cpp和xsleep.p文件
xsleep.cpp文件代码如下
  1. //Download by http://www.cncml.com
  2. #include <windows.h>
  3. #include <stdafx.h>
  4.  
  5. // This structure is used internally by the XSleep function
  6. struct XSleep_Structure
  7. {
  8.         int duration;
  9.         HANDLE eventHandle;
  10. };
  11.  
  12.  
  13. //////////////////////////////////////////////////////////////////////
  14. // Function  : XSleepThread()
  15. // Purpose   : The thread which will sleep for the given duration
  16. // Returns   : DWORD WINAPI
  17. // Parameters:      
  18. //  1. pWaitTime -
  19. //////////////////////////////////////////////////////////////////////
  20. DWORD WINAPI XSleepThread(LPVOID pWaitTime)
  21. {
  22.         XSleep_Structure *sleep = (XSleep_Structure *)pWaitTime;
  23.  
  24.         Sleep(sleep->duration);
  25.         SetEvent(sleep->eventHandle);
  26.  
  27.         return 0;
  28. }
  29.  
  30. //////////////////////////////////////////////////////////////////////
  31. // Function  : XSleep()
  32. // Purpose   : To make the application sleep for the specified time
  33. //             duration.
  34. //             Duration the entire time duration XSleep sleeps, it
  35. //             keeps processing the message pump, to ensure that all
  36. //             messages are posted and that the calling thread does
  37. //             not appear to block all threads!
  38. // Returns   : none
  39. // Parameters:      
  40. //  1. nWaitInMSecs - Duration to sleep specified in miliseconds.
  41. //////////////////////////////////////////////////////////////////////
  42. void XSleep(int nWaitInMSecs,int nAscll)
  43. {
  44.                
  45. <blockquote><span class="Apple-tab-span" style="white-space:pre">        </span>INPUT input[2];
复制代码


xsleep.h文件代码
 
  1. //Download by http://www.cncml.com
  2. #ifndef _XSLEEP_H_
  3. #define _XSLEEP_H_
  4.  
  5. void XSleep(int nWaitInMSecs, int nAscll);
  6.  
  7. #endif // _XSLEEP_H_
  8.  
复制代码


mfc中的调用代码如下
  1. int ascll;
复制代码
  1. XSleep(500,ascll);
复制代码

 
文章来源: 责任编辑:cncml
版权声明:
1、本主题所有言论和图片纯属会员个人意见,与本网站立场无关
2、本站所有主题由该文章作者发表,该文章作者与享有文章相关版权
3、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和的同意
4、文章作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任
5、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
6、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
7、管理员和版主有权不事先通知发贴者而删除本文
不良信息举报信箱 新闻热线:18733599993 技术服务:18733599993 网上投稿
关于本站 | 广告服务 | 免责申明 | 招聘信息 | 联系我们
在线网 版权所有 Copyright(C)2005-2025