MSDN Community

Getting Started with Windows Desktop Development

Welcome to the Windows Desktop community! This guide will help you kick off your first native desktop application using the Win32 API, C++/WinRT, or .NET WinForms/WPF.

Prerequisites

  • Microsoft Visual Studio 2022 (Community or higher)
  • Windows 10 SDK (10.0.19041.0 or newer)
  • Basic C++ or C# knowledge

Step‑by‑Step: Create a Simple Win32 App

  1. Open Visual Studio → Create a new project
  2. Select Windows Desktop Application (C++) and click Next
  3. Give it a name, choose a location, and click Create
  4. Replace the generated WinMain with the code below:
#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
    const wchar_t CLASS_NAME[] = L"SampleWindowClass";

    WNDCLASS wc = { };
    wc.lpfnWndProc   = WindowProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

    HWND hwnd = CreateWindowEx(
        0,
        CLASS_NAME,
        L"Hello, Windows Desktop!",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,
        nullptr,
        nullptr,
        hInstance,
        nullptr
    );

    if (hwnd == nullptr) return 0;

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    MSG msg = { };
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

Press F5 to build and run. You should see a window titled Hello, Windows Desktop!

Resources