睡眠与唤醒(100分)

  • 主题发起人 主题发起人 yihui
  • 开始时间 开始时间
Y

yihui

Unregistered / Unconfirmed
GUEST, unregistred user!
请问各位两个问题:
1:如何用程序使计算机进入睡眠状态?
2:如何用程序使在睡眠状态的计算机唤醒?
 
1.?
2.已经睡眠了,程序就不工作了,如何唤醒计算机?我认为不能!
 
这涉及到系统深层次的东西,不好办
 
1.把计算机的时间改成半夜12:00,计算机就睡了。
2.编个程序使桌子晃一下就醒了。
^_^
开个玩笑。
 
>1:如何用程序使计算机进入睡眠状态?
我估计也就是一两条API指令的问题!
谁有本事跟踪一下开始菜单上“睡眠”菜单被点击
后,所发出来的指令?
 
EASY!

sleep:

SetSystemPowerState(True,False);

wakeup:

CreateWaitableTimer;
SetWaitableTimer;
 
menxin真厉害。
 
>>menxin真厉害。
呵呵,现在才知道? 像menxin这样的高手轻易是不开口的,哪像我,走哪儿都要
插一杠子,也不管懂不懂...惭愧.

不过menxin最近来的次数越来越少了.
 
希望能把高手们留住。
我们的大富翁才有前途。
 
多谢menxin.
我在help中找到了setsystempowerstate,但是没有找到CreateWaitableTimer;
SetWaitableTimer,能具体点吗?
 
New - Windows NT]

The CreateWaitableTimer function creates a "waitable" timer object.

HANDLE CreateWaitableTimer(

LPSECURITY_ATTRIBUTES lpTimerAttributes, // pointer to security attributes
BOOL bManualReset, // flag for manual reset state
LPCTSTR lpTimerName // pointer to timer object name
);


Parameters

lpTimerAttributes

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.

bManualReset

Specifies the timer type. If bManualReset is TRUE, the timer is a manual-reset notification timer. Otherwise, the timer is a synchronization timer.

lpTimerName

Points to a null-terminated string specifying the name of the timer object. The name is limited to MAX_PATH characters and can contain any character except the backslash path-separator character (/). Name comparison is case sensitive.

If the string specified in the lpTimerName parameter matches the name of an existing named timer object, the call returns successfully and the GetLastError function returns ERROR_ALREADY_EXISTS.
If lpTimerName is NULL, the timer object is created without a name.
If lpTimerName matches the name of an existing event, semaphore, mutex, or file-mapping object, the function fails and GetLastError returns ERROR_INVALID_HANDLE. This occurs because event, semaphore, mutex, file-mapping, and waitable-timer objects share the same name space.



Return Values

If the function succeeds, the return value is a handle to the timer object. If the named timer object exists before the function call, GetLastError returns ERROR_ALREADY_EXISTS. Otherwise, GetLastError returns zero.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The handle returned by CreateWaitableTimer is created with the TIMER_ALL_ACCESS access right. This handle can be used in any function that requires a handle to a timer object.
Any thread of the calling process can specify the timer object handle in a call to one of the wait functions.
Multiple processes can have handles to the same timer object, enabling use of the object for interprocess synchronization.

?A process created by the CreateProcess function can inherit a handle to a timer object if the lpTimerAttributes parameter of CreateWaitableTimer enables inheritance.
?A process can specify the timer object handle in a call to the DuplicateHandle function. The resulting handle can be used by another process.
?A process can specify the name of a timer object in a call to the OpenWaitableTimer or CreateWaitableTimer function.



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.
 
[New - Windows NT]

The SetWaitableTimer function activates the specified "waitable" timer. When the due time arrives, the timer is signaled and the thread that set the timer calls the optional completion routine.

BOOL SetWaitableTimer(

HANDLE hTimer, // handle to a timer object
const LARGE_INTEGER *pDueTime, // when timer will become signaled
LONG lPeriod, // periodic timer interval
PTIMERAPCROUTINE pfnCompletionRoutine, // pointer to the completion routine
LPVOID lpArgToCompletionRoutine, // data passed to the completion routine
BOOL fResume // flag for resume state
);


Parameters

hTimer

Identifies the timer object. The CreateWaitableTimer or OpenWaitableTimer function returns this handle.

pDueTime

Specifies when the state of the timer is to be set to signaled, in 100 nanosecond intervals. Use the format described by the FILETIME structure. Positive values indicate absolute time. Negative values indicate relative time. The actual timer accuracy depends on the capability of your hardware.

lPeriod

Specifies the period of the timer, in milliseconds. If lPeriod is zero, the timer is signaled once. If lPeriod is greater than zero, the timer is periodic. A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the CancelWaitableTimer function or reset using SetWaitableTimer. If lPeriod is less than zero, the function fails.

pfnCompletionRoutine

Specifies an optional completion routine. The completion routine has the following prototype:

VOID
(APIENTRY *PTIMERAPCROUTINE)(
LPVOID lpArgToCompletionRoutine,
DWORD dwTimerLowValue,
DWORD dwTimerHighValue
);


The argument for the completion routine is specified when the timer is made active, in the lpArgToCompletionRoutine parameter. The completion routine also takes two DWORD values that specify the high and low time values of the time at which the timer was signaled. These values are passed to the routine by the system using the FILETIME format..

lpArgToCompletionRoutine

Pointer to the structure that is passed to the function specified by the pointer pfnCompletionRoutine.

fResume

Specifies whether to restore a system in suspended power conservation mode when the timer state is set to signaled. If fResume is TRUE on a platform that does not support a restore, the call will succeed, but GetLastError returns ERROR_NOT_SUPPORTED.



Return Value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Timer are initially inactive. Timers are activated by calling SetWaitableTimer. If the timer is already active when you call SetWaitableTimer, the timer is stopped, then it is reactivated. Stopping the timer in this manner does not set the timer state to signaled, so threads blocked in a wait operation on the timer remain blocked.
When the specified due time arrives, the timer becomes inactive. The state of the timer is set to signaled, the timer is reactivated using the specified period, and the thread calls the completion routine. If you call SetWaitableTimer and the thread is not in an alertable state, the completion routine is canceled.

When a manual-reset timer is set to the signaled state, it remains in this state until SetWaitableTimer is called to reset the timer. As a result, a periodic manual-reset timer is set to the signaled state when the initial due time arrives and remains signaled until it is canceled or reset. When a synchronization timer is set to the signaled state, it remains in this state until a thread completes a wait operation on the timer object.
 
new api:") 你的版本老,也许找不到,既然是menxin大哥回答的,CJ当然要帮忙啦。
另:远程唤醒,是不是只要MODEM接到信号就成?
 
:-)

谢了CJ!

最近我的EMAIL总是收不到信,不知为什么?  :(
 
接受答案了.
 
后退
顶部