Chuyển tới nội dung
Home » Win32 Visual Studio 2017 | Create A Windows Desktop Project

Win32 Visual Studio 2017 | Create A Windows Desktop Project

How to create C++ Win32 app in Visual Studio 2017

Build the code

As promised, the complete code for the working application follows.

To build this example

  1. Delete all the code in HelloWindowsDesktop.cpp in the editor. Copy this example code and paste it into HelloWindowsDesktop.cpp:


    // HelloWindowsDesktop.cpp // compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c #include

    #include

    #include

    #include

    // Global variables // The main window class name. static TCHAR szWindowClass[] = _T("DesktopApp"); // The string that appears in the application's title bar. static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application"); // Stored instance handle for use in Win32 API calls such as FindResource HINSTANCE hInst; // Forward declarations of functions included in this code module: LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow ) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION); if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; } // Store instance handle in our global variable hInst = hInstance; // The parameters to CreateWindowEx explained: // WS_EX_OVERLAPPEDWINDOW : An optional extended window style. // szWindowClass: the name of the application // szTitle: the text that appears in the title bar // WS_OVERLAPPEDWINDOW: the type of window to create // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y) // 500, 100: initial size (width, length) // NULL: the parent of this window // NULL: this application does not have a menu bar // hInstance: the first parameter from WinMain // NULL: not used in this application HWND hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; } // The parameters to ShowWindow explained: // hWnd: the value returned from CreateWindow // nCmdShow: the fourth parameter from WinMain ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // Main message loop: MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam; } // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; TCHAR greeting[] = _T("Hello, Windows desktop!"); switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // Here your application is laid out. // For this introduction, we just print out "Hello, Windows desktop!" // in the top left corner. TextOut(hdc, 5, 5, greeting, _tcslen(greeting)); // End application-specific layout section. EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; }




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

    The animation shows clicking the save all button, then choosing Build > Build Solution from the main menu.

  3. To run the application, press F5. A window with the text “Hello, Windows desktop!” should appear.

Congratulations! You’ve built a traditional Windows desktop application.

All Downloads

Windows platforms (CRT)

The C run-time libraries for Visual Studio support all versions of Windows and Windows Server that are still in extended support. Visual Studio 2015 supports Windows 8 and 8.1, Windows Server 2012, Windows 7, Windows Server 2008, and Windows Vista. It optionally supports Windows XP Service Pack 3 (SP3) for x86, Windows XP Service Pack 2 (SP2) for x64, and Windows Server 2003 Service Pack 2 (SP2) for both x86 and x64. All of these operating systems support the Windows desktop API (Win32) and provide Unicode support. In addition, any Win32 application can use a multibyte character set (MBCS).

The C run-time libraries for Visual Studio support all versions of Windows and Windows Server that are still in extended support. Libraries are available for x86, x64, and ARM64. All of these operating systems support the Windows desktop API (Win32) and provide Unicode support. In addition, any Win32 application can use a multibyte character set (MBCS).

Note

The default installation of the Desktop development with C++ workload in Visual Studio 2017 does not include support for Windows XP and Windows Server 2003 development. You must install the optional component Windows XP support for C++ to enable a Windows XP platform toolset.

How to create C++ Win32 app in Visual Studio 2017
How to create C++ Win32 app in Visual Studio 2017

Prerequisites

  • A computer that runs Microsoft Windows 7 or later versions. We recommend Windows 11 or later 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.

  • A basic understanding 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.

The code

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

Where code starts running in 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.

    int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow );

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

    Note

    What are all those extra words, such as


    WINAPI

    , or

    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

    . You’ll also frequently see

    #include

    . That’s to make it easier to write an app that can work with either

    char

    or

    wchar_t

    . The way it works is that you instead use the

    TCHAR

    macro in your code, 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. For more information, see Using generic-text mappings. The following code shows theses two

    #include

    statements at the top of the file.

    #include

    #include

  3. Along with the


    WinMain

    function, every Windows desktop application must also have a window-procedure function. This function is called a

    WndProc

    , but you can give it whatever name you like in your code.

    WndProc

    has the following syntax.

    LRESULT CALLBACK WndProc( _In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam );

    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 sends a message to you. You write code inside a


    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.

