tags:

views:

39

answers:

4

This might be rather trivial, however, after massive amounts of Googling, i haven't been able to find an answer.

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?

A: 

As a disclaimer, I know nothing about GDI or what you have to work with in your application. I'm just trying to be helpful if possible.

That said, I found a link which seems to suggest that it's appropriate to use GetClientRect to get the size of the drawing area:

RECT clientRect;

GetClientRect(hWnd,&clientRect);

http://www.toymaker.info/Games/html/gdi.html#winsize

KevenK
+3  A: 

I also know little about GDI, but it seems GetDeviceCaps might do the trick.

Cogwheel - Matthew Orlando
Specifically, `GetDeviceCaps(hdc, HORZRES)` and `GetDeviceCaps(hdc, VERTRES)` are most likely what's desired.
TheUndeadFish
+2  A: 

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
YeenFei
A: 

You could WindowFromDC(...) to get the DC's window if it's associated with a window. You could then use @KevinK's answer to get the client rect from this.

spong