Category Archives: Windows 8

Will there be an update for “Modern C++ and Windows Store apps” for Windows 8.1?

With Windows 8.1 now released as a Consumer Preview enabling developers to try out and begin building apps for the new Operating System, I wanted to let folks know if there is an updated version of my book, “Modern C++ and Windows Store apps” under development.

When I began contemplating writing a book about Windows 8, I did not want to just show how to build Windows Store apps using C++ /CX and XAML. That would probably have been a great disservice to C++ developers since it would have restricted the scope of the book to just XAML. Don’t get me wrong. XAML is a great UX framework but I wanted to show how the power and flexibility of C++ and C++ /CX can be used to build a vide variety of apps that could be run both on the Desktop and Modern.

The more I thought about what to talk about in the book, the more my ideas began to crystallize around narrating the “C++ Renaissance” at Microsoft and in the industry. Discussing the “C++ Renaissance” is a vast topic in itself and I had to make a few hard decisions on the list of topics. After multiple deliberations, I ended up discussing the following topics:

  • Show the simplicity of developing Windows Store apps using C++ /CX
  • Important concepts of C++11
  • Introduction to C++ /CX
  • A High level tour of XAML
  • Using C++ /CX to combine XAML and DirectX
  • Advanced GPGPU Programming by using C++AMP in Desktop and Windows Store apps.
      • Under the covers of the Windows Runtime and the Windows Runtime Library (WRL)
      • Introducing the new native unit test support in VS2012.
      • Debugging tips for Windows Store apps
      • Performance tips for using XAML
      • Introduction to Windows Azure Mobile Services
      • A sneak preview of Windows Phone 8 “shared code”.

One of the ideas that I steadfastly took while developing samples and the narration was to focus explaining how C++ developers should be using XAML/DirectX interop techniques to make their apps stand apart from pure XAML or WWA counterparts. XAML/DirectX interop is really the “super pill” that can help C++ developers take full advantage of both the retained mode benefits of XAML and the immediate mode rendering provided by DirectX. When coupled with C++AMP, this has the added advantage of eking out maximum performance from the available hardware for all of your workloads.

With Windows 8.1, while XAML got a host of new controls, using those controls by itself is not an impossible task if you have already worked your way through my book. There simply is no point creating a new version of the book, when the fundamentals have already been discussed. All of the new updates are important but they are not breaking changes or stuff that is hard to incorporate. What is really interesting is the changes to the XAML/DirectX interop types. Does it warrant the creation of a new version of the book to explain 4 new interop types? I don’t think so. It, however, does merit explanation. So, going forward, I will begin posting content about the updated XAML/DirectX interop types. I will also update the samples from my book to show how to move code from Windows 8 to Windows 8.1. I hope that is of more value to readers instead of coming up with a new version of the book. What do you think? Please do let me know.

If you have noticed the topics I discussed in my book, attentive readers must have noticed that I did not discuss any communications or network API in the book. Is it a harbinger for things to come in future? Stay tuned for updates Smile

-Sridhar

Multi-touch drawing in Windows Store apps using C++ and DirectX

Windows 8 introduces input via multiple touch points. In the DrawIt sample of my book “Modern C++ and Windows Store apps”, I show how to add free form drawing on a XAML SwapChainBackgroundPanel using either touch, mouse or pen inputs. The sample restricted input to a single pointer i.e. you could draw using a finger or with left mouse button down or with a stylus if your device supported one. In today’s post, I will show how to move from a single pointer to supporting multiple pointers (restricted only by the number of touch points supported by the underlying hardware).

The DrawIt sample has two main classes: MainPage and ShapeRenderer. All of the changes I am about to make below are in the ShapeRenderer class.

  • The only change to MainPage is to add support for the PointerEntered event which in turn calls the corresponding method from ShapeRenderer.
  • I will also add an overlay to the code to show Pointer touch point properties like PointerId, the point where the touch occurs etc. These changes are also in ShapeRenderer
  • In the sample I enclose below, I have removed support for erasing. You are free to add it back as an exercise.

Handling Multiple Pointers

 

  1. Open the ShapeRenderer header file. Add a private member variable of type Platform::Collections::Map.

    Platform::Collections::Map<UINT, Windows::UI::Xaml::Input::Pointer^>^ m_PointerContact;

  2. Add another private variable of type UINT.

    UINT m_activeContacts;

  3. These two variables will be used to keep track of the multiple pointers that can be used to draw on screen.
  4. Add a function declaration for OnPointerEntered in the ShapeRenderer class. The ShapeRenderer class already has methods for OnPointerPressed, OnPointerReleased etc.

    void OnPointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ args);

  5. In the ShapeRenderer constructor, initialize the map as follows:

    m_PointerContact = ref new Map<UINT, Pointer^>();

  6. In the implementation for OnPointerEntered method, we will use the following logic. If the pointer that fires the “Entered” event exists in our map, we do nothing. Else we store the new pointer details in the map, increment the number of active pointer count and begin drawing.
  7. Next we call the Render method of the SwapChain.
  8. Similarly in the OnPointerPressed event handler, we check if the pointer exists in our saved collection. If yes, do nothing. Else proceed to drawing.
  9. In the OnPointerReleased event handler, call EndStroke of the InkManager and then Render the strokes.
  10. After the Render call, remove the released pointer details from the collection and decrement the active pointer count.
  11. That is all there is to handling multiple pointers.

