Graphics Device Interface (GDI) API Reference

Overview

The Graphics Device Interface (GDI) provides a set of functions for drawing graphics and formatted text on Windows-based displays and printers. GDI enables device‑independent representation of graphical objects, allowing applications to create consistent output across a wide variety of hardware.

Commonly Used Functions

FunctionPurpose
CreateCompatibleDCCreate a memory device context compatible with a specified device.
BitBltPerform a bit block transfer of color data between device contexts.
SelectObjectSelect a GDI object (pen, brush, bitmap, etc.) into a device context.
SetPixelVSet the color of a single pixel.
GetDeviceCapsRetrieve device-specific information.

Sample Code

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
    HDC hdc = GetDC(NULL);
    HDC memDC = CreateCompatibleDC(hdc);
    HBITMAP bmp = CreateCompatibleBitmap(hdc, 200, 200);
    SelectObject(memDC, bmp);

    // Fill background
    HBRUSH brush = CreateSolidBrush(RGB(255,255,255));
    FillRect(memDC, &(RECT){0,0,200,200}, brush);
    DeleteObject(brush);

    // Draw a red ellipse
    HPEN pen = CreatePen(PS_SOLID, 2, RGB(255,0,0));
    SelectObject(memDC, pen);
    Ellipse(memDC, 20,20,180,180);
    DeleteObject(pen);

    // Blit to screen
    BitBlt(hdc, 100, 100, 200, 200, memDC, 0,0, SRCCOPY);
    ReleaseDC(NULL, hdc);
    DeleteDC(memDC);
    DeleteObject(bmp);
    return 0;
}

For full documentation, see the individual pages linked in the sidebar.