Add functionality to the WinMain function

  1. In the


    WinMain

    function, you need to capture some basic information about your main window. You do that by filling out a structure of type

    WNDCLASSEX

    . The structure contains information about the window such as 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 that handles the messages that Windows sends to your app. The following example shows a typical

    WNDCLASSEX

    structure:

    WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);

    For information about the fields of the structure above, see


    WNDCLASSEX

    .

  2. Once you have the


    WNDCLASSEX

    structure filled out, you register it 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 per the discussion about Unicode above. The following code shows how to register the window class.

    if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; }

  3. Next you create a window using the


    CreateWindowEx

    function.

    static TCHAR szWindowClass[] = _T("DesktopApp"); static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application"); // The parameters to CreateWindowEx explained: // WS_EX_OVERLAPPEDWINDOW : An optional extended window style. // szWindowClass: the name of the application // szTitle: the text that appears in the title bar // WS_OVERLAPPEDWINDOW: the type of window to create // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y) // 500, 100: initial size (width, length) // NULL: the parent of this window // NULL: this application does not have a menu bar // hInstance: the first parameter from WinMain // NULL: not used in this application HWND hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Call to CreateWindowEx failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; }

    This function returns an


    HWND

    , which is a handle to a window. A handle is somewhat like a pointer. Windows uses it to keep track of the windows you create. 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 parameters to ShowWindow explained: // hWnd: the value returned from CreateWindow // nCmdShow: the fourth parameter from WinMain ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);

    The displayed window is just a blank rectangle because you haven’t yet implemented the


    WndProc

    function. The application isn’t yet handling the messages that Windows is now sending to it.

  5. To handle the messages, we first add what’s called 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:

    MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam;

    For more information about the structures and functions in the message loop, see


    MSG

    ,

    GetMessage

    , TranslateMessage, and

    DispatchMessage

    .

    A basic


    WinMain

    function that creates the application’s main window, and listens for messages that Windows sends your app, would resemble the following code:

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION); if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; } // Store instance handle in our global variable hInst = hInstance; // The parameters to CreateWindowEx explained: // WS_EX_OVERLAPPEDWINDOW : An optional extended window style. // szWindowClass: the name of the application // szTitle: the text that appears in the title bar // WS_OVERLAPPEDWINDOW: the type of window to create // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y) // 500, 100: initial size (width, length) // NULL: the parent of this window // NULL: this application dows not have a menu bar // hInstance: the first parameter from WinMain // NULL: not used in this application HWND hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL ); if (!hWnd) { MessageBox(NULL, _T("Call to CreateWindow failed!"), _T("Windows Desktop Guided Tour"), NULL); return 1; } // The parameters to ShowWindow explained: // hWnd: the value returned from CreateWindow // nCmdShow: the fourth parameter from WinMain ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // Main message loop: MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam; }

Handle messages in the WndProc function

  1. To handle messages that the application receives, you implement a


    switch

    statement in your

    WndProc

    function.

    An important message to handle is


    WM_PAINT

    . The application receives a

    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 and moves it away again. It receives this message the first time your window is displayed, giving you a chance to display your application UI. Your application finds out about these events when Windows sends them. 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. Then call

    EndPaint

    . For this application, the code between

    BeginPaint()

    and

    EndPaint()

    displays

    Hello, Windows desktop!

    in the window you created in

    WinMain()

    . In the following code, the

    TextOut

    function displays the text at the specified location in the window.

    PAINTSTRUCT ps; HDC hdc; TCHAR greeting[] = _T("Hello, Windows desktop!"); switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // Here your application is laid out. // For this introduction, we just print out "Hello, Windows desktop!" // in the top left corner. TextOut(hdc, 5, 5, greeting, _tcslen(greeting)); // End application-specific layout section. EndPaint(hWnd, &ps); break; }

    In the preceding code,


    HDC

    is a handle to a device context which is associated with the window’s client area. You use it when drawing in the window to refer to its 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.

  2. An application typically handles many other messages. For example,


    WM_CREATE

    is sent when a window is first created, and

    WM_DESTROY

    when the window is closed. The following code shows a basic but complete

    WndProc

    function:

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; TCHAR greeting[] = _T("Hello, Windows desktop!"); switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // Here your application is laid out. // For this introduction, we just print out "Hello, Windows desktop!" // in the top left corner. TextOut(hdc, 5, 5, greeting, _tcslen(greeting)); // End application specific layout section. EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); break; } return 0; }

Correct configuration properties for building CrackMe's in Visual Studio 2017 win32
Correct configuration properties for building CrackMe’s in Visual Studio 2017 win32

Visual Studio 2019 Installation

