封装了一个类,为了对大限度的降低耦合,简化使用时的编码,决定使用下可等待计时器,以替换掉OnTimer。各种资料上面说的不够完整,大多也是抄袭的,所以打算自己看下原文API,顺便翻译下。
====================出双入对的分割线======================
原文来自MSDN,原文链接:http://msdn.microsoft.com/en-us/library/windows/desktop/ms682492%28v=vs.85%29.aspx
本文仅作翻译、注释。
本文链接:http://blog.csdn.net/wlsgzl/article/details/38872123
转载请保持文章的完整性,并在显要的注明作者和出处。
-------------------------------------秀恩爱 分的快--------------------------------------
CreateWaitableTimer Function |
Creates or opens a waitable timer object.
To specify an access mask for the object, use the CreateWaitableTimerEx function.
HANDLE WINAPI CreateWaitableTimer(//防盗,本文作者http://blog.csdn.net/wlsgzl _In_opt_ LPSECURITY_ATTRIBUTES lpTimerAttributes, _In_ BOOL bManualReset, _In_opt_ LPCTSTR lpTimerName );
A pointer to a SECURITY_ATTRIBUTES structure that specifies a security descriptor for the new timer object and determines whether child processes can inherit the returned handle.
If lpTimerAttributes is NULL, the timer object gets a default security descriptor and the handle cannot be inherited. The ACLs in the default security descriptor for a timer come from the primary or impersonation token of the creator.
If this parameter is TRUE, the timer is a manual-reset notification timer. Otherwise, the timer is a synchronization timer.
The name of the timer object. The name is limited to MAX_PATH characters. Name comparison is case sensitive.
If lpTimerName is NULL, the timer object is created without a name.
If lpTimerName matches the name of an existing event, semaphore, mutex, job, or file-mapping object, the function fails andGetLastError returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.
The name can have a "Global\" or "Local\" prefix to explicitly create the object in the global or session namespace. The remainder of the name can contain any character except the backslash character (\). For more information, seeKernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
The object can be created in a private namespace. For more information, see Object Namespaces.
If the function succeeds, the return value is a handle to the timer object. If the named timer object exists before the function call, the function returns a handle to the existing object andGetLastError returns ERROR_ALREADY_EXISTS.
If the function fails, the return value is NULL. To get extended error information, callGetLastError.
The handle returned by CreateWaitableTimer is created with theTIMER_ALL_ACCESS access right; it can be used in any function that requires a handle to a timer object, provided that the caller has been granted access. If a timer is created from a service or thread that is impersonating a different user, you can either apply a security descriptor to the timer when you create it, or change the default security descriptor for the creating process by changing its default DACL. For more information, seeSynchronization Object Security and Access Rights.
Any thread of the calling process can specify the timer object handle in a call to one of thewait functions.
Multiple processes can have handles to the same timer object, enabling use of the object for interprocess synchronization.
Use the CloseHandle function to close the handle. The system closes the handle automatically when the process terminates. The timer object is destroyed when its last handle has been closed.
To compile an application that uses this function, define _WIN32_WINNT as 0x0400 or later. For more information, seeUsing the Windows Headers.
To associate a timer with a window, use the SetTimer function.
For an example that uses CreateWaitableTimer, see Using Waitable Timer Objects.(本文链接http://blog.csdn.net/wlsgzl/article/details/38872123)
Minimum supported client |
Windows XP [desktop apps only] |
---|---|
Minimum supported server |
Windows Server 2003 [desktop apps only] |
Header |
|
Library |
|
DLL |
|
Unicode and ANSI names |
CreateWaitableTimerW (Unicode) and CreateWaitableTimerA (ANSI) |