The Graphics Device Interface (GDI) is a core component of the Microsoft Windows operating system responsible for presenting graphical information to users. GDI provides a set of functions that applications can use to draw lines, curves, text, and graphics primitives on various output devices such as displays, printers, and plotters.
This section of the MSDN Community provides a comprehensive reference to the GDI API, covering its functions, structures, data types, and concepts. Whether you are developing graphical applications, drivers, or system-level components, understanding GDI is crucial for effective graphics programming on Windows.
Key GDI Concepts
- Device Context (DC): A structure that contains information about a particular device and the graphics attributes that apply to it. All GDI drawing operations are performed through a device context.
- GDI Objects: Resources that can be selected into a device context to control drawing attributes. These include pens, brushes, fonts, bitmaps, and regions.
- Coordinate Systems: Understanding world, page, and device coordinates is essential for accurate drawing.
- Bitmaps and Metafiles: Techniques for storing and manipulating graphical images.
Core GDI Function Categories
Drawing Functions
Functions for drawing basic shapes, lines, and text.
Rectangle,Ellipse,LineToTextOut,ExtTextOutMoveToEx,LineToPolygon,Polyline
GDI Object Management
Functions for creating, selecting, and deleting GDI objects.
CreatePen,CreateSolidBrush,CreateFontSelectObjectDeleteObjectGetCurrentObject
Device Context Management
Functions for obtaining, manipulating, and releasing device contexts.
GetDC,CreateDCGetDeviceCapsReleaseDCSaveDC,RestoreDC
Bitmap and Pixel Operations
Functions for working with bitmaps and manipulating individual pixels.
CreateBitmap,CreateCompatibleBitmapBitBlt,StretchBltSetPixel,GetPixel
Path and Region Management
Functions for defining and manipulating complex graphical areas.
BeginPath,EndPath,StrokePathCreatePolygonRgn,CreateRectRgnCombineRgn
Example Usage (Conceptual)
Here's a simplified conceptual example of how you might use GDI to draw a red line:
HDC hdc = GetDC(NULL); // Get a device context for the screen
if (hdc != NULL) {
// Create a red pen
HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
if (hPen != NULL) {
// Select the pen into the device context
HPEN hOldPen = (HPEN)SelectObject(hdc, hPen);
// Draw a line from (10, 10) to (100, 100)
MoveToEx(hdc, 10, 10, NULL);
LineTo(hdc, 100, 100);
// Restore the original pen
SelectObject(hdc, hOldPen);
// Clean up the pen
DeleteObject(hPen);
}
// Release the device context
ReleaseDC(NULL, hdc);
}