Welcome to Visual Studio 2019! In this version, it’s easy to choose and install just the features you need. And because of its reduced minimum footprint, it installs quickly and with less system impact.

Note

This topic applies to installation of Visual Studio on Windows. Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn’t support Microsoft C++, but does support .NET languages and cross-platform development. For installation instructions, see Install Visual Studio for Mac.

Want to know more about what else is new in this version? See the Visual Studio release notes.

Ready to install? We walk you through it, step-by-step.

Step 1 – Make sure your computer is ready for Visual Studio

Before you begin installing Visual Studio:

  1. Check the system requirements. These requirements help you know whether your computer supports Visual Studio 2019.

  2. Apply the latest Windows updates. These updates ensure that your computer has both the latest security updates and the required system components for Visual Studio.

  3. Reboot. The reboot ensures that any pending installs or updates don’t hinder the Visual Studio install.

  4. Free up space. Remove unneeded files and applications from your %SystemDrive% by, for example, running the Disk Cleanup app.

For questions about running previous versions of Visual Studio side by side with Visual Studio 2019, see the Visual Studio 2019 Platform Targeting and Compatibility page.

Step 2 – Download Visual Studio

Next, download the Visual Studio bootstrapper file. To do so, choose the following button to go to the Visual Studio download page. Choose the Download button, then you can select the edition of Visual Studio that you want.

Step 3 – Install the Visual Studio installer

Run the bootstrapper file you downloaded to install the Visual Studio Installer. This new lightweight installer includes everything you need to both install and customize Visual Studio.

  1. From your Downloads folder, double-click the bootstrapper that matches or is similar to one of the following files:

    • vs_community.exe for Visual Studio Community
    • vs_professional.exe for Visual Studio Professional
    • vs_enterprise.exe for Visual Studio Enterprise

    If you receive a User Account Control notice, choose Yes to allow the bootstrapper to run.

  2. We ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy Statement. Choose Continue.

Step 4 – Choose workloads

After the installer is installed, you can use it to customize your installation by selecting the workloads, or feature sets, that you want. Here’s how.

  1. Find the workload you want in the Installing Visual Studio screen.

    For core C and C++ support, choose the “Desktop development with C++” workload. It comes with the default core editor, which includes basic code editing support for over 20 languages, the ability to open and edit code from any folder without requiring a project, and integrated source code control.

    Other workloads support more kinds of development. For example, choose the “Universal Windows Platform development” workload to create apps that use the Windows Runtime for the Microsoft Store. Choose “Game development with C++” to create games that use DirectX, Unreal, and Cocos2d. Choose “Linux development with C++” to target Linux platforms, including IoT development.

    The Installation details pane lists the included and optional components installed by each workload. You can select or deselect optional components in this list. For example, to support development by using the Visual Studio 2017 or 2015 compiler toolsets, choose the MSVC v141 or MSVC v140 optional components. You can add support for MFC, the experimental Modules language extension, IncrediBuild, and more.

  2. After you choose the workload(s) and optional components you want, choose Install.

    Next, status screens appear that show the progress of your Visual Studio installation.

Tip

At any time after installation, you can install workloads or components that you didn’t install initially. If you have Visual Studio open, go to Tools > Get Tools and Features… which opens the Visual Studio Installer. Or, open Visual Studio Installer from the Start menu. From there, you can choose the workloads or components that you wish to install. Then, choose Modify.

Step 5 – Choose individual components (Optional)

If you don’t want to use the Workloads feature to customize your Visual Studio installation, or you want to add more components than a workload installs, you can do so by installing or adding individual components from the Individual components tab. Choose what you want, and then follow the prompts.

Step 6 – Install language packs (Optional)

By default, the installer program tries to match the language of the operating system when it runs for the first time. To install Visual Studio in a language of your choosing, choose the Language packs tab from the Visual Studio Installer, and then follow the prompts.

Change the installer language from the command line

Another way that you can change the default language is by running the installer from the command line. For example, you can force the installer to run in English by using the following command:

vs_installer.exe --locale en-US

. The installer will remember this setting when it’s run the next time. The installer supports the following language tokens: zh-cn, zh-tw, cs-cz, en-us, es-es, fr-fr, de-de, it-it, ja-jp, ko-kr, pl-pl, pt-br, ru-ru, and tr-tr.

Step 7 – Change the installation location (Optional)

You can reduce the installation footprint of Visual Studio on your system drive. You can choose to move the download cache, shared components, SDKs, and tools to different drives, and keep Visual Studio on the drive that runs it the fastest.

