cncml手绘网
标题:
非滞后式延迟执行
[打印本页]
作者:
admin
时间:
2018-6-27 00:03
标题:
非滞后式延迟执行
方法如下
) F( `/ r3 X V3 p3 w. b7 v# `
建立 xsleep.cpp和xsleep.p文件
0 m7 z& A3 }" \" p# ^
xsleep.cpp文件代码如下
5 ^, o0 y* r4 Z2 g6 A- w
//Download by http://www.cncml.com
5 y7 [: Z9 R0 z# b$ M9 R
#include <windows.h>
% S" Q3 T+ z2 Y$ o( Z3 K) F6 O; b8 `
#include <stdafx.h>
* c% C% Z3 }1 J1 f$ t- r! J7 e
! C0 b$ G) o7 u; J, U1 d3 h: ?
// This structure is used internally by the XSleep function
$ ~* F. z8 g3 F' \& q
struct XSleep_Structure
* U. M4 h0 n( w/ k" V9 V4 @4 Y
{
! C/ r1 M8 Y/ I3 n7 @
int duration;
/ Y! b: y9 @# p7 _$ s: |1 ]" |* p
HANDLE eventHandle;
0 v( u ?" B: r1 Q. c3 H+ d
};
; ?+ u, Q8 ~7 @' x @% z) l0 d
5 ~4 T6 \7 W! `# {! b
/ k6 U3 _+ O8 u$ [1 l+ u' M2 ^. }
//////////////////////////////////////////////////////////////////////
7 Q: B: d! h3 v. |: ?
// Function : XSleepThread()
D. ]' \; Y+ ?
// Purpose : The thread which will sleep for the given duration
. Y- Q+ n- T. X& Q) @
// Returns : DWORD WINAPI
7 r4 P9 l" ?3 [8 ?; u
// Parameters:
# j \* P! ~7 r; g4 m
// 1. pWaitTime -
* U+ A& Z4 _: [8 M8 g8 ?
//////////////////////////////////////////////////////////////////////
3 V9 R$ \; R9 I: k8 T3 g
DWORD WINAPI XSleepThread(LPVOID pWaitTime)
: R, K8 b6 Y0 D3 Y; V! p
{
& D8 E8 p' v- U1 U$ w) ?% {
XSleep_Structure *sleep = (XSleep_Structure *)pWaitTime;
$ Y* r5 Q3 }! H/ j0 C2 N
M2 _ a7 z3 {8 U5 u5 B
Sleep(sleep->duration);
6 V d: T0 V9 V$ k1 D
SetEvent(sleep->eventHandle);
5 Z6 e5 g+ L7 X6 L
0 b; ^* l; w& f& U. D7 G4 d
return 0;
" ?, m( K3 x4 j- D+ ]. o7 g
}
a8 O8 D. a7 h0 m
& A1 E f3 w4 G: _3 T1 z
//////////////////////////////////////////////////////////////////////
) a7 c2 s Z$ ^: L1 C
// Function : XSleep()
' n( Y5 B* N, x) ^/ @
// Purpose : To make the application sleep for the specified time
) o" k: O7 ?* M# R) Y3 F, {$ F
// duration.
. d" N5 x& ?; A0 m4 W' p& {/ ^' |
// Duration the entire time duration XSleep sleeps, it
9 Z. v& I# T8 f/ O+ y! X/ Z# y( H
// keeps processing the message pump, to ensure that all
4 c5 w& B# j/ X; N x$ o
// messages are posted and that the calling thread does
3 b+ f$ N# U$ c7 W
// not appear to block all threads!
1 j% F2 _8 o& o! M6 F
// Returns : none
+ v& i1 M" i/ ~( W
// Parameters:
9 \: f8 n1 Q4 {5 x% n8 X8 g
// 1. nWaitInMSecs - Duration to sleep specified in miliseconds.
) p& T, t) c! t5 h9 O
//////////////////////////////////////////////////////////////////////
/ P r! l& P) T: `- R% R* d. c, K
void XSleep(int nWaitInMSecs,int nAscll)
; r2 Z$ n3 d! c9 _) V: m1 q2 k
{
: n7 }: M- Z' _
6 Y$ i( T' ~# C8 b
<blockquote><span class="Apple-tab-span" style="white-space:pre"> </span>INPUT input[2];
复制代码
$ N4 D2 K% l9 v& k
. n; b' g; z8 |. j+ G
xsleep.h文件代码
, p& _7 z: I" |! @7 C2 Z
/ e) K# C3 m2 D) E
//Download by http://www.cncml.com
6 i" n( p% T+ C5 b' R8 @9 a
#ifndef _XSLEEP_H_
) q& }1 w, P; L( ~' E1 y
#define _XSLEEP_H_
5 e' `1 S H( T6 k( D1 r6 V( ]
& \* n8 J6 Y R& ~; Y$ a
void XSleep(int nWaitInMSecs, int nAscll);
' ~4 I2 r. D: w, d! ^9 _1 f
# }4 b0 t0 C1 a' O
#endif // _XSLEEP_H_
( H1 A- ^, [7 k. _: ~ |
复制代码
8 s) c. |( \7 d" m, M1 C5 f5 y5 w ?
8 Y! e* h$ P L3 v
mfc中的调用代码如下
9 ]6 a) C6 V9 S) C/ [
int ascll;
复制代码
XSleep(500,ascll);
复制代码
0 u% J+ L. j& j; s) Q' m% ^# z3 ~
6 U4 c2 O5 O3 n! G
欢迎光临 cncml手绘网 (http://bbs.cncml.com/)
Powered by Discuz! X3.2