7 Interacting with the Window System, Operating System, and Input Devices

7.010 How do I obtain the window width and height or screen max width and height?

To obtain the window size on Win32, use the following code:

RECT rect;
HWND hwnd;
GetClientRect(hwnd, &rect);
/* rect.top and rect.left will always be 0, 0, respectively.
   The width and height are in rect.right and rect.bottom. */

For the screen size in pixels on Win32:

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

To obtaining the screen and window width and height using GLUT:

int screenWidth, screenHeight, windowWidth, windowHeight;

screenWidth = glutGet(GLUT_SCREEN_WIDTH);
screenHeight = glutGet(GLUT_SCREEN_HEIGHT);
windowWidth = glutGet(GLUT_WINDOW_WIDTH);
windowHeight = glutGet(GLUT_WINDOW_HEIGHT);