WaitFor.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Version : 2.3.15
  5. * Author : Bruce Liang
  6. * Website : http://www.jessma.org
  7. * Project : https://github.com/ldcsaa
  8. * Blog : http://www.cnblogs.com/ldcsaa
  9. * Wiki : http://www.oschina.net/p/hp-socket
  10. * QQ Group : 75375912
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #pragma once
  25. /* timeGetTime() 包装方法 */
  26. DWORD TimeGetTime();
  27. /**********************************
  28. 描述: 获取当前时间与原始时间的时间差
  29. 参数:
  30. dwOriginal : 原始时间(毫秒),通常用 timeGetTime() 或 GetTickCount() 获取
  31. 返回值: 与当前 timeGetTime() 之间的时间差
  32. **********************************/
  33. DWORD GetTimeGap32(DWORD dwOriginal);
  34. #if _WIN32_WINNT >= _WIN32_WINNT_WS08
  35. /**********************************
  36. 描述: 获取当前时间与原始时间的时间差
  37. 参数:
  38. ullOriginal : 原始时间(毫秒),通常用 GetTickCount64() 获取
  39. 返回值: 与当前 GetTickCount64() 之间的时间差
  40. **********************************/
  41. ULONGLONG GetTimeGap64(ULONGLONG ullOriginal);
  42. #endif
  43. /**********************************
  44. 描述: 处理Windows消息
  45. 参数:
  46. bDispatchQuitMsg : 是否转发 WM_QUIT 消息
  47. TRUE : 转发(默认)
  48. FALSE: 不转发,并返回 FALSE
  49. 返回值: TRUE : 收完消息
  50. FALSE : bDispatchQuitMsg 参数为 FALSE 并收到 WM_QUIT 消息
  51. **********************************/
  52. BOOL PeekMessageLoop(BOOL bDispatchQuitMsg = TRUE);
  53. /**********************************
  54. 描述: 等待指定时间, 同时处理Windows消息
  55. 参数: (参考: MsgWaitForMultipleObjectsEx() )
  56. dwHandles : 数组元素个数
  57. szHandles : 对象句柄数组
  58. dwMilliseconds : 等待时间 (毫秒)
  59. dwWakeMask : 消息过滤标识
  60. dwFlags : 等待类型
  61. 返回值: (0 ~ dwHandles - 1): 等待成功
  62. WAIT_TIMEOUT : 超时
  63. WAIT_FAILED : 执行失败
  64. **********************************/
  65. DWORD WaitForMultipleObjectsWithMessageLoop(DWORD dwHandles, HANDLE szHandles[], DWORD dwMilliseconds = INFINITE, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE);
  66. /**********************************
  67. 描述: 等待指定时间, 同时处理Windows消息
  68. 参数: (参考: MsgWaitForMultipleObjectsEx() )
  69. hHandle : 对象句柄
  70. dwMilliseconds : 等待时间 (毫秒)
  71. dwWakeMask : 消息过滤标识
  72. dwFlags : 等待类型
  73. 返回值: TRUE: 等待成功,FALSE: 超时
  74. **********************************/
  75. BOOL MsgWaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds = INFINITE, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE);
  76. /**********************************
  77. 描述: 等待指定时间, 同时处理Windows消息
  78. 参数: (参考: MsgWaitForMultipleObjectsEx() )
  79. dwMilliseconds : 等待时间 (毫秒)
  80. dwWakeMask : 消息过滤标识
  81. dwFlags : 等待类型
  82. 返回值: MsgWaitForMultipleObjectsEx() 函数的操作结果
  83. **********************************/
  84. void WaitWithMessageLoop(DWORD dwMilliseconds, DWORD dwWakeMask = QS_ALLINPUT, DWORD dwFlags = MWMO_INPUTAVAILABLE);
  85. /**********************************
  86. 描述: 等待用Sleep()函数等待某个变量小于指定值
  87. 参数:
  88. plWorkingItemCount : 监视变量
  89. lMaxWorkingItemCount : 指定值
  90. dwCheckInterval : 检查间隔 (毫秒)
  91. 返回值:
  92. **********************************/
  93. void WaitForWorkingQueue(long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval);
  94. /**********************************
  95. 描述: 等待用Sleep()函数等待某个变量减小到 0
  96. 参数:
  97. plWorkingItemCount : 监视变量
  98. dwCheckInterval : 检查间隔 (毫秒)
  99. 返回值:
  100. **********************************/
  101. void WaitForComplete (long* plWorkingItemCount, DWORD dwCheckInterval);
  102. /**********************************
  103. 描述: 等待用WaitWithMessageLoop()函数等待某个变量小于指定值
  104. 参数:
  105. plWorkingItemCount : 监视变量
  106. lMaxWorkingItemCount : 指定值
  107. dwCheckInterval : 检查间隔 (毫秒)
  108. 返回值:
  109. **********************************/
  110. void MsgWaitForWorkingQueue (long* plWorkingItemCount, long lMaxWorkingItemCount, DWORD dwCheckInterval = 10);
  111. /**********************************
  112. 描述: 等待用WaitWithMessageLoop()函数等待某个变量减小到 0
  113. 参数:
  114. plWorkingItemCount : 监视变量
  115. dwCheckInterval : 检查间隔 (毫秒)
  116. 返回值:
  117. **********************************/
  118. void MsgWaitForComplete (long* plWorkingItemCount, DWORD dwCheckInterval = 10);