Important

You can select a different drive only when you first install Visual Studio. If you’ve already installed it and want to change drives, you must uninstall Visual Studio and then reinstall it.

Step 8 – Start developing

  1. After Visual Studio installation is complete, choose the Launch button to get started developing with Visual Studio.

  2. On the start window, choose Create a new project.

  3. In the search box, enter the type of app you want to create to see a list of available templates. The list of templates depends on the workload(s) that you chose during installation. To see different templates, choose different workloads.

    You can also filter your search for a specific programming language by using the Language drop-down list. You can filter by using the Platform list and the Project type list, too.

  4. Visual Studio opens your new project, and you’re ready to code!

Create a Windows desktop project

Follow these steps to create your first Windows desktop project. Per the note at the beginning of this walkthrough, the completed code is available in the Build the code section at the end of the walkthrough. Go ahead and follow the steps to create the project, but hold off pasting the following sections of code until the end, when the complete application code is presented. Some details are omitted in the code snippets to focus on the most important parts. You can copy the complete code and paste it into your project at the end.

To simplify the explanation. To see the documentation for your preferred version of Visual Studio, use the Version selector control. It’s located at the top of the table of contents on this page.

To create a Windows desktop project in Visual Studio

  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. In the Application type dropdown, make sure you select Desktop application (.exe). Since we’re making a Windows application, choosing Console Application results in a project that won’t build given the code we’re going to use. Then, 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.

    The animation shows right-clicking on the project name in Solution Explorer, choosing Add in the menu that appears, and then choosing 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 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.

    The animation shows right-clicking on the project name in Solution Explorer, choosing Add in the menu that appeared, and then choosing 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 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.

    The animation shows right-clicking on the project name in Solution Explorer, choosing Add in the menu that appears, and then choosing 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.

How To Use Win32 API in Visual Studio C++ Project
How To Use Win32 API in Visual Studio C++ Project

Visual Studio 2015 Installation

To install Visual Studio 2015, go to the Microsoft Visual Studio Older downloads page. Expand the 2015 section, and choose the Download button. Run the downloaded setup program and choose Custom installation and then choose the C++ component. To add C and C++ support to an existing Visual Studio 2015 installation, click on the Windows Start button and type Add Remove Programs. Open the program from the results list and then find your Visual Studio 2015 installation in the list of installed programs. Double-click it, then choose Modify and select the Visual C++ components to install.

In general, we highly recommend that you use the latest version of Visual Studio even if you need to compile your code using the Visual Studio 2015 compiler. For more information, see Use native multi-targeting in Visual Studio to build old projects.

When Visual Studio is running, you’re ready to continue to the next step.

Phản hồi

Gửi và xem ý kiến phản hồi dành cho

I used Vs2019, but cocos2d-x doesn’t support for it when build *.exe, So I removed it first.

I install Vs2017 [build tool 141] and run in VS oke,

I go CMD to build DEBUG mode :
cocos compile -p win32 // everything oke

But with:
cocos deploy -p win32 -m release
I got :
“1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): error MSB8020: The build tools for v142 (Platform Toolset = ‘v142’) cannot be found. To build using the v142 build tools, please install v142 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting “Retarget solution”.”

It’s weird error, because BuildTool v142 cannot be installed on Vs2017. It’s oke on Vs2019 (2019 cannot build file *.exe)

Hi R101:
your ‘cmake … -G”Visual Studio 16 2019″ -DCMAKE_BUILD_TYPE=Release’,
Make me error when clicking Build In VS:
lack of ’ lib\Release\cocos2d.lib ’
But: cmake … -G”Visual Studio 16 2019″ -A Win32 -Tv142 // enough lib to build
I built a release mode for game with file *.exe has game_icon
Thank you!

Install C and C++ support in Visual Studio

If you haven’t downloaded and installed Visual Studio and the Microsoft C/C++ tools yet, here’s how to get started.

C++ : How can I get Visual Studio 2017 to sign a Win32 application automatically?
C++ : How can I get Visual Studio 2017 to sign a Win32 application automatically?

Wondering which tool is best for you? We can help

Visual Studio Code for Mac

Highlights

  • Free code editor
  • Built on open source and runs everywhere
  • Hundreds of programming languages supported

  • Add on the C# DevKit for Visual Studio Code

Visual Studio Code for Windows

Lightweight yet powerful source code editor with tons of
extensions for many languages and runtimes.Download Visual Studio Code

