Dev C++ Visual Studio

Dev C++ Visual Studio 3,7/5 1913 votes

C/C support for Visual Studio Code is provided by a Microsoft C/C extension to enable cross-platform C and C development on Windows, Linux, and macOS. Getting started C/C compiler and debugger. The C/C extension does not include a C compiler or debugger. You will need to install these tools or use those already installed on your computer. Popular C compilers are: GCC on Linux. Microsoft Visual C Redistributable for Visual Studio 2019 This package installs run-time components of Visual C libraries and can be used to run such applications on a computer even if it does not have Visual Studio 2019 installed. Visual C is from Microsoft. It supports plain C in addition to windows libraries MFC, COM, Win32. If you want to develop applications for windows and want to do it faster use Visual Studio. Applications can also be developed with Dev C, but its a lot of work configuring the libraries and so on. Feb 03, 2018  In this video I am going to show, How to Set Up C Development With Visual Studio Code on Windows 10. We will use MinGW with VS code as our compiler and debugging tool. Yes, you very well can learn C using Visual Studio. Visual Studio comes with its own C compiler, which is actually the C compiler. Just use the.c file extension to save your source code. You don't have to be using the IDE to compile C. You can write the source in Notepad, and compile it in command line using Developer Command Prompt which.

-->

As part of the Visual Studio Integrated Development Environment (IDE), Microsoft C++ (MSVC) shares many windows and tools in common with other languages. Many of those, including Solution Explorer, the code editor, and the debugger, are documented under Visual Studio IDE. Often, a shared tool or window has a slightly different set of features for C++ than for other languages. A few windows or tools are only available in Visual Studio Professional or Visual Studio Enterprise editions.

In addition to shared tools in the Visual Studio IDE, MSVC has several tools specifically for native code development. These tools are also listed in this article. For a list of which tools are available in each edition of Visual Studio, see C++ Tools and Features in Visual Studio Editions.

Create projects

A project is basically a set of source code files and resources such as images or data files that are built into an executable program or library.

Visual Studio provides support for any project system or custom build tools that you wish to use, with full support for IntelliSense, browsing and debugging:

  • MSBuild is the native project system for Visual Studio. When you select File > New > Project from the main menu, you see many kinds of MSBuild project templates that get you started quickly developing different kinds of C++ applications.

    In general, you should use these templates for new projects unless you are using existing CMake projects, or you are using another project system. For more information, see Creating and managing MSBuild-based projects.

  • CMake is a cross-platform build system that is integrated into the Visual Studio IDE when you install the Desktop development with C++ workload. You can use the CMake project template for new projects, or simply open a folder with a CMakeLists.txt file. For more information, see CMake projects in Visual Studio.

  • Any other C++ build system, including a loose collection of files, is supported via the Open Folder feature. You create simple JSON files to invoke your build program and configure debugging sessions. For more information, see Open Folder projects for C++.

Add to source control

Source control enables you to coordinate work among multiple developers, isolate in-progress work from production code, and backup your source code. Visual Studio supports Git and Team Foundation Version Control (TFVC) through its Team Explorer window.

For more information about Git integration with repos in Azure, see Share your code with Visual Studio 2017 and Azure Repos Git. For information about Git integration with GitHub, see GitHub Extension for Visual Studio.

Obtain libraries

Use the vcpkg package manager to obtain and install third-party libraries. Over 900 open-source libraries are currently available in the catalog.

Create user interfaces with designers

If your program has a user interface, you can use a designer to quickly populate it with controls such as buttons, list boxes and so on. When you drag a control from the toolbox window and drop it onto the design surface, Visual Studio generates the resources and code required to make it all work. You then write the code to customize the appearance and behavior.

For more information about designing a user interface for a Universal Windows Platform app, see Design and UI.

For more information about creating a user interface for an MFC application, see MFC Desktop Applications. For information about Win32 Windows programs, see Windows Desktop Applications.

Write code

After you create a project, all the project files are displayed in the Solution Explorer window. (A solution is a logical container for one or more related projects.) When you click on a .h or .cpp file in Solution Explorer, the file opens up in the code editor.

The code editor is a specialized word processor for C++ source code. It color-codes language keywords, method and variable names, and other elements of your code to make the code more readable and easier to understand. It also provides tools for refactoring code, navigating between different files, and understanding how the code is structured. For more information, see Writing and refactoring code.

Add and edit resources

A Windows program or DLL usually includes some resources, such as dialogs, icons, images, localizable strings, splash screens, database connection strings, or any arbitrary data. Visual Studio includes tools for adding and editing resources. For more information, see Working with Resource Files.

Build (compile and link)

Choose Build > Build Solution on the menu bar, or enter the Ctrl+Shift+B key combination to compile and link a project. Build errors and warnings are reported in the Error List (Ctrl+, E). The Output Window (Alt+2) shows information about the build process.

For more information about configuring builds, see Working with Project Properties and Projects and build systems.

You can also use the compiler (cl.exe) and many other build-related standalone tools such as NMAKE and LIB directly from the command line. For more information, see Build C/C++ code on the command line and C/C++ Building Reference.

Debug

You can start debugging by pressing F5. Execution pauses on any breakpoints you have set (by pressing F9). You can also step through code one line at a time (F10), view the values of variables or registers, and even in some cases make changes in code and continue debugging without re-compiling. The following illustration shows a debugging session in which execution is stopped on a breakpoint. The values of the data structure members are visible in the Watch Window.

For more information, see Debugging in Visual Studio.

Test

Visual Studio includes the Microsoft Unit Test Framework for C++, as well as support for Boost.Test, Google Test, and CTest. Run your tests from the Test Explorer window:

For more information, see Verifying Code by Using Unit Tests and Write unit tests for C/C++ in Visual Studio.

Analyze

Visual Studio includes static code analysis tools that can detect potential problems in your source code. These tools include an implementation of the C++ Core Guidelines rules checkers. For more information, see Code analysis for C/C++ overview.

Deploy completed applications

You can deploy both traditional desktop applications and UWP apps to customers through the Microsoft Store. Deployment of the CRT is handled automatically behind the scenes. For more information, see Publish Windows apps and games.

You can also deploy a native C++ desktop to another computer. For more information, see Deploying Desktop Applications.

For more information about deploying a C++/CLI program, see Deployment Guide for Developers,

Next steps

Explore Visual Studio further by following along with one of these introductory articles:

-->

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.

Important

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

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

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

  3. 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.

  4. Choose the Create button to create the project.

  5. 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.

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

  7. 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.

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

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

  2. 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.

  3. 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.

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

  5. 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.

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

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

  2. 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.

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

  4. 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.

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

  6. 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.

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

  1. 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.

    September 21, 2018 (6,196). Drum kit online.

    Note

    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.

  2. Windows desktop programs require <windows.h>. <tchar.h> 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.

  3. 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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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

  1. 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 is to display the string 'Hello, Windows desktop!' in the window. In the following code, notice that the TextOut function is used to display the string.

    HDC in the code is a handle to a device context, which is a data structure that Windows uses to enable your application to communicate with the graphics subsystem. The BeginPaint and EndPaint functions make your application behave like a good citizen and doesn't use the device context for longer than it needs to. The functions help make the graphics subsystem is available for use by other applications.

  2. 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.

Dev Visual Studio Essentials

Build the code

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

To build this example

Visual Studio C++ Example

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

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

  3. 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.

Download Dev C++ Visual Studio

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

Visual Studio Dev Community

See also