How to find out DC's dimensions?

nhaa123 picture nhaa123 · Jul 1, 2010 · Viewed 14.6k times · Source

Let's say I have a handle to device context (naturally, in Windows environment):

HDC hdc;

How can I get the width and height of it?

Answer

YeenFei picture YeenFei · Jul 1, 2010

A device context (DC) is a structure that defines a set of graphic objects and their associated attributes, and the graphic modes that affect output.

By width and height I'm guessing you are referring to the bitmap painted ?
If so then i guess you can try the following :

BITMAP structBitmapHeader;
memset( &structBitmapHeader, 0, sizeof(BITMAP) );

HGDIOBJ hBitmap = GetCurrentObject(hDC, OBJ_BITMAP);
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);

//structBitmapHeader.bmWidth
//structBitmapHeader.bmHeight