Highlights

  • Free code editor
  • Built on open source and runs everywhere
  • Hundreds of programming languages supported

Visual Studio Code for Mac

Highlights

  • Free code editor
  • Built on open source and runs everywhere
  • Hundreds of programming languages supported

Visual Studio Code for Linux

Highlights

  • Free code editor
  • Built on open source. Runs everywhere
  • Hundreds of programming languages supported

Visual Studio for Windows

A complete array of development tools and features in one
place to elevate and enhance every stage of your
software development.How to install offline Compare editions

Highlights

  • Free for individual use
  • Code faster, test, debug, deploy any app from one place
  • Visual Studio built-in features empower full development cycle.

Visual Studio 2022 Installation

Welcome to Visual Studio 2022! In this version, it’s easy to choose and install just the features you need. And because of its reduced minimum footprint, it installs quickly and with less system impact.

Note

This topic applies to installation of Visual Studio on Windows. Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn’t support Microsoft C++, but does support .NET languages and cross-platform development. For installation instructions, see Install Visual Studio for Mac.

Want to know more about what else is new in this version? See the Visual Studio release notes.

Ready to install? We walk you through it, step-by-step.

Step 1 – Make sure your computer is ready for Visual Studio

Before you begin installing Visual Studio:

  1. Check the system requirements. These requirements help you know whether your computer supports Visual Studio 2022.

  2. Apply the latest Windows updates. These updates ensure that your computer has both the latest security updates and the required system components for Visual Studio.

  3. Reboot. The reboot ensures that any pending installs or updates don’t hinder the Visual Studio install.

  4. Free up space. Remove unneeded files and applications from your %SystemDrive% by, for example, running the Disk Cleanup app.

For questions about running previous versions of Visual Studio side by side with Visual Studio 2022, see the Visual Studio 2022 Platform Targeting and Compatibility page.

Step 2 – Download Visual Studio

Next, download the Visual Studio bootstrapper file. To do so, choose the following button to go to the Visual Studio download page. Select the edition of Visual Studio that you want and choose the Free trial or Free download button.

Step 3 – Install the Visual Studio installer

Run the bootstrapper file you downloaded to install the Visual Studio Installer. This new lightweight installer includes everything you need to both install and customize Visual Studio.

  1. From your Downloads folder, double-click the bootstrapper that matches or is similar to one of the following files:

    • vs_community.exe for Visual Studio Community
    • vs_professional.exe for Visual Studio Professional
    • vs_enterprise.exe for Visual Studio Enterprise

    If you receive a User Account Control notice, choose Yes to allow the bootstrapper to run.

  2. We ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy Statement. Choose Continue.

Step 4 – Choose workloads

After the installer is installed, you can use it to customize your installation by selecting the workloads, or feature sets, that you want. Here’s how.

  1. Find the workload you want in the Installing Visual Studio screen.

    For core C and C++ support, choose the “Desktop development with C++” workload. It comes with the default core editor, which includes basic code editing support for over 20 languages, the ability to open and edit code from any folder without requiring a project, and integrated source code control.

    Other workloads support more kinds of development. For example, choose the “Universal Windows Platform development” workload to create apps that use the Windows Runtime for the Microsoft Store. Choose “Game development with C++” to create games that use DirectX, Unreal, and Cocos2d. Choose “Linux development with C++” to target Linux platforms, including IoT development.

    The Installation details pane lists the included and optional components installed by each workload. You can select or deselect optional components in this list. For example, to support development by using the Visual Studio 2017 or 2015 compiler toolsets, choose the MSVC v141 or MSVC v140 optional components. You can add support for MFC, the experimental Modules language extension, IncrediBuild, and more.

  2. After you choose the workload(s) and optional components you want, choose Install.

    Next, status screens appear that show the progress of your Visual Studio installation.

Tip

At any time after installation, you can install workloads or components that you didn’t install initially. If you have Visual Studio open, go to Tools > Get Tools and Features… which opens the Visual Studio Installer. Or, open Visual Studio Installer from the Start menu. From there, you can choose the workloads or components that you wish to install. Then, choose Modify.

Step 5 – Choose individual components (Optional)

If you don’t want to use the Workloads feature to customize your Visual Studio installation, or you want to add more components than a workload installs, you can do so by installing or adding individual components from the Individual components tab. Choose what you want, and then follow the prompts.

Step 6 – Install language packs (Optional)

