在Windows Mobile 6中禁用睡眠模式 [英] Disable sleep mode in Windows Mobile 6

查看:166
本文介绍了在Windows Mobile 6中禁用睡眠模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我如何在Windows Mobile上程式停用/启用睡眠模式?

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

谢谢!

推荐答案

如果你希望你的程序在运行时不会进入休眠状态,最好的方法是创建一个KeepAlive类型函数,调用SystemIdleTimerReset,SHIdleTimerReset并模拟一个键触。然后你需要调用它很多,基本上无处不在。

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
}



在无人值守模式下使用时,您仍然需要调用KeepAlive,你可以使用一个单独的线程,休眠x毫秒,并调用保持活动函数。

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.

所以如果你启动无人值守模式,而设备处于挂起模式,它不会唤醒屏幕或任何东西。所有无人参与模式都是停止WM暂停您的应用程序。另一个问题是它不工作在所有设备,一些设备的电源管理不是很好,它会暂停你无论你做什么。

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.

这篇关于在Windows Mobile 6中禁用睡眠模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