Using DirectX 11.2 and C++ to build the most basic Windows Form

You know, I can make a lot of stuff work and work well.  My neighbors, professors, and students often ask me to review documents, projects and so forth.  So I keep looking at the tutorials on MSDN, like the one at:Creating a Simple Direct2D Application  and ask myself who is this written for?  Why does it look like it is part of the C++/XAML/DirectX information?  I don’t know but there are few problems with this otherwise functional demo.   The tutorial appears to be for Direct2D, but it suggests that you use VS 2008, to quote from the website:

To follow the tutorial, you can use Microsoft Visual Studio 2008 to create a Win32 project and then replace the code in the main application header and cpp file with the code described in this tutorial, or you can copy the code from the Draw Rectangle Example.

And frankly you could get it to work, but likely if you are like me, you look at this and wonder why this even came up in my search for information about how to use C++ with XAML and Windows 8.1.  Well it did, but it hasn’t been updated for a period of time and even with a number of beginners asking about how to fix it, it never got updated.  It should be.  So who could do that?  Oh, that would be the whiner: me.

Ok, let’s face it, you can’t get it to work in VS 2013, or can you?  Yes you can, and just like you would in VS 2008, but if you aren’t used to working with VS 2008 C++ or especially VS 2013, you might struggle with this tutorial.  And that is sad, because the fixes are pretty easy and procedural, nothing to do with programming.  Make sure you continue to scroll down the page to see the full answer, and also refer to the “Tutorial”

Do you use Console or Win32 in the New Project Dialog box?

Either one won’t work, but the easiest one to not work is the Console one (note I am using the VS 2013 Ultimate, your dialog box may vary, who knows.

<<<if you are reading this when VS 2014 or VS 2015, stop here and find a more recent document, this is guaranteed only for VS 2013>>>

image

Ok, now you have a simple app, whatever you named it, maybe you didn’t and just kept the initial name, that would make you a rookie Smile:

Now you get these wonderful choices, doesn’t make any difference, all of them are wrong, so just take whatever shows up, and continue to scroll down:

image

Ok you could use this as is for a console app, but in this case you need to add a couple of things that the “Tutorial” neglected to tell you about.  Now to fair if you are a regular Windows developer in C++, you might not realize that these items are needed to be changed or what to do

So Right Click on the Project Name and then select Properties (or whatever process you like), scroll down to see more:

image

In the properties box, select C/C++ then “ linker” then in the additional dependencies, you will need to hit the drop down box on the right side of the line, (now  scroll down on this page)

image

then select <edit>, then add D2d1.lib

(make sure to scroll to see more)

image

Now on the dialog box click “Apply” and then Ok

Let’s keep going, you have another thing you have to do, that is to make sure to not use Precompiled header,

Use the drop down to select “Not using Precompiled Headers”

image

All right one more thing! On the property page select Linker again and then All Options then Subsystem (you can use the option in that box on top), then switch that to Windows(/SUBSYSTEM:WINDOWS)

image

Delete that current source file and add the header file and source file from the tutorial example code, Draw Rectangle Examplel::

  • DemoApp.cpp
  • DemoApp.h

Add the EXISTING DemoApp.cpp to the source file and add EXISTING DemoApp.h app to the Header file, the code should work (if you did the cut and paste you might get an error), so scroll down on this page to see what it suppose to look like!

image

It’s ALIVE:

image