How to make windows apps

Build desktop apps for Windows PCs

This article provides the info you need to get started building desktop apps for Windows or updating existing desktop apps to adopt the latest experiences in Windows 10.

Platforms for desktop apps

There are four main platforms for building desktop apps for Windows PCs. Each platform provides an app model that defines the lifecycle of the app, a complete UI framework and set of UI controls that let you create desktop apps like Word, Excel, and Photoshop, and access to a comprehensive set of managed or native APIs for using Windows features.

For an in-depth comparison of these platforms along with additional resources for each platform, see Choose your app platform.

The leading-edge platform for Windows 10 apps and games. You can build UWP apps that exclusively use UWP controls and APIs, or you can use UWP controls and APIs in desktop apps that are built using one of the other platforms.

The platform of choice for native Windows apps that require direct access to Windows and hardware.

The established .NET-based platform for graphically-rich managed Windows apps with a XAML UI model. These apps can target .NET Core 3 or the full .NET Framework.

A .NET-based platform that is designed for managed line-of-business apps with a lightweight UI model. These apps can target .NET Core 3 or the full .NET Framework.

Future roadmap

Looking forward, we are evolving the Windows app development platforms with the Windows UI Library (WinUI) and Project Reunion.

WinUI is a native user experience (UX) framework for Windows 10 apps. WinUI started as a toolkit that provides new and updated versions of WinRT controls for UWP apps that target down-level versions of Windows 10. As of WinUI 3, WinUI is growing in scope to become the premier native user interface (UI) framework for Windows 10 apps across UWP, .NET, and Win32 app platforms.

Project Reunion is the code name for a broad set of new developer components and tools that represents the next evolution in the Windows app development platform. Project Reunion provides a unified set of APIs and tools that can be used in a consistent way by any app on a broad set of target Windows 10 OS versions. Project Reunion complements existing Windows app platforms and frameworks such as UWP and native Win32, and .NET with a common set of APIs and tools that developers can rely on across these platforms.

For more information, see Project Reunion.

Update existing desktop apps for Windows 10

If you have an existing WPF, Windows Forms, or native Win32 desktop app, Windows 10 and the Universal Windows Platform (UWP) offer many features you can use to deliver a modern experience in your app. Most of these features are available as modular components that you can adopt in your app at your own pace without having to rewrite your app for a different platform.

Here are just a few of the features available to enhance your existing desktop apps:

  • Use MSIX to package and deploy your desktop apps. MSIX is a modern Windows app package format that provides a universal packaging experience for all Windows apps. MSIX brings together the best aspects of MSI, .appx, App-V and ClickOnce installation technologies and is built to be safe, secure, and reliable.
  • Integrate your desktop app with Windows 10 experiences by using package extensions. For example, point Start tiles to your app, make your app a share target, or send toast notifications from your app.
  • Use XAML Islands to host UWP XAML controls in your desktop app. Many of the latest Windows 10 UI features are only available to UWP XAML controls.

For more information, see these articles.

Platform Description Docs and resources
Universal Windows Platform (UWP)
Article Description
Modernize desktop apps Describes the latest Windows 10 and UWP development features you can use in any desktop app, including WPF, Windows Forms, and C++ Win32 apps.
Tutorial: Modernize a WPF app Follow step-by-step instructions to modernize an existing WPF line-of-business sample app by adding UWP Ink and calendar controls to the app and packaging it in an MSIX package.

Create new desktop apps

If you are creating a new desktop app for Windows, here are some resources to help get you started.

Start coding

Welcome to the UWP platform! On this page, we’ll point you at the right information you need to start coding the Windows 10 apps you want to create.

Before you begin development, you should be sure to get set up.

Learning tracks

The following learning tracks show you what you need to know to complete some basic tasks, and where you can find that info. They aren’t tutorials, but they provide reference code to ensure you’re on the right track.

