DirectX/C++/CX: Charming charms in your charming app

You want to make a beautiful app, well to make a beautiful app shouldn’t it be charming as well?  But how do you do these charming features for your wonderful and beautiful apps?

Charms in C++, DirectX

First if you are a C++ programmer who has been doing other interesting work, but not designing UIs, or if you aren’t using Windows 8, but have access to MSDN subscription, here is what you are missing out on, except the symbols look different, you might get the idea here.

image

Adding a privacy statement

It’s easy, but due to the documentation philosophy at Microsoft to make sure that beginners like students, hobbyists and professors are in a state of confusion.  Thus the process seems to be either really hard or just designed to be confusing.  It isn’t. (Unless you are reading my stuff, I am just a blogger and any confusion or weird thought processes are the reason you are reading this.)

First go to the MSDN site: Add your privacy policy in the Settings charm to a DirectX game , scroll down to the “Adding a Privacy Policy policy Setting Charm”.  Well first off, to me, the privacy policy is NOT a setting charms.  However, the designers felt that it is.  But when you write it down and then read it, it seems odd.  It is.  Privacy Policy is part of the Settings Charms, you can’t adjust the Privacy Policy here, the developer does that.  So no switches, etc.

Then, and this is weird, the sample code won’t work as written.  Oh sure it will if you have added the correct namespace, but the document doesn’t tell you that.

Make sure you add the line:

using namespace Windows::UI::ApplicationSettings;

For some reason this line is not included in the default templates.  You might ask why since the Privacy policy is so important and most apps have to have one, in fact there are only a few cases of apps that don’t use a privacy apps.  If the privacy policy is needed in general, wouldn’t it be easy to just add this to a the templates, after all if I am starting with a template I am likely a beginner.  Oh well, I am not on anyone’s speed dial I guess.

Once if you the namespace you can add the example code to your app and it will run.  Oh not really.  It is mentioned that you need a website.  For testing you can using any web site, but for your privacy statement you will need to have a website hosted someplace.

You can use the free Azure website you can create using your non-premium or premium DreamSpark account (https://www.dreamspark.com )

Use WebMatrix to build your webpages, make sure to include your correctly spelled app name.

I have an example but simple privacy statement that might disappear at any time:

https://socalprivacypolicy.azurewebsites.net/privacypolicy.html

What about a  working example?  I added the code to the XAML DirectX 3D shooting game sample (8.1), get from: https://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-Samples, it is in the samples that you download.

The code for the shooting game should now look like the following, I did remove some precompile code to clean up the number of lines.

Image (click to enlarge)  which is followed by code you can cut and paste:

image

//***********************************************************************************************************

using namespace Windows::UI::ApplicationSettings; /*Added */
MainPage::MainPage() :
m_possiblePurchaseUpgrade(false)
{
InitializeComponent();
// Add a Settings charm for the privacy policy
SettingsPane::GetForCurrentView()->CommandsRequested +=
ref new TypedEventHandler<SettingsPane^, SettingsPaneCommandsRequestedEventArgs^>(
[this](SettingsPane^ sender, SettingsPaneCommandsRequestedEventArgs^ args)
{
args->Request->ApplicationCommands->Append(
ref new SettingsCommand(
"privacyPolicy",
"Privacy Policy",
ref new Windows::UI::Popups::UICommandInvokedHandler([=](Windows::UI::Popups::IUICommand^ command)
{
// The URI to launch
// Be sure to replace this string with the URL to your privacy policy.
auto uri = ref new Windows::Foundation::Uri("https://socalprivacypolicy.azurewebsites.net/privacypolicy.html");

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

}

//***************************************************************