WP8代码实现一键锁屏和一键重启

Posted by baicai on April 14, 2014

锁屏篇:

WP8.1的锁屏需要新建WP8.1Runtime Component项目,然后建立W8.1RT项目来引用它。</span> </p>

1.新建Windows Store - Windows Runtime Component项目(需要win8SDK)

2.DllImport引入ShellChromeAPI.dll,封装Shell_TurnScreenOn(bool value)方法

public sealed class Lock
{
    [DllImport("ShellChromeAPI.dll")]
    private extern static void Shell_TurnScreenOn(bool value);
    public static void TurnScreen(bool isOn)
    {
        Shell_TurnScreenOn(isOn);
    }
}

3.项目属性选择arm平台,生成

4.将生成的.winmd文件引入wp项目

5.调用(false为锁屏)

重启篇(wp8.1已失效):

await Launcher.LaunchUriAsync(new Uri("test:"));

收工