Graphics::FromHDC(HDC) method (gdiplusgraphics.h)

The Graphics::FromHDC method creates a Graphics object that is associated with a specified device context.

Syntax

Graphics * FromHDC(
  [in] HDC hdc
);

Parameters

[in] hdc

Type: HDC

Handle to the device context that will be associated with the new Graphics object.

Return value

Type: Graphics*

This method returns a pointer to the new Graphics object.

Remarks

When you use this method to create a Graphics object, make sure that the Graphics object is deleted before the device context is released.

Examples

The following example calls Graphics::FromHDC to create a Graphics object and then uses that Graphics object to draw a rectangle.

VOID Example_FromHDC(HDC hdc)
{
   Graphics* pGraphics = Graphics::FromHDC(hdc);
   Pen pen(Color(255, 255, 0, 0));
   pGraphics->DrawRectangle(&pen, 10, 10, 200, 100);
   delete pGraphics;
}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusgraphics.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Changes in the Programming Model

FromHDC Methods

Graphics

Graphics Constructors

Graphics::FromHWND

Graphics::FromImage

Graphics::GetHDC