{"id":14547,"date":"2017-04-17T17:06:22","date_gmt":"2017-04-18T01:06:22","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=14547"},"modified":"2022-08-17T17:31:38","modified_gmt":"2022-08-17T17:31:38","slug":"windows-desktop-development-with-c-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/windows-desktop-development-with-c-in-visual-studio\/","title":{"rendered":"Windows desktop development with C++ in Visual Studio"},"content":{"rendered":"<p><div class=\"alert alert-info\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Content outdated<\/strong><\/p> For up-to-date documentation see <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/windows\/overview-of-windows-programming-in-cpp?view=msvc-170\">Overview of Windows Programming in C++<\/a>.<\/p>\n<p>For an overview of the Visual Studio capabilities described in this article, see <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/features\/cplusplus\/\">Develop C and C++ applications<\/a>.<\/div>The Windows desktop platform has long been the most popular platform among C++ application developers.\u00a0 With C++ and Visual Studio, you use Windows SDKs to target many versions of Windows ranging from Windows XP to Windows 10, which is well over a billion devices.\u00a0 Popular desktop applications like Microsoft Office, Adobe Creative Suite, and Google Chrome all are built using the same Win32 APIs that serve as the foundation for Windows desktop development.\u00a0 Developing for Windows desktop allows you to reach the highest number of users on any non-mobile development platform.<\/p>\n<p>In this post we will dive into the \u201cDesktop development with C++\u201d workload inside Visual Studio\u00a0and go over the\u00a0workflow used to develop a desktop app. \u00a0For information on developing Universal Windows Platform apps, <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/04\/17\/universal-windows-platform-development-with-c\/\">check out this post<\/a>.<\/p>\n<ul>\n<li><a href=\"#installation\">Acquiring the tools<\/a><\/li>\n<li><a href=\"#opening\">Opening code and building<\/a><\/li>\n<li><a href=\"#creating\">Creating new projects<\/a><\/li>\n<li><a href=\"#editing\">Editing code<\/a><\/li>\n<li><a href=\"#debugging\">Debugging and diagnostics<\/a><\/li>\n<li><a href=\"#testing\">Testing<\/a><\/li>\n<li><a href=\"#teamwork\">Working with others<\/a><\/li>\n<li><a href=\"#winstore\">Windows Store packaging<\/a><\/li>\n<\/ul>\n<h2 id=\"installation\">Acquiring the tools<\/h2>\n<p>After installing Visual Studio, open the Visual Studio Installer from the Start menu and navigate to the Workloads Page. We need to install the \u201cDesktop development with C++\u201d workload, which provides the tools needed for developing Windows desktop applications that can run on Windows.\u00a0 The Win32 API model used in these types of applications is the development model used in Windows versions prior to the introduction of the modern Windows API that began with Windows 8.\u00a0 This modern API later evolved into the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/windows\/uwp\/get-started\/universal-application-platform-guide\">UWP platform for Windows 10<\/a>, but traditional desktop development using Windows APIs is still fully supported on all versions of Windows.<\/p>\n<p>When you install the C++ Windows desktop workload, you have many options to customize the installation by selecting your desired tools, Windows SDKs, and other additional features like recent ISO C++ standards candidates such modules support for the STL. \u00a0The core C++ compiler and libraries for building desktop applications that target x86 and x64 systems are included in the <em>VC++ 2017 v141 toolset (x86, x64).<\/em>\u00a0 Notable optional tools include support for MFC and C++\/CLI development.\u00a0 In the following examples, we will show how to create an MFC app, so this optional component was installed.<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?attachment_id=14565\"><img decoding=\"async\" class=\"alignnone size-large wp-image-14565\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/desktopwl.png\" alt=\"desktopwl\" width=\"249\" height=\"394\" \/><\/a><\/p>\n<h2>Opening code and building<\/h2>\n<p>After installing the C++ desktop workload, you can begin coding in existing projects or you can create new ones. Out of the box, Visual Studio can open any folder of code and be configured to build using CMake, a cross-platform build system. The Visual Studio CMake integration even allows you to use another compiler by opening the directory containing your CMakeLists.txt files and let VS do the rest.<\/p>\n<p>Of course ,there is also full support for Microsoft\u2019s own build system called <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/0k6kkbsd.aspx\">MSBuild<\/a>, which uses the .vcxproj file format.\u00a0 MSBuild is a robust and fully featured build system that allows building projects in Visual Studio that target Windows. Building an MSBuild-based project just requires a .vcxproj file and can be built in the IDE or by <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms164311.aspx\">using the command prompt<\/a>.<\/p>\n<p>In Visual Studio 2017, you can also simply open a folder of code files and immediately begin working in it. In the background, Visual Studio will index your files and providing Intellisense support along with refactoring and all the other navigation aids that you expect. You can create custom .json scripts to specify build configurations.<\/p>\n<h2 id=\"creating\">Creating new projects<\/h2>\n<p>If you are creating a new project from scratch, then you can start with one of a variety of project templates.: Each template provides customizable build configurations and boilerplate code that compiles and runs out of the box:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"97\"><strong>Project Type (folder)<\/strong><\/td>\n<td width=\"817\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"95\">Win32<\/td>\n<td width=\"819\">The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/bb384843.aspx\">Win32 API<\/a> (also known as the Windows API) is a C-based framework for creating GUI-based Windows desktop applications that have a message loop and react to Windows messages and commands. A Win32 console application has no GUI by default\u00a0and runs in a console window from the\u00a0command line.<\/td>\n<\/tr>\n<tr>\n<td width=\"95\">ATL<\/td>\n<td width=\"826\">The <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/3ax346b7.aspx\">Active Template Library<\/a> is a set of template-based C++ classes that let you create small, fast Component Object Model (COM) objects. COM<\/td>\n<\/tr>\n<tr>\n<td width=\"95\">MFC<\/td>\n<td width=\"819\"><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/d06h2x6e.aspx\">Microsoft Foundation Classes<\/a> is an object oriented wrapper over the Win32 API that provides designers and extensive code-generation support for creating a native UI.<\/td>\n<\/tr>\n<tr>\n<td width=\"95\">CLR<\/td>\n<td width=\"819\"><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/68td296t.aspx\">C++\/CLI<\/a> (Common Language Interface) enables \u00a0efficient communication between native C++ code and .NET code written in languages such as C# or Visual Basic.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Project templates are included for each of these types of desktop applications depending on the features you select for the workload.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14605\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/templates.png\" alt=\"templates\" width=\"879\" height=\"240\" \/><\/p>\n<h3>Project Wizard<\/h3>\n<p>Once you have selected a template, you have the option to customize the project you have selected to create.\u00a0 Each of these project types has a wizard to help you create and customize your new project. \u00a0The illustrations below show the wizard for an MFC application.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14615\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/wizard.png\" alt=\"wizard\" width=\"670\" height=\"525\" \/><\/p>\n<p>The wizard creates and opens a new project for you and your project files will show up in Solution Explorer.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14596\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/solnexp1.png\" alt=\"solnexp\" width=\"350\" height=\"418\" \/><\/p>\n<p>At this point, even before you write a single line of code, you can build and run the application by pressing F5.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14586\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/mfcapp-1024x606.png\" alt=\"mfcapp\" width=\"879\" height=\"520\" \/><\/p>\n<h2 id=\"editing\">Editing code and navigating<\/h2>\n<p>Visual Studio provides many features that help you to code correctly and more efficiently. Whether it be the powerful predictive capabilities provided by <strong>IntelliSense<\/strong> or the fluid navigation found in <strong>Navigate To<\/strong> there is a feature to make almost any action faster inside Visual Studio.\u00a0 Let Visual Studio do the work for you with autocompletion simply by pressing Tab on the item you want to add from the member list.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14585\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/intellisense.png\" alt=\"intellisense\" width=\"413\" height=\"348\" \/><\/p>\n<p>You can also hover over any variable, function, or other code symbol and get information about that symbol using the quick info feature.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14575\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/infotip.png\" alt=\"infotip\" width=\"406\" height=\"98\" \/><\/p>\n<p>There are also many great code navigation features to make dealing with large code bases much more productive, including <strong>Go To Definition<\/strong>, <strong>Go To Line\/Symbols\/Members\/Types<\/strong>, <strong>Find All References<\/strong>, <strong>View Call Hierarchy,<\/strong> <strong>Object Browser<\/strong>, and more.\u00a0 <strong>Peek Definition<\/strong> allows you to view the code that defines the selected variable without even having to open another file which minimizes context switching.<\/p>\n<h2><img decoding=\"async\" class=\"alignnone size-full wp-image-14555\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/codepeak.png\" alt=\"codepeak\" width=\"560\" height=\"381\" \/><\/h2>\n<p>We also have support for some of the more common refactoring techniques like rename and extract function that allow you to keep your code looking nice and consistent.<\/p>\n<h2 id=\"debugging\">Debugging and Diagnostics<\/h2>\n<p>Debugging applications is what Visual Studio is famous for!\u00a0 With a world-class debugging experience that provides a plethora of tools for any type of app, no tool is better suited to debugging applications that target the Windows desktop platform.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14556\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/datatip.png\" alt=\"datatip\" width=\"855\" height=\"107\" \/><\/p>\n<p>Powerful features like advanced breakpoints, custom data visualization, and debug-time profiling enable you to have full control of your app\u2019s execution and pinpoint even the hardest to find bugs.\u00a0 View data values from your code with debugger data tips.\u00a0 Take memory snapshots and diff them to reveal potential memory leaks, and even invoke<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/hardware\/ff549561(v=vs.85).aspx\"> PageHeap<\/a> on your app from inside Visual Studio to help solve the notoriously hard problem of memory corruption.\u00a0 Track live CPU and memory usage while your application runs and monitor performance in real-time.<a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?attachment_id=14625\"><img decoding=\"async\" class=\"alignnone size-full wp-image-14625\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/hub.png\" alt=\"hub\" width=\"452\" height=\"462\" \/><\/a><\/p>\n<h2 id=\"testing\">Testing your code<\/h2>\n<p>Unit testing is a very popular way of improving code quality, and test-driven-development is fully supported inside Visual Studio. \u00a0 Create new tests and <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh419385.aspx\">manage<\/a><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh419385.aspx\">\u00a0them inside the Test Explorer<\/a>\u00a0for easy tracking and execution of tests. \u00a0<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/hh598953.aspx\">Writing unit tests is easy<\/a> and can help find problems as they arise instead of later on when things are harder to isolate.\u00a0 Visual Studio allows both native and managed test project templates for testing native code which can be found in the <em>Visual C++\/<\/em><em>Test<\/em> section of the new project templates.\u00a0 Note that the native test template comes with the C++ desktop workload and the managed test comes with the .NET desktop workload.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-large wp-image-14645\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/test.png\" alt=\"test\" width=\"372\" height=\"517\" \/><\/p>\n<h2 id=\"teamwork\">Working with others<\/h2>\n<p>Besides all of the individual developer activities that Visual Studio makes more productive, collaboration is also something that is directly integrated into the IDE.\u00a0 Visual Studio Team Services is a suite of features that optimize the team collaboration process for software development organizations.\u00a0 Create work items, track progress, and manage your bug and open issue database all from inside Visual Studio.\u00a0 Git is fully supported and works seamlessly with the Team Explorer, allowing for easy management of branches, commits, and pull requests.<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?attachment_id=14635\"><img decoding=\"async\" class=\"alignnone wp-image-14635\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/teamexp.jpg\" alt=\"teamexp\" width=\"422\" height=\"314\" \/><\/a><\/p>\n<p>Simply <a href=\"https:\/\/go.microsoft.com\/fwlink\/?LinkId=307137\">sign up for a Visual Studio Team Services account for free<\/a>, then you can track the source code of your desktop applications into Visual Studio Team Services. \u00a0Visual Studio Team Services also simplifies continuous integrations for your desktop applications. Create and manage build processes that automatically compile and test your apps in the cloud.<\/p>\n<h2 id=\"winstore\">Windows Store packaging for desktop apps<\/h2>\n<p>When you are ready to deploy your desktop application, you would typically build an executable (.exe) and possibly some libraries so that your application can run on a Windows device.\u00a0 This allows you to easily distribute your application however you like, for example via a download from your website or even through a third-party sales platform such as Steam.<\/p>\n<p>A new option for Windows desktop apps is to be available in the Windows Store with all the advantages that entails. The <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2016\/07\/07\/using-visual-c-runtime-in-centennial-project\/\">Desktop Bridge project<\/a>\u00a0allows you to package and distribute your Win32 application through the Windows Store alongside <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=14655&amp;preview=true\">Universal Windows Platform apps<\/a>. When targeting Windows 10, this can provide advantages including streamlined deployment, greater reach, simpler monetization, simplified setup authoring, and differential updates.<\/p>\n<h2>Try out Visual Studio 2017 for desktop development with C++!<\/h2>\n<p><a href=\"https:\/\/aka.ms\/vs\/15\/release\/vs_Community.exe\">Download Visual Studio 2017<\/a>, try it out and share your feedback.\u00a0 For problems, let us know via the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a> option in the upper right corner of the VS title bar. \u00a0Track your feedback on the <a href=\"https:\/\/developercommunity.visualstudio.com\/index.html\">developer community portal<\/a>. For suggestions, let us know through <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">UserVoice<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Windows desktop platform has long been the most popular platform among C++ application developers.\u00a0 With C++ and Visual Studio, you use Windows SDKs to target many versions of Windows ranging from Windows XP to Windows 10, which is well over a billion devices.\u00a0 Popular desktop applications like Microsoft Office, Adobe Creative Suite, and Google [&hellip;]<\/p>\n","protected":false},"author":295,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>The Windows desktop platform has long been the most popular platform among C++ application developers.\u00a0 With C++ and Visual Studio, you use Windows SDKs to target many versions of Windows ranging from Windows XP to Windows 10, which is well over a billion devices.\u00a0 Popular desktop applications like Microsoft Office, Adobe Creative Suite, and Google [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/14547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/295"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=14547"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/14547\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=14547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=14547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=14547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}