GDI Structures
The Graphics Device Interface (GDI) provides a set of data structures that applications use to represent graphical objects and pass information between GDI functions. Understanding these structures is crucial for effectively using GDI to draw and manage graphics within Windows applications.
Overview
GDI structures are used to define:
- Geometric shapes (e.g., points, rectangles, polygons).
- Colors and palettes.
- Pens, brushes, and fonts.
- Device contexts.
- Bitmap images.
- Metafile records.
Commonly Used Structures
POINT
Represents a point in two-dimensional space.
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT, *PPOINT, *LPPOINT;
RECT
Defines the coordinates of the upper-left and lower-right corners of a rectangle.
typedef struct tagRECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, *LPRECT;
COLORREF
Specifies an RGB color value.
typedef DWORD COLORREF;
You can create a COLORREF value using the RGB() macro:
COLORREF myColor = RGB(255, 0, 0); // Red
LOGPEN
Contains information about a logical pen, used for drawing lines and borders.
typedef struct tagLOGPEN {
UINT lopnStyle;
INT lopnWidth;
COLORREF lopnColor;
} LOGPEN;
LOGBRUSH
Contains information about a logical brush, used for filling areas and creating patterns.
typedef struct tagLOGBRUSH {
UINT lbStyle;
COLORREF lbColor;
LONG lbHatch;
} LOGBRUSH;
DEVMODE
Contains device-specific information about the device's current environment or about the initialization of a device.
typedef struct tagDEVMODE {
... // Many members defining printer or display settings
} DEVMODE;