Add your privacy policy in the Settings charm to a DirectX game

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

In this topic, you will learn about adding a Settings charm to a DirectX 11 game for the Windows Store using C++. This topic describes the charms, the Settings charm, related store requirements, and how to add the Settings charm by using C++.

This topic uses the DirectX game (XAML) template as a starting point. See the Create a DirectX game project from a template topic for more information.

What is the Settings charm?

The charms are a specific and consistent set of buttons for users in every app: search, share, connect, settings, and start. The Settings charm displays a set of settings specific to the current app. You add items to the settings menu and set the actions triggered when the user clicks on each item.

Here is an illustration of the charms.

Windows draws the charms and triggers the charms events.

Adding a privacy policy Settings charm

The Windows Store requires that some apps include a privacy policy. (See the Windows and Windows Phone Store Policies for more info.)

The example code here adds a privacy policy Settings charm to your app. Place this code in the constructor or an initialization method.

// Add a Settings charm for the privacy policy
SettingsPane::GetForCurrentView()->CommandsRequested += 
ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>(
    [this](SettingsPane^ sender, SettingsPaneCommandsRequestedEventArgs^ args) 
    {
        // Add the command labeled "Privacy Policy".
        args->Request->ApplicationCommands->Append(
            ref new SettingsCommand(
                "privacyPolicy",  // settings command name.
                "Privacy Policy", // Settings command label.
     
                // Add a handler for when the user clicks the command.
                ref new Windows::UI::Popups::UICommandInvokedHandler([=](Windows::UI::Popups::IUICommand^ command)
                {
                    // TODO: Make sure to replace this string with a link to your privacy policy.
                    Platform::String uriString = "https://www.contoso.com";

                    // This is a link to your privacy policy on you're website.
                    // Be sure to replace this string with the URL to your privacy policy.
                    auto uri = ref new Windows::Foundation::Uri(uriString);

                    // Launch the URI.
                    concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
                    launchUriOperation.then([](bool success){});
                })));
    });

The UICommandInvokedHandler delegate is where you place your event handler code.

Note  An invalid URL causes an exception at runtime.

 

Detecting when the charms appear

Many games need to pause when the charms appear. The example code here detects when the charms appear so that you can pause the game or perform other commands.

// Add an event handler to pause when charms are activated.
Window::Current->Activated += ref new WindowActivatedEventHandler(
    [this] (Platform::Object^ sender, Windows::UI::Core::WindowActivatedEventArgs^ args)
    {
        switch (args->WindowActivationState)
        {
        case Windows::UI::Core::CoreWindowActivationState::Deactivated:
            m_paused = true;  // Set the game state to "paused".
            break;
            
        case Windows::UI::Core::CoreWindowActivationState::CodeActivated:
        case Windows::UI::Core::CoreWindowActivationState::PointerActivated:
            m_paused = false; // Set the game state to "unpaused".
            break;
        }
    });

Note  The preceding example does not detect when the app bar appears. The app bar triggers event handlers when it opens and closes; you can use these events (for example) to pause your game as appropriate. See Add an app bar for details.

 

By following the example you can add additional settings for your game. You can also add Settings flyouts, each with multiple settings.

Adding entry points to Settings flyouts

Entry points are text strings that appear at the top of the Settings pane and generally open Settings flyouts, where you can display one or more settings options.

If you are creating a game with DirectX and XAML, you can use the XAML Popup element to show a flyout container and display a custom settings pane. This pane can contain a variety of XAML controls, such as the Slider control. For example code see the XAML Popup sample.

Note  If your app does not use XAML, you must provide your own code to display flyouts by using a technology such as Direct2D to draw the flyout. The Guidelines for app settings describe best practices for using the Settings charm to display app settings.