请教各位老大! windows2000里怎么样 用rundll32 命令 让计算机休眠阿?小弟 正在研究 让计算机 自己 休眠的 程序!望 告之! 小弟感激不敬阿!先谢谢各位老大了!
解决方案 »
- MFC中的CDC对象和SDK中的HDC是一回事吗?
- 子窗口透明问题!
- 一子对话框如何 获得另了子对话框的指针
- 下面程序错误是什么意思
- 类,提示无效指针
- error C2065: 'brmul' : undeclared identifier 求助!!!
- ★★★★★★★★★★★★★ ^-^请问: MFC 和 VCL 各自的 “消息机制” 哪个更高效率?
- 打了VC 的SP5补丁之后,原来使用的OCX控件无效,重新注册提示分配内存失败!
- 各位老大,小弟有一个小问题请教?感谢!!!
- 请问各位怎么才能让编译好的程序不用mfc42d.dll,而是用mfc42.dll?
- 在程序如何实现让windows进入睡眠状态,急
- 郁闷
给你一个实现休眠的代码(VCBASE):void PERR(LPTSTR szAPI, DWORD dwLastError);
#define RTN_ERROR 13INT SetPower()
{
// TODO: Add your control notificationhandler code here
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid; LPTSTR MachineName=NULL; // pointer to machine name if(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES,
&hToken ))
{
PERR("OpenProcessToken", GetLastError() );
return RTN_ERROR;
} if(!LookupPrivilegeValue(MachineName, SE_SHUTDOWN_NAME, &luid)) {
PERR("LookupPrivilegeValue", GetLastError() );
return RTN_ERROR;
} tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
NULL, NULL ); SetSystemPowerState(FALSE,TRUE);
return 0;}
void PERR(
LPTSTR szAPI, // pointer to failed API name
DWORD dwLastError // last error value associated with API
)
{
LPTSTR MessageBuffer;
DWORD dwBufferLength; //
// TODO get this fprintf out of here!
//
fprintf(stderr,"%s error! (rc=%lu)\n", szAPI, dwLastError); if(dwBufferLength=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dwLastError,
LANG_NEUTRAL,
(LPTSTR) &MessageBuffer,
0,
NULL))
{ DWORD dwBytesWritten; //
// Output message string on stderr
//
WriteFile(GetStdHandle(STD_ERROR_HANDLE),
MessageBuffer,
dwBufferLength,
&dwBytesWritten,
NULL); //
// free the buffer allocated by the system
//
LocalFree(MessageBuffer);
}
}注意:此函数只运行于Windows 2000/XP,并且打开了高级电源管理的休眠支持。
SetSuspendStateThe SetSuspendState function suspends the system by shutting power down. Depending on the Hibernate parameter, the system either enters a suspend (sleep) state or hibernation (S4).
BOOLEAN SetSuspendState(
BOOL Hibernate,
BOOL ForceCritical,
BOOL DisableWakeEvent
);Parameters
Hibernate
[in] If this parameter is TRUE, the system hibernates. If the parameter is FALSE, the system is suspended.
ForceCritical
[in] If this parameter is TRUE, the system suspends operation immediately; if it is FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation.
DisableWakeEvent
[in] If this parameter is TRUE, the system disables all wake events. If the parameter is FALSE, any system wake events remain enabled.
Return Values
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.Res
An application may use SetSuspendState to transition the system from the working state to the standby (sleep), or optionally, hibernate (S4) state. This function is similar to the SetSystemPowerState function.Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows Me, and Windows 98.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Header: Declared in Powrprof.h.
Library: Use Powrprof.lib.