Extracting window size from HDC

Started by
2 comments, last by TempusElf 20 years, 8 months ago
I wrote a function that takes an HDC, creates a Render Context for OpenGL, handles all the perspective stuff, and then returns the render context. I had originally hard coded the height and width into the function, but now I''d like to have it work for any size, so I changed the function to look like this:

HGLRC getRC(HDC dcIn, const int width, const in height);
 
but it would be much nicer if I could extract the size of the client area from the DC... so I try this:

HBITMAP hbmIn;
BITMAP bmIn;
hbmIn = (HBITMAP)GetCurrentObject(dcIn, OBJ_BITMAP);
GetObject(hbmIn, sizeof(BITMAP), &bmIn);
 
no dice, the height and width in bmIn are zero so I try this:

SIZE area;
GetWindowExtEx(dcIn, &area);
 
again height and width are zero Is there something that I''m doing wrong? Is there a smart way to extract the height and width of a client area DC?
Advertisement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowFunctions/GetClientRect.asp

The GetClientRect function retrieves the coordinates of a window''s client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window''s client area, the coordinates of the upper-left corner are (0,0). SyntaxBOOL GetClientRect(          HWND hWnd,    LPRECT lpRect); 
Hi - try the getwindowinfo api takes an hwnd as input and fills a windowinfo structure with the information you need.
Hope this helps-

BM
RECT rc;
GetClientRect(WindowFromDC(hDC), &rc); ?

This topic is closed to new replies.

Advertisement