Sign in to follow this  

detecting window's resolution

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just wondering if there's a function that will return a window's current resolution. I'm looking to constrain my mouse cursor to these bounds without havin g to pass the data through 2 functions. I haven't found a function for this in the msdn.

Share this post


Link to post
Share on other sites
GetClientRect() will return the usable space on a window. Generally upon resizing, you GetClientRect() and use (right-left, bottom-top) as your new backbuffer size. GetWindowRect() will return the entire window size, including the space needed for menu bars, titlebars, borders, etc.

If you want to make a window a specific size, to simulate a fullscreen resolution, such as 800x600, you need AdjustWindowRect(). This can transform a client rect size into a window rect size. You then pass this size, with the same style flags to CreateWindow, or one of the resizing calls, and you'll have a window of the size you'd like.

If you want to know the resolution of a monitor, use D3D's GetAdapterDisplayMode, or GetAdapterMonitor and a Win32's GetMonitorInfo.

You can convert a mouse click position to between client and screen coords with ClientToScreen and ScreenToClient.

That should cover just about anything you'll need regarding window coordinates.

Share this post


Link to post
Share on other sites
Add a handler for the WM_SIZE message. It gets called when the window is created and any time it is resized. I use it to setup the DirectX stuff and reset the device in my MFC application:

void CMyClientWindow::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);

if( g_pDevice )
{
g_bPauseDrawing = TRUE;
HRESULT hr = 0;
g_D3DPresentParams.BackBufferWidth = cx;
g_D3DPresentParams.BackBufferHeight = cy;


The format is a tad different for a WIN32 app, but it does the same thing. You get the windows size in the cx and cy parameters.

Or you can use functions shown by Namethat... to get the actual top left and bottom right coordinates of the window.

Share this post


Link to post
Share on other sites

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this