Task Description
Construct a form Learn how to create a form that’s easy to use and looks good no matter the screen size.
Display customers in a list Learn how to display and edit data in your UI.
Save and load settings Learn how and where to save and retrieve settings.
Work with files Learn how to read from and write to files, and which folders you do and don’t have access to.

All our learning tracks are written for experienced devs who are getting familiar with Windows 10. If you’re just beginning, start with our content for new developers.

For new developers

If you’re a new dev, Microsoft has many resources to teach you the basics of how to use the code and tools that you’ll need for Windows 10 development.

If you want a more detailed walkthrough on the basics of coding, the C# language, Visual Studio, or the features of the Universal Windows Platform, you should check out the following resources:

Docs:

Tutorials:

Using the docs

If you’ve already explored our learning tracks, or if you’re interested in something they don’t cover, you should take your own tour through our documentation. Here’s a quick overview of what you can expect to find in each area:

Area Description
What’s New? Each major update of Windows 10 sees our docs expanded with new guidance. These docs have information about the feature into and developer guidance we’ve added for every release, as well as lists of new APIs: What’s new for devs in the latest Windows 10 release
Design and UI All information on the visual presentation and UI of your app is contained in this area of the docs. If you’re interested on the specifics of the XAML markup language or just want to create a unique look for your docs, start here: Design basics for UWP apps
Develop apps If you want detailed information on a specific Windows 10 feature, or are just interested in seeing what you can do with UWP development, check out this area of our docs: UWP app features. API reference for Windows 10 apps is hosted in a related set of docs, which you can find here: Windows UWP namespaces File and XML schemas
Develop games These docs contain information on how to develop games on Windows or Xbox. This includes setup instructions, developer programs, and instructions for programming with DirectX or Xbox features. Getting started with game development
Publish These docs contain information on how to publish your app to the Windows Store, from app submission to pricing to promotion and customer engagement: Publish your app to the Windows Store

Other docs

Some specialized Windows 10 platforms, like web development or Mixed Reality, have their own doc sets. If you’re interested in developing an app with those features, check out their documentation:

Walkthrough: Create a traditional Windows Desktop application (C++)

This walkthrough shows how to create a traditional Windows desktop application in Visual Studio. The example application you’ll create uses the Windows API to display «Hello, Windows desktop!» in a window. You can use the code that you develop in this walkthrough as a pattern to create other Windows desktop applications.

The Windows API (also known as the Win32 API, Windows Desktop API, and Windows Classic API) is a C-language-based framework for creating Windows applications. It has been in existence since the 1980s and has been used to create Windows applications for decades. More advanced and easier-to-program frameworks have been built on top of the Windows API. For example, MFC, ATL, the .NET frameworks. Even the most modern Windows Runtime code for UWP and Store apps written in C++/WinRT uses the Windows API underneath. For more information about the Windows API, see Windows API Index. There are many ways to create Windows applications, but the process above was the first.

For the sake of brevity, some code statements are omitted in the text. The Build the code section at the end of this document shows the complete code.

Prerequisites

A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 10 for the best development experience.

A copy of Visual Studio. For information on how to download and install Visual Studio, see Install Visual Studio. When you run the installer, make sure that the Desktop development with C++ workload is checked. Don’t worry if you didn’t install this workload when you installed Visual Studio. You can run the installer again and install it now.

An understanding of the basics of using the Visual Studio IDE. If you’ve used Windows desktop apps before, you can probably keep up. For an introduction, see Visual Studio IDE feature tour.

An understanding of enough of the fundamentals of the C++ language to follow along. Don’t worry, we don’t do anything too complicated.

Create a Windows desktop project

Follow these steps to create your first Windows desktop project. As you go, you’ll enter the code for a working Windows desktop application. To see the documentation for your preferred version of Visual Studio, use the Version selector control. It’s found at the top of the table of contents on this page.

To create a Windows desktop project in Visual Studio 2019

From the main menu, choose File > New > Project to open the Create a New Project dialog box.

At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Desktop.