By default, the installer program tries to match the language of the operating system when it runs for the first time. To install Visual Studio in a language of your choosing, choose the Language packs tab from the Visual Studio Installer, and then follow the prompts.

Change the installer language from the command line

Another way that you can change the default language is by running the installer from the command line. For example, you can force the installer to run in English by using the following command:

vs_installer.exe --locale en-US

. The installer will remember this setting when it’s run the next time. The installer supports the following language tokens: zh-cn, zh-tw, cs-cz, en-us, es-es, fr-fr, de-de, it-it, ja-jp, ko-kr, pl-pl, pt-br, ru-ru, and tr-tr.

Step 7 – Change the installation location (Optional)

You can reduce the installation footprint of Visual Studio on your system drive. You can choose to move the download cache, shared components, SDKs, and tools to different drives, and keep Visual Studio on the drive that runs it the fastest.

Important

You can select a different drive only when you first install Visual Studio. If you’ve already installed it and want to change drives, you must uninstall Visual Studio and then reinstall it.

Step 8 – Start developing

  1. After Visual Studio installation is complete, choose the Launch button to get started developing with Visual Studio.

  2. On the start window, choose Create a new project.

  3. In the search box, enter the type of app you want to create to see a list of available templates. The list of templates depends on the workload(s) that you chose during installation. To see different templates, choose different workloads.

    You can also filter your search for a specific programming language by using the Language drop-down list. You can filter by using the Platform list and the Project type list, too.

  4. Visual Studio opens your new project, and you’re ready to code!

Bùng nổ cảm xúc với Liên khúc Xuân của dàn diễn viên VFC| Gặp gỡ diễn viên truyền hình 2024
Bùng nổ cảm xúc với Liên khúc Xuân của dàn diễn viên VFC| Gặp gỡ diễn viên truyền hình 2024

Still want an older version?

Select a product below and click on the download button to log in to your Visual Studio (MSDN) subscription or join the free Dev Essentials program, to gain access to the older versions.

Visual Studio 2019 and other Products

To download any product from the following list, click the download button and log in with your Visual Studio Subscription account when prompted. If you don’t have a Visual Studio Subscription, you can create one for free by clicking on “Create a new Microsoft account” on the login page.

Visual Studio Professional 2019; Visual Studio Enterprise 2019;

Visual Studio 2019 for Mac

Build Tools for Visual Studio 2019

Visual Studio Team Explorer 2019

Agents for Visual Studio 2019

IntelliTrace Standalone Collector for Visual Studio 2019

Performance Tools for Visual Studio 2019

Remote Tools for Visual Studio 2019

Microsoft Visual C++ Redistributable for Visual Studio 2019

Visual Studio 2017 and other Products

To download any product from the following list, click the download button and log in with your Visual Studio Subscription account when prompted. If you don’t have a Visual Studio Subscription, you can create one for free by clicking on “Create a new Microsoft account” on the login page.

Visual Studio Professional 2017; Visual Studio Enterprise 2017;

Visual Studio 2017 for Mac

Visual Studio Test Professional 2017

Build Tools for Visual Studio 2017

Visual Studio Team Explorer 2017

Agents for Visual Studio 2017

Feedback Client for Visual Studio 2017

IntelliTrace Standalone Collector for Visual Studio 2017

Performance Tools for Visual Studio 2017

Remote Tools for Visual Studio 2017

Visual Studio 2015 and other Products

To download any product from the following list, click the download button and log in with your Visual Studio Subscription account when prompted. If you don’t have a Visual Studio Subscription, you can create one for free by clicking on “Create a new Microsoft account” on the login page.

Visual Studio Professional 2015; Visual Studio Enterprise 2015;

Visual Studio Test Professional 2015

Visual C++ Build Tools for Visual Studio 2015; Microsoft Visual Build Tools for Visual Studio 2015

Visual Studio 2015 Language Pack

Visual Studio Test Professional 2015 Language Pack

Visual Studio Team Foundation Server 2015

Visual Studio Team Foundation Server Express 2015

Visual Studio Team Foundation Server Office Integration 2015

Visual Studio 2015 SDK

Agents for Visual Studio 2015

Modeling SDK for Visual Studio 2015

Remote Tools for Visual Studio 2015

Release Management for Visual Studio 2015

Visual Studio 2013 and Other Products

To download any product from the following list, click the download button and log in with your Visual Studio Subscription account when prompted. If you don’t have a Visual Studio Subscription, you can create one for free by clicking on “Create a new Microsoft account” on the login page.

