C++/DirectX: Creating a settings charm in the charm bar

In my previous blog, I showed that implementing a privacy statement was easy.  And I questioned the VS templates and examples for not having the Privacy Policy charm, well I won’t question this, now.  But at one time, you would not have settings in your app, you were suppose to have the settings in the charms, and then no one did so.  Well you could have similar questions.  Or not.

Settings are pretty important and you can put them in your app, but it wastes screen space and so forth, but for most XAML programmers you might lean toward using on screen space or the app bar instead of the charm.  And seriously you would likely have to explain settings to your audience.

So here I am explain settings and trying to make it very simple and non-generalized to a multiple of things.  To write this blog I used the code from:

But I didn’t try to do two things, this is just about creating a setting that has a message box.  That’s it.  Doesn’t do anything really.

Use the example app from the previous blog: C++/DirectX: Adding a privacy statement to a template app .

Header File

Project name is: GameFunMain, so you appname would replace that

image

Source File:

First add the Setting() method (copy and paste if you want to use this code):

//****************Copy starts here ****************************

void <Your Project Name>::Setting()
{
    SettingsPane::GetForCurrentView()->CommandsRequested +=
        ref new TypedEventHandler<SettingsPane^,
        SettingsPaneCommandsRequestedEventArgs^>(
        [=](SettingsPane^ sender, SettingsPaneCommandsRequestedEventArgs^ args)
        {
             using namespace Windows::UI::Popups;
            args->Request->ApplicationCommands->Append(
                ref new SettingsCommand(
                "DemoSettings",
                "Detect Humor",
                ref new UICommandInvokedHandler(
                [=](IUICommand^ command)
        {
             MessageDialog^ msg = ref new MessageDialog("You're kidding me, there is no humor in this");
            msg->ShowAsync();
        })
            )
            );
    });

}

//*****************Copy ends here ******************************

Then you will need to add the Setting() methods call

What you application will look like:

image

When you press the “Detect Humor” this is the message box that shows up:

image