Partager via


How to disable the lock screen from a Direct3D app for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

This topic shows you how to disable the lock screen from a Windows Phone Direct3D app. Example scenarios for using this are games that use the accelerometer for user input, or apps that play long videos. If the user doesn’t interact with the screen, the phone will assume that it is idle and will engage the lock screen after the time interval configured by the user in the Settings app. If your app disables the lock screen, it should do this only while the user is actively using the part of your app that does not involve user input. This means that a video app should reenable the lock screen when video is not playing and a game should reenable the lock screen in the game menus or if the accelerometer is inactive for an extended period of time.

Disabling and enabling the lock screen

  1. Declare a member variable for storing a DisplayRequest object. It is important that this variable remain in scope for as long as you want to disable idle detection. A good idea is to declare it as a member of your IFrameworkView implementation.

        Windows::System::Display::DisplayRequest^ m_displayRequest;
    
  2. When your app begins a task in which the user won’t interact with the screen, disable the lock screen by calling RequestActive()()().

        m_displayRequest = ref new Display::DisplayRequest();
        m_displayRequest->RequestActive();
    
  3. When the task in which the user doesn’t interact with the screen is finished, reenable the lock screen by calling RequestRelease()()().