The function is used to gets the drawing device handle (HDC).

HDC GetImageHDC(IMAGE* pImg = NULL);



The drawing device pointer. If NULL, represents the default graphics window.

Return Value

Returns the drawing device handle (HDC).


Get stake in the HDC handle that can be used in the Windows GDI function.

Each IMAGE object has an HDC handle that allows you to perform GDI function operations on the IMAGE. In the same IMAGE device, do not mix easyX drawing functions with GDI drawing functions.

If you get the HDC handle of the default graphics window, the GDI function is not displayed directly to the screen after performing the GDI function, perform the FlushBatchDraw() display of the previous GDI action effect.


#include <graphics.h>
#include <conio.h>

int main()
	// Initialize the graphics window
	initgraph(640, 480);

	// Get the HDC handle to the default graphics window
	HDC hdc = GetImageHDC();

	// Perform ingress ingress functions of Windows GDI
	MoveToEx(hdc, 10, 10, NULL);
	LineTo(hdc, 100, 100);

	// Make previous Windows GDI drawings work

	// Create an img object with a size 200x200
	IMAGE img(200, 200);

	// Get the HDC handle for the img object
	hdc = GetImageHDC(&img);

	// Perform ingress ingress functions of Windows GDI
	Ellipse(hdc, 0, 50, 199, 150);

	// Show img objects above the graphics window
	putimage(100, 0, &img);

	// Press any key to exit