From the filtered list of project types, choose Windows Desktop Wizard then choose Next. In the next page, enter a name for the project, for example, DesktopApp.

Choose the Create button to create the project.

The Windows Desktop Project dialog now appears. Under Application type, select Desktop application (.exe). Under Additional options, select Empty project. Choose OK to create the project.

In Solution Explorer, right-click the DesktopApp project, choose Add, and then choose New Item.

In the Add New Item dialog box, select C++ File (.cpp). In the Name box, type a name for the file, for example, HelloWindowsDesktop.cpp. Choose Add.

Visual C plus plus selected and the C plus plus File option highlighted.» title=»Add .cpp file to DesktopApp Project» data-linktype=»relative-path»>

Your project is now created and your source file is opened in the editor. To continue, skip ahead to Create the code.

To create a Windows desktop project in Visual Studio 2017

On the File menu, choose New and then choose Project.

In the New Project dialog box, in the left pane, expand Installed > Visual C++, then select Windows Desktop. In the middle pane, select Windows Desktop Wizard.

In the Name box, type a name for the project, for example, DesktopApp. Choose OK.

Visual C plus plus > Windows Desktop selected, the Windows Desktop Wizard option highlighted, and DesktopApp typed in the Name text box.» title=»Name the DesktopApp project» data-linktype=»relative-path»>

In the Windows Desktop Project dialog, under Application type, select Windows application (.exe). Under Additional options, select Empty project. Make sure Precompiled Header isn’t selected. Choose OK to create the project.

In Solution Explorer, right-click the DesktopApp project, choose Add, and then choose New Item.

In the Add New Item dialog box, select C++ File (.cpp). In the Name box, type a name for the file, for example, HelloWindowsDesktop.cpp. Choose Add.

Visual C plus plus selected and the C plus plus File option highlighted.» title=»Add .cpp file to DesktopApp Project» data-linktype=»relative-path»>

Your project is now created and your source file is opened in the editor. To continue, skip ahead to Create the code.

To create a Windows desktop project in Visual Studio 2015

On the File menu, choose New and then choose Project.

In the New Project dialog box, in the left pane, expand Installed > Templates > Visual C++, and then select Win32. In the middle pane, select Win32 Project.

In the Name box, type a name for the project, for example, DesktopApp. Choose OK.

Templates > Visual C plus plus > Win32 selected, the Win32 Project option highlighted, and DesktopApp typed in the Name text box.» title=»Name the DesktopApp project» data-linktype=»relative-path»>

On the Overview page of the Win32 Application Wizard, choose Next.

On the Application Settings page, under Application type, select Windows application. Under Additional options, uncheck Precompiled header, then select Empty project. Choose Finish to create the project.

In Solution Explorer, right-click the DesktopApp project, choose Add, and then choose New Item.

In the Add New Item dialog box, select C++ File (.cpp). In the Name box, type a name for the file, for example, HelloWindowsDesktop.cpp. Choose Add.

Visual C plus plus selected and the C plus plus File option highlighted.» title=»Add .cpp file to DesktopApp Project» data-linktype=»relative-path»>

Your project is now created and your source file is opened in the editor.

Create the code

Next, you’ll learn how to create the code for a Windows desktop application in Visual Studio.

To start a Windows desktop application

Just as every C application and C++ application must have a main function as its starting point, every Windows desktop application must have a WinMain function. WinMain has the following syntax.

For information about the parameters and return value of this function, see WinMain entry point.

What are all those extra words, such as CALLBACK , or HINSTANCE , or _In_ ? The traditional Windows API uses typedefs and preprocessor macros extensively to abstract away some of the details of types and platform-specific code, such as calling conventions, __declspec declarations, and compiler pragmas. In Visual Studio, you can use the IntelliSense Quick Info feature to see what these typedefs and macros define. Hover your mouse over the word of interest, or select it and press Ctrl+K, Ctrl+I for a small pop-up window that contains the definition. For more information, see Using IntelliSense. Parameters and return types often use SAL Annotations to help you catch programming errors. For more information, see Using SAL Annotations to Reduce C/C++ Code Defects.

