PDA

View Full Version : 2 screen questions



Aliii
06-13-2012, 01:10 AM
When I set up a fullscreen window, how do I know whats the aspect ration of the monitor, and what are the resolutions that it supports?

2nd:
In windowed mode I need to know what is the size of the window headline in pixels ...I have problems when counting the cursor distance from the centre of the screen.
Thanks!
(Im using Win XP btw)

mhagain
06-13-2012, 10:21 AM
For Windows you need to use some Windows API calls for these. Look up EnumDisplaySettings for supported resolutions; for the current screen size you have a choice: SystemParametersInfo (SPI_GETWORKAREA, ... is useful for windowed modes as it excludes the taskbar from it's returned value, so you get the actual client area of the screen; for fullscreen (or if you need the full screen resolution including the taskbar) GetDC (NULL), then some GetDeviceCaps calls is one option (not forgetting a ReleaseDC when done).

By "window headline" I assume that you mean the title bar. It's generally a bad idea to hard-code this value as it can change between different versions of Windows or based on user preferences (and overriding user preferences is an even worse idea), so you use GetWindowRect to get the full rectangle coords for the window including title bar and borders, then GetClientRect for the coords excluding them, and from there it's just some simple subtraction to get the sizes. You probably also want to respond to WM_SIZE messages and recalculate these if needed, and likely also WM_MOVE if you're using ClipCursor to constrain the mouse within a specified rectangle.

Look up all of these on your local friendly MSDN: http://msdn.microsoft.com/en-ie/ms348103.aspx

Aliii
06-13-2012, 01:21 PM
For Windows you need to use some Windows API calls for these. Look up EnumDisplaySettings for supported resolutions; for the current screen size you have a choice: SystemParametersInfo (SPI_GETWORKAREA, ... is useful for windowed modes as it excludes the taskbar from it's returned value, so you get the actual client area of the screen; for fullscreen (or if you need the full screen resolution including the taskbar) GetDC (NULL), then some GetDeviceCaps calls is one option (not forgetting a ReleaseDC when done).

By "window headline" I assume that you mean the title bar. It's generally a bad idea to hard-code this value as it can change between different versions of Windows or based on user preferences (and overriding user preferences is an even worse idea), so you use GetWindowRect to get the full rectangle coords for the window including title bar and borders, then GetClientRect for the coords excluding them, and from there it's just some simple subtraction to get the sizes. You probably also want to respond to WM_SIZE messages and recalculate these if needed, and likely also WM_MOVE if you're using ClipCursor to constrain the mouse within a specified rectangle.

Look up all of these on your local friendly MSDN: http://msdn.microsoft.com/en-ie/ms348103.aspx

Thanks! EnumDisplaySettings works perfectly.

but getClientRect doesnt.
Im trying
LPRECT c_rect;
GetClientRect( hWnd, c_rect);
and it crashes. hWnd is "set up" already.

aqnuep
06-13-2012, 01:58 PM
but getClientRect doesnt.
Im trying
LPRECT c_rect;
GetClientRect( hWnd, c_rect);
and it crashes. hWnd is "set up" already.
Obviously, because you pass an invalid pointer to it. The LPRECT type is a pointer type that points to a RECT structure. You have to allocate the structure and pass a pointer to it to GetClientRect.
Here's what you have to do:

RECT c_rect;
GetClientRect( hWnd, &c_rect );

Aliii
06-13-2012, 02:19 PM
Thanks! works