Visual Studio Professional 2013; Visual Studio Premium 2013; Visual Studio Ultimate 2013

Visual Studio Test Professional 2013

Visual Studio 2013 Language Pack

Visual Studio Test Professional 2013 Language Pack

Visual Studio Team Foundation Server 2013

Visual Studio Team Foundation Server Express 2013

Team Explorer for Visual Studio 2013

Visual Studio 2013 SDK

Visual Studio 2013 Modeling SDK

Visual Studio 2013 Agents

Visual Studio Express 2013 for Web

Visual Studio Express 2013 for Windows

Visual Studio Express 2013 for Windows Desktop

Microsoft Visual C++ Redistributable for Visual Studio 2017

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

Right-click on the following link to copy or bookmark this download: Microsoft Visual C++ Redistributable for Visual Studio 2017

Microsoft Visual C++ 2015 Redistributable Update 3

Install run-time components of Visual C++ libraries that are required to run C++ applications. Microsoft Visual C++ 2015 Redistributable includes bug fixes to the runtime DLLs and also the latest versions for KB 2999226.

Right-click on the following link to copy or bookmark this download: Microsoft Visual C++ 2015 Redistributable Update 3

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

This walkthrough shows how to create a traditional Windows desktop application in Visual Studio. The application you 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 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 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.

Important

The Build the code section at the end of this document shows the complete code. This walkthrough covers the various pieces of code that go into a Windows app, but you won’t code as you go because some details are omitted in the code snippets to focus on the most important parts. You can copy the complete code and paste it into your project at the end.

Skip to main content
Skip to main content
Microsoft
Visual Studio
Visual Studio
Visual Studio
Home
Learn About Feedback
Guidelines
Problems
Suggestions
Code of Conduct
Downloads
Support
Visual Studio IDE
Visual Studio Code
Azure DevOps
Team Foundation Server
Accounts and Subscriptions
Subscriber Access
More
All Microsoft
Global
Microsoft Security
Azure
Dynamics 365
Microsoft 365
Microsoft Teams
Windows 365
Tech & innovation
Tech & innovation
Microsoft Cloud
AI
Azure Space
Mixed reality
Microsoft HoloLens
Microsoft Viva
Quantum computing
Sustainability
Industries
Industries
Education
Automotive
Financial services
Government
Healthcare
Manufacturing
Retail
All industries
Partners
Partners
Find a partner
Become a partner
Partner Network
Find an advertising partner
Become an advertising partner
Azure Marketplace
AppSource
Resources
Resources
Blog
Microsoft Advertising
Developer Center
Documentation
Events
Licensing
Microsoft Learn
Microsoft Research
View Sitemap
Sign in
You need to enable JavaScript to run this app.
Sorry this browser is no longer supported
Please use any other modern browser like ‘Microsoft Edge’.

I installed the

VS2017 community

and I am lost: the Win32 Console Application in missing.

I don’t even have template when I go to

New Project

and also I cannot create C++ Empty Project in

VS2017

.

How I can solve it?

I installed the

VS2017 community

and I am lost: the Win32 Console Application in missing.

I don’t even have template when I go to

New Project

and also I cannot create C++ Empty Project in

VS2017

.

How I can solve it?

Install all the optional tools for c++ development

then follow these steps ( Microsoft has updated its visual studio and there are some minor changes)

The new updated changed some things. Win32 Console Application is gone in the new update. Go to File -> New Project -> Visual C++ -> Windows Desktop -> Windows Desktop Wizard -> Application type: Console Application (.exe), Additional Options: Empty Project

Then have fun!

You just need to install “Visual Studio C++ core features”. Don’t install everything about C++. It consumes too much storage and possibly slow down your IDE.

Steps:

That’s all.

If you are not interested in Game or Mobile C++ development you can remove your selections in “Workloads” tab to get free space in your hard drive 🙂

Have you tried the latest Visual Studio?

Try the latest 64-bit Visual Studio 2022 to create your ideal IDE, build smarter apps, integrate with the cloud, optimize for performance, and stay ahead of the curve

Check out what’s new in Visual Studio 2022

you will never ask about pointers again after watching this video
you will never ask about pointers again after watching this video

Visual Studio 2017 Installation

In Visual Studio 2017, it’s easy to choose and install just the features you need. And because of its reduced minimum footprint, it installs quickly and with less system impact.

