您尚未登录,请登录后浏览更多内容! 登录 | 立即注册

QQ登录

只需一步,快速开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

cncml手绘网 首页 站长博文 学习笔记 查看内容

[C++学习资料]非滞后式延迟执行

2019-11-1 11:57| 发布者: admin| 查看: 422| 评论: 0|原作者: admin

摘要: 非滞后式延迟执行
方法如下
建立 xsleep.cpp和xsleep.p文件
xsleep.cpp文件代码如下
  1. //Download by http://www.cncml.com
  2. #include
  3. #include

  4. // This structure is used internally by the XSleep function
  5. struct XSleep_Structure
  6. {
  7.         int duration;
  8.         HANDLE eventHandle;
  9. };


  10. //////////////////////////////////////////////////////////////////////
  11. // Function  : XSleepThread()
  12. // Purpose   : The thread which will sleep for the given duration
  13. // Returns   : DWORD WINAPI
  14. // Parameters:      
  15. //  1. pWaitTime -
  16. //////////////////////////////////////////////////////////////////////
  17. DWORD WINAPI XSleepThread(LPVOID pWaitTime)
  18. {
  19.         XSleep_Structure *sleep = (XSleep_Structure *)pWaitTime;

  20.         Sleep(sleep->duration);
  21.         SetEvent(sleep->eventHandle);

  22.         return 0;
  23. }

  24. //////////////////////////////////////////////////////////////////////
  25. // Function  : XSleep()
  26. // Purpose   : To make the application sleep for the specified time
  27. //             duration.
  28. //             Duration the entire time duration XSleep sleeps, it
  29. //             keeps processing the message pump, to ensure that all
  30. //             messages are posted and that the calling thread does
  31. //             not appear to block all threads!
  32. // Returns   : none
  33. // Parameters:      
  34. //  1. nWaitInMSecs - Duration to sleep specified in miliseconds.
  35. //////////////////////////////////////////////////////////////////////
  36. void XSleep(int nWaitInMSecs,int nAscll)
  37. {
  38.                
  39.         INPUT input[2];
复制代码


xsleep.h文件代码

  1. //Download by http://www.cncml.com
  2. #ifndef _XSLEEP_H_
  3. #define _XSLEEP_H_

  4. void XSleep(int nWaitInMSecs, int nAscll);

  5. #endif // _XSLEEP_H_
复制代码


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



鲜花

握手

雷人

路过

鸡蛋

最新评论

关闭

站内最热文章上一条 /1 下一条

GMT+8, 2024-4-24 14:00 , Processed in 0.147043 second(s), 38 queries .

Copyright © 2001-2024 Powered by cncml! X3.2. Theme By cncml!