Dev C++ Sample Project
- C++ Sample Programs
- Dev C++ Project
- Dev C++ Programs
- C++ Sample Projects
- Dev C++ Sample Program
- C# Sample Projects
C programs with output showing usage of operators, loops, functions, arrays, performing operations on strings, files, pointers. Download executable files and execute them without compiling the source file. Code::Blocks IDE is used to write programs, most of these will work with GCC and Dev C compilers. The first program, prints 'Hello World.'
- Apr 11, 2017 To build a DirectX desktop app, you can start with the Win32 Project template in the New Project dialog, or download a Win32 game template, or download a sample from DirectX11 samples or DirectX12 samples as a starting point. Write C code with the full power of the Visual Studio IDE.
- Programming with the Dev C IDE 1 Introduction to the IDE Dev-C is a full-featured Integrated Development Environment (IDE) for the C/C programming language. As similar IDEs, it offers to the programmer a simple and unified tool to edit, compile, link, and debug programs. It also provides support for the management of the.
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
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.
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.
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.
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.
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.
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 aWinMain
function.WinMain
has the following syntax.For information about the parameters and return value of this function, see WinMain entry point.
Note
What are all those extra words, such as
CALLBACK
, orHINSTANCE
, 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 <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.Along with the
WinMain
function, every Windows desktop application must also have a window-procedure function. This function is typically namedWndProc
, 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 typicalWNDCLASSEX
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 theTCHAR
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 aWM_PAINT
message. When the window is first displayed, all of it must be updated.Mar 06, 2019 Just about every genre of music from Hip Hop to Country is using Auto-Tune these days. The new Auto-Tune Pro from Antares is easily my favorite Auto-Tune to date. With new features like Flex-Tune. Aug 20, 2017 How to Autotune your voice for a professional vocal processing sound. Vocal Production and Tuning singing can be done quickly with the auto tune plugin by UAD and Antares. This plug-in gets used. Auto tune my recording app. Jun 16, 2018 Turn on my Notifications and Dm Me Your Soundcloud song and a picture of the turned on notification thru INSTAGRAM DM only. Follow those steps and you will have a chance of being chosen to be. Home of the Auto-Tune plug-in, the music industry standard for pitch correction and vocal effects. Shop and learn about the best plug-ins for pitch correction, vocal effects, voice processing, and noise reduction. Auto-Tune Pro, Auto-Tune Artist, Auto-Tune EFX+, Auto-Tune Access, Harmony Engine, Mic.
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. TheBeginPaint
andEndPaint
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.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.
See also
-->C++ Sample Programs
The usual starting point for a C++ programmer is a 'Hello, world!' application that runs on the command line. That's what you'll create in Visual Studio in this step.
Prerequisites
- Have Visual Studio with the Desktop development with C++ workload installed and running on your computer. If it's not installed yet, see Install C++ support in Visual Studio.
Create your app project
Visual Studio uses projects to organize the code for an app, and solutions to organize your projects. A project contains all the options, configurations, and rules used to build your apps, and manages the relationship between all the project's files and any external files. To create your app, first, you'll create a new project and solution.
In Visual Studio, open the File menu and choose New > Project to open the Create a new Project dialog. Select the Console App template, and then choose Next.
In the Configure your new project dialog, enter HelloWorld in the Project name edit box. Choose Create to create the project.
Visual Studio creates a new project, ready for you to add and edit your source code. By default, the Console App template fills in your source code with a 'Hello World' app:
When the code looks like this in the editor, you're ready to go on to the next step and build your app.
In Visual Studio, open the File menu and choose New > Project to open the New Project dialog.
In the New Project dialog, select Installed, Visual C++ if it isn't selected already, and then choose the Empty Project template. In the Name field, enter HelloWorld. Choose OK to create the project.
Visual Studio creates a new, empty project, ready for you to specialize for the kind of app you want to create and to add your source code files. You'll do that next.
Make your project a console app
Visual Studio can create all kinds of apps and components for Windows and other platforms. The Empty Project template isn't specific about what kind of app it creates. To create a console app, one that runs in a console or command prompt window, you must tell Visual Studio to build your app to use the console subsystem.
In Visual Studio, open the Project menu and choose Properties to open the HelloWorld Property Pages dialog.
In the Property Pages dialog, under Configuration Properties, select Linker, System, and then choose the edit box next to the Subsystem property. In the dropdown menu that appears, select Console (/SUBSYSTEM:CONSOLE). Choose OK to save your changes.
Visual Studio now knows to build your project to run in a console window. Next, you'll add a source code file and enter the code for your app.
Add a source code file
In Solution Explorer, select the HelloWorld project. On the menu bar, choose Project, Add New Item to open the Add New Item dialog.
In the Add New Item dialog, select Visual C++ under Installed if it isn't selected already. In the center pane, select C++ file (.cpp). Change the Name to HelloWorld.cpp. Choose Add to close the dialog and create the file.
Visual studio creates a new, empty source code file and opens it in an editor window, ready to enter your source code.
Add code to the source file
Copy this code into the HelloWorld.cpp editor window.
The code should look like this in the editor window:
When the code looks like this in the editor, you're ready to go on to the next step and build your app.
Next Steps
Troubleshooting guide
Come here for solutions to common issues when you create your first C++ project.
Create your app project issues
Dev C++ Project
If the New Project dialog doesn't show a Visual C++ entry under Installed, your copy of Visual Studio probably doesn't have the Desktop development with C++ workload installed. You can run the installer right from the New Project dialog. Choose the Open Visual Studio Installer link to start the installer again. If the User Account Control dialog requests permissions, choose Yes. In the installer, make sure the Desktop development with C++ workload is checked, and choose OK to update your Visual Studio installation.
If another project with the same name already exists, choose another name for your project, or delete the existing project and try again. To delete an existing project, delete the solution folder (the folder that contains the helloworld.sln file) in File Explorer.
Dev C++ Programs
Go back.
Make your project a console app issues
If you don't see Linker listed under Configuration Properties, choose Cancel to close the Property Pages dialog and then make sure that the HelloWorld project is selected in Solution Explorer, not the solution or another file or folder, before you try again.
The dropdown control does not appear in the SubSystem property edit box until you select the property. You can select it by using the pointer, or you can press Tab to cycle through the dialog controls until SubSystem is highlighted. Choose the dropdown control or press Alt+Down to open it.
Add a source code file issues
It's okay if you give the source code file a different name. However, don't add more than one source code file that contains the same code to your project.
C++ Sample Projects
If you added the wrong kind of file to your project, for example, a header file, delete it and try again. To delete the file, select it in Solution Explorer and press the Delete key.
Go back.
Add code to the source file issues
Dev C++ Sample Program
If you accidentally closed the source code file editor window, to open it again, double-click on HelloWorld.cpp in the Solution Explorer window.
C# Sample Projects
If red squiggles appear under anything in the source code editor, check that your code matches the example in spelling, punctuation, and case. Case is significant in C++ code.
Go back.