Getting Started with the Windows SDK

Welcome to the Windows Software Development Kit (SDK). This guide will help you get started with developing applications for Windows using the latest SDK.

Prerequisites

Before you begin, ensure you have the following installed:

Installing the Windows SDK

The Windows SDK is usually installed automatically when you select specific workloads in the Visual Studio Installer. If you need to install it separately or ensure you have the latest version:

  1. Open the Visual Studio Installer.
  2. Click Modify on your Visual Studio installation.
  3. Under the Workloads tab, ensure that workloads like "Desktop development with C++" or "UWP development" are selected.
  4. Navigate to the Individual components tab.
  5. Scroll down to the "SDKs, libraries, and frameworks" section.
  6. Select the desired Windows SDK version (e.g., "Windows 11 SDK" or "Windows 10 SDK (10.0.22621.0)").
  7. Click Modify to begin the installation.

Alternatively, you can download the SDK directly from the Microsoft Developer website.

Your First Windows Application

Let's create a simple "Hello, World!" application using the Windows SDK and Visual Studio.

Using Visual C++

  1. Open Visual Studio.
  2. Create a new project: File > New > Project...
  3. In the project template dialog, search for "Windows Desktop Application" (for C++).
  4. Select the "Windows Desktop Application" template and click Next.
  5. Name your project (e.g., "HelloWorldWin32") and choose a location. Click Create.
  6. Visual Studio will generate a basic project structure. Find the main source file (often named like `HelloWorldWin32.cpp`).
  7. Replace the existing code with the following simple example:
    #include <Windows.h>
    #include <windowsx.h>
    
    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
    
    // Global Variables
    HINSTANCE hInst; // current instance
    HWND      g_hWnd;  // window handle
    
    int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPWSTR    lpCmdLine,
                         _In_ int       nCmdShow)
    {
        UNREFERENCED_PARAMETER(hPrevInstance);
        UNREFERENCED_PARAMETER(lpCmdLine);
    
        // Register the window class.
        MyRegisterClass(hInstance);
    
        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow))
        {
            return FALSE;
        }
    
        MSG msg;
    
        // Main message loop.
        while (GetMessage(&msg, nullptr, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return (int) msg.wParam;
    }
    
    //
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class for the application.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
        WNDCLASSEXW 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(hInstance, IDI_APPLICATION);
        wcex.hCursor       = LoadCursor(nullptr, IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName  = nullptr;
        wcex.lpszClassName = L"HelloWorldWin32Class";
        wcex.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
    
        return RegisterClassExW(&wcex);
    }
    
    //
    //   FUNCTION: InitInstance(HINSTANCE, int)
    //
    //   PURPOSE: Saves instance handle and creates main window
    //
    //   COMMENTS:
    //
    //        In this function, we save the instance handle in a global variable and
    //        create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       hInst = hInstance; // Store instance handle in our global variable
    
       HWND hWnd = CreateWindowW(L"HelloWorldWin32Class", L"Hello World", WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
    
       if (!hWnd)
       {
          return FALSE;
       }
    
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
       return TRUE;
    }
    
    //
    //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
        case WM_PAINT:
            {
                PAINTSTRUCT ps;
                HDC hdc = BeginPaint(hWnd, &ps);
                // Add any drawing code here...
                TextOut(hdc, 50, 50, L"Hello, Windows SDK!", 18);
                EndPaint(hWnd, &ps);
            }
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
    
                    
  8. Build the project: Build > Build Solution.
  9. Run the application: Debug > Start Without Debugging.

Key Components of the Windows SDK

The Windows SDK provides a comprehensive set of tools, headers, libraries, and documentation to build Windows applications. Some key components include:

Explore the API Reference

Navigate the extensive API reference to find documentation on specific functions, structures, and interfaces. This is your go-to resource for understanding how to interact with the Windows operating system.

Browse the API Reference