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

Translate This Page

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

Rate This
  • Comments 1

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 (http://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:

http://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: http://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("
http://socalprivacypolicy.azurewebsites.net/privacypolicy.html");

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

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

Leave a Comment
  • Please add 5 and 6 and type the answer here:
  • Post
  • Very nice post, well described

    www.charm-anhaenger.net

Page 1 of 1 (1 items)
Generic Content

Legal Note:

  1. The author, Sam Stokes, is an employee of Microsoft
  2. There is no guarantee that anything I write is correct, I do try to make sure that what I write is correct.
  3. Use anything written in this blog at your own risk
  4. Test what I write about before using the information
  • Sometimes posts will disappear because I realized that they really don't fit with the total chaos of what I write about
  • Links are tested and available on date of publication, what others do with their links are out of my control

Restrictions:

  • Whatever I write on this blog is unedited by management or anyone, which should be obvious from the randomness of the blog.  I simply write about things I like.
  • Microsoft does not restrict me in anyway, so I generallyblather about whatever I want to.
  • For personal reasons I will not write about:
    • Company confidential stuff, mainly because Microsoft is more transparent than any company I have ever worked for.
    • Other people unless they give me permission to write about them