在 Windows Mobile 6 中禁用睡眠模式

发布于 2024-07-07 07:39:50 字数 60 浏览 10 评论 0原文

有谁知道如何在 Windows Mobile 上以编程方式禁用/启用睡眠模式?

谢谢!

Does anyone know how could I programatically disable/enable sleep mode on Windows Mobile?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

指尖凝香 2024-07-14 07:39:50

如果您希望程序在运行时不进入睡眠状态,最好的方法是创建一个 KeepAlive 类型的函数,调用 SystemIdleTimerReset、SHIdleTimerReset 并模拟按键触摸。 然后你需要经常调用它,基本上到处都是。

#include <windows.h>
#include <commctrl.h>

extern "C"
{
    void WINAPI SHIdleTimerReset();
};

void KeepAlive()
{
    static DWORD LastCallTime = 0;
    DWORD TickCount = GetTickCount();
    if ((TickCount - LastCallTime) > 1000 || TickCount < LastCallTime) // watch for wraparound
    {
        SystemIdleTimerReset();
        SHIdleTimerReset();
        keybd_event(VK_LBUTTON, 0, KEYEVENTF_SILENT, 0);
        keybd_event(VK_LBUTTON, 0, KEYEVENTF_KEYUP | KEYEVENTF_SILENT, 0);
        LastCallTime = TickCount;
    }
}

此方法仅在用户手动启动应用程序时有效。

如果您的应用程序是通过通知启动的(即当设备挂起时),那么您需要执行更多操作,否则您的应用程序将在很短的时间内挂起,直到用户将设备从挂起模式中唤醒。 要解决此问题,您需要将设备置于无人值守电源模式。

if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, TRUE))
{
    // handle error
}

// do long running process

if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, FALSE))
{
    // handle error
}

在无人值守模式使用期间,您仍然需要多次调用KeepAlive,您可以使用一个单独的线程,该线程休眠x毫秒并调用keepalive函数。

请注意,无人值守模式不会使其退出睡眠模式,而是使设备处于奇怪的半唤醒状态。

因此,如果您在设备处于挂起模式时启动无人值守模式,它将不会唤醒屏幕或任何其他内容。 所有无人值守模式所做的就是阻止 WM 挂起您的应用程序。 另一个问题是它不适用于所有设备,某些设备的电源管理不是很好,无论您做什么它都会暂停您。

If you want your program to not be put to sleep while it's running, the best way is to create a KeepAlive type function that calls SystemIdleTimerReset, SHIdleTimerReset and simulates a key touch. Then you need to call it a lot, basically everywhere.

#include <windows.h>
#include <commctrl.h>

extern "C"
{
    void WINAPI SHIdleTimerReset();
};

void KeepAlive()
{
    static DWORD LastCallTime = 0;
    DWORD TickCount = GetTickCount();
    if ((TickCount - LastCallTime) > 1000 || TickCount < LastCallTime) // watch for wraparound
    {
        SystemIdleTimerReset();
        SHIdleTimerReset();
        keybd_event(VK_LBUTTON, 0, KEYEVENTF_SILENT, 0);
        keybd_event(VK_LBUTTON, 0, KEYEVENTF_KEYUP | KEYEVENTF_SILENT, 0);
        LastCallTime = TickCount;
    }
}

This method only works when the user starts the application manually.

If your application is started by a notification (i.e. while the device is suspended), then you need to do more or else your application will be suspended after a very short period of time until the user powers the device out of suspended mode. To handle this you need to put the device into unattended power mode.

if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, TRUE))
{
    // handle error
}

// do long running process

if(!::PowerPolicyNotify (PPN_UNATTENDEDMODE, FALSE))
{
    // handle error
}

During unattended mode use, you still need to call the KeepAlive a lot, you can use a separate thread that sleeps for x milliseconds and calls the keep alive funcation.

Please note that unattended mode does not bring it out of sleep mode, it puts the device in a weird half-awake state.

So if you start a unattended mode while the device in suspended mode, it will not wake up the screen or anything. All unattended mode does is stop WM from suspending your application. Also the other problem is that it does not work on all devices, some devices power management is not very good and it will suspend you anyway no matter what you do.

嘿咻 2024-07-14 07:39:50

修改影响您想要的特定睡眠条件的电源管理器注册表设置 (超时、电池、交流电源等)以及名为“PowerManager/ReloadActivityTimeouts”的命名系统事件上的 SetEvent,以告诉操作系统重新加载设置。

Modify the Power Manager registry setting that affects the specific sleep condition you want (timeout, batter, AC power, etc) and the SetEvent on a named system event called "PowerManager/ReloadActivityTimeouts" to tell the OS to reload the settings.

一抹苦笑 2024-07-14 07:39:50

可能通过修改“系统电源状态”,如 此处所述(但在 c# 中) )

该文章还介绍了一种防止移动设备进入睡眠状态的方法(这可能不完全是您想要的),即定期调用本机函数 SystemIdleTimerReset() (以防止设备断电)。

Probably by modifying the "System Power States" as described here (but in c#)

That article also describes a way to prevent the mobile device to sleep (which is not exactly what you may want), by calling the native function SystemIdleTimerReset() periodically (to prevent the device from powering down).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文