Windows Graphics API Reference

Welcome to the comprehensive reference for Windows graphics APIs. This section covers essential functions and structures for rendering, image manipulation, and device interaction.

You are viewing documentation for the Graphics category.

GDI Functions

The Graphics Device Interface (GDI) provides a set of functions for drawing 2D graphics, text, and images on Windows.

CreateSolidBrush

Creates a logical brush with the specified solid color.

HBRUSH CreateSolidBrush( COLORREF color );

Parameters:

  • color: The red, green, blue (RGB) color value.

Return Value:

  • If the function succeeds, the return value is a handle to the new logical brush.
  • If the function fails, the return value is NULL.

Note:

You must use the DeleteObject function to delete the brush when it is no longer needed.

Rectangle

Draws a rectangle using the current pen and fills it with the current brush.

BOOL Rectangle( HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect );

Parameters:

  • hdc: Handle to a device context.
  • nLeftRect: x-coordinate of the rectangle's upper-left corner.
  • nTopRect: y-coordinate of the rectangle's upper-left corner.
  • nRightRect: x-coordinate of the rectangle's lower-right corner.
  • nBottomRect: y-coordinate of the rectangle's lower-right corner.

Return Value:

  • If the function succeeds, the return value is nonzero.
  • If the function fails, the return value is zero.

TextOut

Writes a string of characters at the specified coordinates.

BOOL TextOut( HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString );

Parameters:

  • hdc: Handle to the device context.
  • nXStart: x-coordinate for the beginning of the string.
  • nYStart: y-coordinate for the beginning of the string.
  • lpString: Pointer to the string to be written.
  • cchString: Number of characters to write.

Return Value:

  • If the function succeeds, the return value is nonzero.
  • If the function fails, the return value is zero.

Direct3D Core

Direct3D is a low-level API for rendering 3D graphics. It's part of DirectX.

D3D11CreateDevice

Creates a device and a corresponding device context for Direct3D 11.

HRESULT D3D11CreateDevice( IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext );

Parameters:

  • pAdapter: Pointer to the video adapter.
  • DriverType: The type of driver.
  • Software: Handle to the DLL that implements a software rasterizer.
  • Flags: Runtime layers to enable.
  • pFeatureLevels: An array of feature levels.
  • FeatureLevels: The number of feature levels.
  • SDKVersion: The SDK version.
  • ppDevice: Address of a pointer to the created device.
  • pFeatureLevel: Address of a variable that receives the chosen feature level.
  • ppImmediateContext: Address of a pointer to the created device context.

Return Value:

  • S_OK if the method succeeds, or one of the Direct3D 11 Creation Errors.

DXGI (DirectX Graphics Infrastructure)

DXGI is a low-level component that provides services for graphics adapters and display output.

CreateDXGIFactory1

Creates a DXGI factory, which you can use to enumerate adapters.

HRESULT CreateDXGIFactory1( REFIID riid, void** ppvFactory );

Parameters:

  • riid: A reference to the globally unique identifier (GUID) of the interface to be created.
  • ppvFactory: The address of a pointer variable that receives the interface pointer.

Return Value:

  • S_OK if the function succeeds, E_INVALIDARG if riid or ppvFactory are invalid, DXGI_ERROR_UNSUPPORTED if the GUID is not supported.