Creating an overlay while drawing

 

  1. Add three new methods to the ShapeRenderer header file.

    void UpdateInfoPop(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);

    void DestroyInfoPop(Windows::UI::Xaml::Input::Pointer^ ptr);

    void CreateInfoPop(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);

  2. The logic to create the popup is simple. In the CreateInfoPop method, we create a TextBlock. Get the current touch point details and add the pointer details to the TextBlock. Apply a RenderTransform on the TextBlock by creating a TranslateTransform and offset the TextBlock position by 20 pixels from the point where the pointer is on screen. This allows the TextBlock to be visible and display contents.
  3. The UpdateInfoPop is used to move the TextBlock as the pointer moves on the screen. Check for all children of the SwapChain that matches the TextBlock control type and then use the name property to zero on the right pointer. Once the right pointer is identified, update the TextBlock position to the new position as determined by the pointer point.

That is all there is to adding information overlay to a pointer move event. The sample code is attached. Download the code and let me know your thoughts!

-Sridhar

The Windows Store opportunity for C++ developers

One of my colleagues sent this statement my way and I quote him “The advent of Windows Store combines a great app-development infrastructure with a reach of 250 million people and counting. This is a great opportunity for seasoned and new app developers alike. While Microsoft has published great examples, tutorials, and help, a more detailed and focused resource like the book, “Modern C++ and Windows Store apps” is a fantastic contribution to help developers profit from this opportunity.”

Many thanks Mike Wehinger

-Sridhar

Modern C++ and Windows Store apps giveaway

BUILD 2013 is 9 weeks away. In anticipation of BUILD 2013, I am listing a giveaway for my book, “Modern C++ and Windows Store apps”. Every week leading to the BUILD 2013 conference, I will give out a copy of my book. Sounds interesting? Want a copy? Getting a copy is easy. All you have to do is put on your thinking caps and send me a mail about “What interests you about Windows 8 and Modern C++ put together to develop Windows Store apps?”

Each week I will select the best quote I receive, and send out a copy of my book to the person who has sent me the quote. I will also share the quote on my blog, twitter and Facebook feed. So, put your thinking caps on and send me mail at win8book at sridharpoduri dot com.

Please do not post your quotes as comments to this blog post as I will not be considering those. J

Rules and Regulations:

  1. Only one entry per person. I cannot verify duplicates but would expect everyone as professionals to be honorable.
  2. I reserve the right to select what I believe is best entry every week.
  3. I will share the best entry every week.
  4. I will not share the details of the person who sent the best entry (email address or any other personally identifiable details).
  5. After I post the selection of the best entry please look out for an email from me asking for your mailing address.
  6. I will bear the cost of shipment of the book to your address. You do not have to pay for shipping or the book cost. J
  7. Feel free to tweet or share this on your social networks!

Bring those interesting thoughts on!!!

Cheers,

Sridhar

Purchase Modern C++ and Windows Store apps in India

Hi,

Wanted to provide a quick update on the availability of my book, “Modern C++ and Windows Store apps”, in India.

Get the eBook in Adobe PDF: http://www.infibeam.com/eBooks/modern-c-windows-store-apps-sridhar-poduri-pdf-ebook-download/9780989020800-BEPDF.html

Get the paperback edition: http://www.junglee.com/Modern-C-Windows-Store-Apps/dp/0989020800/ref=sr_1_1?ie=UTF8&qid=1364203192&sr=8-1

Thanks,

Sridhar

[Updated with purchase and discount links] Modern C++ and Windows Store Apps – A book about Modern C++ and native technologies

Over the past few months, I have been writing a book on developing apps using C++ and the various native technologies shipping as part of the Windows 8 wave. Some of these technologies include: C++11, C++ /CX, native XAML, the Windows Runtime, C++AMP, Windows Azure Mobile Services etc. I am happy to announce that the Kindle version of “Modern C++ and Windows Store apps” will be available shortly for purchase via the Amazon website. A paperback edition will also be available soon.

For purchasing the paperback edition of the book, please visit this link. You can use the discount code 5C56GCKN to get 20% discount off MRP.

For folks interested in an electronic edition, you can purchase a Kindle edition on Amazon

A quick update: This is just me self-publishing the book thereby bringing the work to its logical conclusion.

For the benefit of everyone, I am listing some of the topics that await anyone who picks up a copy of this book. For the more adventurous amongst us who would rather prefer to play with code, the book samples can be downloaded from the Downloads section of this blog.

The new native API
What is a Windows 8 App?
Quick walkthrough of a Windows 8 App

Hello Modern C++
Move semantics
Welcome to the Component Extensions
The C++ /CX Type System
Asynchronous Programming in C++ /CX
Building a WinRT component using C++ /CX and ISO-C++
Guidance on the use of C++ /CX

Introduction to XAML
Hello World with XAML and C++ /CX
Basic XAML Syntax
Using Panels to Layout UX
Basic XAML Controls
Windows 8 Signature XAML Controls
Handling Events
Markup Extensions
Data Binding
Binding to a Data Model
Building a XAML custom control
Using Animations in XAML Controls

Introduction to XAML + DirectX
SurfaceImageSource
VirtualSurfaceImageSource
Design considerations when using SiS and VSiS
SwapChainBackgroundPanel
The DrawIt Application – C++, XAML and DirectX

The C++ AMP Library
The ImageEffects application

Playing by the rules of the Windows Runtime
Introduction to the Windows Runtime Library
Hello World XAML App using Windows Runtime Library

Getting Started with Windows Store apps and Windows Azure Mobile Services
Creating a simple Windows Store app with Windows Azure Mobile Services
Supporting Push Notifications using Windows Azure Mobile Services

And more….

I had a lot of fun writing this stuff and learning along the way. I hope there are concepts that you can apply to your work as you build apps for the Windows 8 Store using C++.

Please send feedback on the book contents directly to win8book at sridharpoduri dot com