Could be more.  Likely less.

As of 11:21 4/12/2012, the documentation for how to program using C++ consists of some complicated samples (that I must say are useful, but complex), a little discussion here and there, and that’s it.

Don’t get your expectations up about any of this blog either.  But here we go.  Right now.  Ok.

Open Visual Studio 11 Express Beta and start a project, give it whatever name you wish.  Right now I have to experiment with the various project types, it would be easier to use Visual Studio 11 Ultimate Express, but that doesn’t constrain us to only the WinRT.  So to make this a challenge for me, I am just using the VS 11 Express Beta.

Let’s use the Blank Application or Solution for our initial cut at WinRT/Metro XAML/C++, what the heck.

 

Your IDE (Integrated Design Environment) should look like, double click to enlarge:

image

 

So let’s talk about functions, bear in mind that the first three letters of function is FUN!

In C++ you provide a prototype in the header file and this is referred to as Function Prototyping.  Do you have to put it in the header file? Yes.  Ok, not always, but let’s keep this simple.

Click the little triangle thingie (I call it a twistie) next to BlankPage.xaml, you will see two files like the following:

  • BlankPage.xaml.cpp
  • BlankPage.xaml.h

Now add a control like the TextBlock or TextBox to your app.

<Grid x:Name="grdBig1" Background="{StaticResource ApplicationPageBackgroundBrush}">
        <TextBox x:Name="AAATextAAA" Text="sillybugger" />
</Grid>

 

Make sure to name the control using:

  • x:Name

if you don’t the program doesn’t autoname the control. 

Now, Press F7 to build your app, this step is required so that you can use the control in the code behind.

Now open the BlankPage.xaml.cpp, and add some text for your textbox or textblock:

BlankPage::BlankPage()
{
    InitializeComponent();
}
 
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.  The Parameter
/// property is typically used to configure the page.</param>
void BlankPage::OnNavigatedTo(NavigationEventArgs^ e)
{
    AAATextAAA->Text="Unsilly Bill";
 
}

 

The Code that you add is the line:

AAATextAAA->Text=”Unsilly Bill”;

If you named the control AAATextAAA which is stupid way to name anything so don’t do that, but it makes the point and it is easy to see, don’t do it in a “real” program, like for school or work.

Ok, that’s it.  There is a bug, sometimes the program won’t detect your control, usually you will have to reboot your O/S, apparently this has been fixed but hasn’t shown up in current release.  Annoying, very annoying.