Windows desktop programs require . defines the TCHAR macro, which resolves ultimately to wchar_t if the UNICODE symbol is defined in your project, otherwise it resolves to char . If you always build with UNICODE enabled, you don’t need TCHAR and can just use wchar_t directly.

Along with the WinMain function, every Windows desktop application must also have a window-procedure function. This function is typically named WndProc , but you can name it whatever you like. WndProc has the following syntax.

In this function, you write code to handle messages that the application receives from Windows when events occur. For example, if a user chooses an OK button in your application, Windows will send a message to you and you can write code inside your WndProc function that does whatever work is appropriate. It’s called handling an event. You only handle the events that are relevant for your application.

For more information, see Window Procedures.

To add functionality to the WinMain function

In the WinMain function, you populate a structure of type WNDCLASSEX. The structure contains information about the window: the application icon, the background color of the window, the name to display in the title bar, among other things. Importantly, it contains a function pointer to your window procedure. The following example shows a typical WNDCLASSEX structure.

For information about the fields of the structure above, see WNDCLASSEX.

Register the WNDCLASSEX with Windows so that it knows about your window and how to send messages to it. Use the RegisterClassEx function and pass the window class structure as an argument. The _T macro is used because we use the TCHAR type.

Now you can create a window. Use the CreateWindow function.

This function returns an HWND , which is a handle to a window. A handle is somewhat like a pointer that Windows uses to keep track of open windows. For more information, see Windows Data Types.

At this point, the window has been created, but we still need to tell Windows to make it visible. That’s what this code does:

The displayed window doesn’t have much content because you haven’t yet implemented the WndProc function. In other words, the application isn’t yet handling the messages that Windows is now sending to it.

To handle the messages, we first add a message loop to listen for the messages that Windows sends. When the application receives a message, this loop dispatches it to your WndProc function to be handled. The message loop resembles the following code.

For more information about the structures and functions in the message loop, see MSG, GetMessage, TranslateMessage, and DispatchMessage.

At this point, the WinMain function should resemble the following code.

To add functionality to the WndProc function

To enable the WndProc function to handle the messages that the application receives, implement a switch statement.

One important message to handle is the WM_PAINT message. The application receives the WM_PAINT message when part of its displayed window must be updated. The event can occur when a user moves a window in front of your window, then moves it away again. Your application doesn’t know when these events occur. Only Windows knows, so it notifies your app with a WM_PAINT message. When the window is first displayed, all of it must be updated.

To handle a WM_PAINT message, first call BeginPaint, then handle all the logic to lay out the text, buttons, and other controls in the window, and then call EndPaint. For the application, the logic between the beginning call and the ending call displays the string «Hello, Windows desktop!» in the window. In the following code, the TextOut function is used to display the string.

HDC in the code is a handle to a device context, which is used to draw in the window’s client area. Use the BeginPaint and EndPaint functions to prepare for and complete the drawing in the client area. BeginPaint returns a handle to the display device context used for drawing in the client area; EndPaint ends the paint request and releases the device context.

An application typically handles many other messages. For example, WM_CREATE when a window is first created, and WM_DESTROY when the window is closed. The following code shows a basic but complete WndProc function.

Build the code

As promised, here’s the complete code for the working application.

To build this example

Delete any code you’ve entered in HelloWindowsDesktop.cpp in the editor. Copy this example code and then paste it into HelloWindowsDesktop.cpp:

On the Build menu, choose Build Solution. The results of the compilation should appear in the Output window in Visual Studio.

To run the application, press F5. A window that contains the text «Hello, Windows desktop!» should appear in the upper-left corner of the display.

Congratulations! You’ve completed this walkthrough and built a traditional Windows desktop application.

Читайте также:  Qttabbar windows 10 настройка
Оцените статью