Prerequisites

  • A broadband internet connection. The Visual Studio installer can download several gigabytes of data.

  • A computer that runs Microsoft Windows 7 or later versions. We recommend the latest version of Windows for the best development experience. Make sure that the latest updates are applied to your system before you install Visual Studio.

  • Enough free disk space. Visual Studio requires at least 7 GB of disk space, and can take 50 GB or more if many common options are installed. We recommend you install it on your C: drive.

For details on the disk space and operating system requirements, see Visual Studio Product Family System Requirements. The installer reports how much disk space is required for the options you select.

Download and install

  1. To download the latest Visual Studio 2017 installer for Windows, go to the Microsoft Visual Studio Older downloads page. Expand the 2017 section, and choose the Download button.

    Tip

    The Community edition is for individual developers, classroom learning, academic research, and open source development. For other uses, install Visual Studio 2017 Professional or Visual Studio 2017 Enterprise.

  2. Find the installer file you downloaded and run it. The downloaded file might be displayed in your browser, or you might find it in your Downloads folder. The installer needs Administrator privileges to run. You might see a User Account Control dialog asking you to give permission to let the installer make changes to your system; choose Yes. If you’re having trouble, find the downloaded file in File Explorer, right-click on the installer icon, and choose Run as Administrator from the context menu.

  3. The installer presents you with a list of workloads, which are groups of related options for specific development areas. Support for C++ is now part of optional workloads that aren’t installed by default.

    For C and C++, select the Desktop development with C++ workload and then choose Install.

  4. When the installation completes, choose the Launch button to start Visual Studio.

    The first time you run Visual Studio, you’re asked to sign in with a Microsoft Account. If you don’t have one, you can create one for free. You must also choose a theme. Don’t worry, you can change it later if you want to.

    It might take Visual Studio several minutes to get ready for use the first time you run it. Here’s what it looks like in a quick time-lapse:

    Visual Studio starts faster when you run it again.

  5. When Visual Studio opens, check to see if the flag icon in the title bar is highlighted:

    If it’s highlighted, select it to open the Notifications window. If there are any updates available for Visual Studio, we recommend you install them now. Once the installation is complete, restart Visual Studio.

Keywords searched by users: win32 visual studio 2017

Visual Studio 2017 Lỗi Khi Tạo Project Không Có Tùy Chọn Win32 Console -  Randomq - Dạy Nhau Học
Visual Studio 2017 Lỗi Khi Tạo Project Không Có Tùy Chọn Win32 Console – Randomq – Dạy Nhau Học
Solved I Cannot Find Win32 Console Application In Visual Studio 2105 -  Youtube
Solved I Cannot Find Win32 Console Application In Visual Studio 2105 – Youtube
Visual Studio 2017 Lỗi Khi Tạo Project Không Có Tùy Chọn Win32 Console -  Randomq - Dạy Nhau Học
Visual Studio 2017 Lỗi Khi Tạo Project Không Có Tùy Chọn Win32 Console – Randomq – Dạy Nhau Học
Walkthrough: Create And Use Your Own Dynamic Link Library (C++) | Microsoft  Learn
Walkthrough: Create And Use Your Own Dynamic Link Library (C++) | Microsoft Learn
Get Started With Webview2 In Win32 Apps - Microsoft Edge Developer  Documentation | Microsoft Learn
Get Started With Webview2 In Win32 Apps – Microsoft Edge Developer Documentation | Microsoft Learn
Create Win32 Project In Visual Studios 2019 - Youtube
Create Win32 Project In Visual Studios 2019 – Youtube
Walkthrough: Create A Traditional Windows Desktop Application (C++) |  Microsoft Learn
Walkthrough: Create A Traditional Windows Desktop Application (C++) | Microsoft Learn
Hướng Dẫn Build Lib Opencv 4.8.0 Trên Windows 10 - Thị Giác Máy Tính
Hướng Dẫn Build Lib Opencv 4.8.0 Trên Windows 10 – Thị Giác Máy Tính
Windows Desktop Wizard | Microsoft Learn
Windows Desktop Wizard | Microsoft Learn
Win32 Sample App With Visual Composition - Microsoft Edge Developer  Documentation | Microsoft Learn
Win32 Sample App With Visual Composition – Microsoft Edge Developer Documentation | Microsoft Learn
Build A C# .Net App With Winui 3 And Win32 Interop - Windows Apps |  Microsoft Learn
Build A C# .Net App With Winui 3 And Win32 Interop – Windows Apps | Microsoft Learn

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *