Category Archives: Windows 8

Windows 8

Create app bar button icons using Segue UI Symbols font

Creating app bar buttons for WinRT applications is easier than creating them for Windows Phone applications. While Windows Phone uses transparent images for app bar buttons, WinRT applications use built-in Segoue UI Symbol font for that purpose. This simplifies things quite a bit since we don’t have to trouble ourselves with scaling, picking correct size for the app bar images and theming (in case we need black and white versions). If you took a look at the default styles that come for WinRT applications, you could notice that they don’t use any images, they are simply referencing a particular symbol in the font. read more »

Windows 8 Windows Phone 7/8

Async, portable libraries and Windows Phone 7 in Visual Studio 2012

Windows phone topic Portable classes in Visual Studio 2012 are simply awesome. They allow high code reuse for multiple platforms. Another great addition in Visual Studio 2012 is support for asynchronous programming in C# 5 which, sadly, was not initially available for Windows Phone 7 developers.

If you want to target Windows Phone 8 and Windows Store, you can use Async if you also target .NET 4.5. If you want to target Windows Phone 7.1 and Windows Store, you cannot use asynchronous features from C# 5. But with the prerelease version of Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone 7.5 and 8 you can finally use Async in your Windows Phone 7 applications. If you want to target largest market, you need to support Windows Phone 7 along with Windows Phone 8, it is too large to simply ignore.

So, can we use Async in portable libraries while still targeting both Windows Phone 7 and Windows Store? Luckily, the answer is yes. But, and there is always a but, with one caveat – you must target .NET 4.0 instead of .NET 4.5.

The procedure is simple: create a new Portable Class Library and select the targets as seen on the image below:

Targets for Portable Class Library project

Portable Class Library targets

To add Async support, run the following command in the Package Manager Console:

Install-Package Microsoft.Bcl.Async -Pre

Voila, you can now write asynchronous code in a portable class library which can then be linked in Windows Phone 7, Windows Phone 8 and Windows Store projects. If you build a Windows Phone 7 application and link to such portable class library, you will need to add the same NuGet package to that project also.

Windows 8

DirectX and XAML in Windows (Phone) 8 – part 2 of N – WinRT component and C# integration

This entry is part of a series, DirectX and XAML»

In the previous post I have created a basic Windows 8 application featuring both DirectX and XAML. However, the sample was written in C++/CX and there aren’t any project templates for writing applications with both XAML and DirectX since the latter one is exposed only in C++. Luckily, there is a way for you to write C++ code that deals with DirectX which you could then reference in C#/VB – by creating WinRT component.

Creating an WinRT component

You can create Windows Runtime components in either C++ or your favorite managed language. Start Visual Studio and create new project with Visual C++/Windows Store/Windows Runtime Component. Delete the sample class created by the template (seen on the image below).
read more »

Windows 8

DirectX and XAML in Windows (Phone) 8 – part 1 of N – Simple 2D surface

This entry is part of a series, DirectX and XAML»

If you want to add a simple DirectX drawn surface to your existing XAML application, use SurfaceImageSource. This is a XAML type which allows you to continue using XAML composition and it also gives you the full control to the DirectX surface for rendering.

Once instantiated, use SurfaceImageSource as a source for ImageBrush. Since brushes are reusable, you can use the same DirectX surface for multiple XAML elements. This sample code creates new SurfaceImageSource and assigns it as the source for ImageBrush:

SurfaceImageSource^ surfaceImageSource =  
    ref new SurfaceImageSource(width, height, true);    
ImageBrush^ brush = ref new ImageBrush(); 
brush->ImageSource = surfaceImageSource; 

// if you have a rectangle or a ellipse
element->Fill = brush;

However, you can notice that SurfaceImageSource doesn’t expose any methods for drawing, for that you need to use the backing native interface. The above code can be easily written in C#, but you cannot access the underlying native interface necessary for rendering to the DirectX surface. That interface and also entire DirectX is currently available only in C++ template projects that ship with Visual Studio 2012. read more »

Windows 8 Windows Phone 7/8

DirectX and XAML in Windows (Phone) 8 – part 0 of N – Overview

This entry is part of a series, DirectX and XAML»

DirectX is a powerful beast that enables creation of stunning graphics oriented applications (not just games :) ). On the other hand, XAML is used to quickly create basic application UI. Having both in a single application seems like an obvious choice. For example: when building a game, you can use XAML to create level selection screens, mode selection screen, options page, etc while leaving DirectX to power the game itself. It is only natural to combine the best of the two in a single application.

Since we now have both Windows 8 and Windows Phone 8 out in the wild, I will dedicate some time on this blog to describing how to combine XAML and DirectX on both platforms. This is the first blog post in the series and will provide some basic overview of future posts.

Since DirectX is exposed only in C++ project templates, first couple of posts will feature C++/CX only. Later on, I will describe how to bridge the gap to the managed world using SharpDX for Windows 8. All examples will be rather simplistic, but you can use your imaginations to build wonderful new things.

During the series, I will be using Microsoft Visual Studio 2012 Express for Windows 8 and Microsoft Visual Studio 2012 Express for Windows Phone, which you can download from the following links: Express for Windows 8 and Express for Windows Phone. All samples for Windows 8 can can also run on Windows RT since we are building a Windows Store app. read more »

Windows 8

Asynchronous loading of text files in Metro/C++/DirectX applications

By just adding a simple modification to the existing ReadDataAsync function, we can load text files asynchronously:

You can load files using the following code (don’t forget it is asynchronous.

auto loadTextTask = ReadStringAsync(L"Assets\\Text.txt")
                                   .then([this](Platform::String^ text)
{
	m_text = text;
});

Enjoy.

Windows 8 Windows Phone 7/8

DirectX 11, Metro and Windows Phone 8

I couldn’t resist it, I simply had to install WP8 SDK. The first thing I did was creating a new project to see what has been added and what removed. Sadly, if you add XNA project, you can target WP7, and not WP8. However, since XNA based applications will be compatible with WP8, it makes no sense to discard WP7 since it has millions of users and not all of them will make the jump. One app, two marketplaces.

Moving on to the DX11 stuff I have created three projects:

  • Visual C++/Windows Metro Style/Direct3D App
  • Visual C++/Windows Phone/Windows Phone Direct3D App
  • Visual C#/Windows Phone/Windows Phone Direct3D XAML Application

The C# project template actually added two projects in my solution: a C# based Direct3DXamlApp1 project which references C++ Direct3DXamlApp1Comp project. C++ templates added only 1 project.

On basic inspection, all three C++ projects shared the same directory structure! In the image below, you can see how similar they are.

It simply screams “reuse me!” And since it is obvious that C# class can consume C++ components, you can create XNA-like library using the DirectX Tool Kit. I guess that it is not bad after all.

Since my processor does not support SLAT and I cannot run emulator, I will leave the refactoring of common classes for some other time. It is quite obvious that Microsoft made an effort to unite the mobile platforms for easy creation of DirectX apps for both platforms.

Windows 8

DirectX Tool Kit – native “XNA” for Windows 8

For all those who miss XNA in Metro applications, DirectX Tool Kit is a handy set of classes that mimic popular XNA classes such as SpriteBatch, SpriteFont and BasicEffect. Let’s see how easy it is to use it. For my first trick, I shall load a texture and render it on screen. Nothing fancy, but it will quickly establish the similarities between old and proven XNA code with new DX11 code. Just to be clear, the code in this blog post is written using C++.

Go and download DirectXTK from Codeplex/. Open the DirectXTK_11_Metro solution and you will see only one project inside. Build it and you will get a static library. Include files are located in the Inc folder. read more »

Windows 8

C++ and Metro: event handling and MessageBox

This entry is part of a series, C++ Metro applications»

In the previous post we have created simple Metro application using C++ as the language of choice. Now we are going to add some interactivity into it.

MessageDialog

Add a simple button and using the following XAML snippet:

<Button Content="Click me" Click="Button_Click_1" Margin="12,20" />

Right click on the Button_Click_1 attribute value and select the Navigate to Event Handler. You will be transferred to the cpp file and both header and source file will be properly updated. Add the following code inside:

using namespace Windows::UI::Popups;
auto msgDlg = ref new MessageDialog("We want to notify you that you have successfully handled this event", "Vexing information");
msgDlg->ShowAsync();

read more »

Entries in this series:
  1. C++ and Metro: basic application
  2. C++ and Metro: event handling and MessageBox
Powered by Hackadelic Sliding Notes 1.6.5
Windows 8

C++ and Metro: basic application

This entry is part of a series, C++ Metro applications»

Visual Studio 11 Consumer Preview enables creating Metro styled applications using C++ which is a great news for any native developer. Let’s create a simple Metro application. Start up Visual Studio and create new project using the Visual C++>Windows Metro Style>Blank Application template.
read more »