Sign in to follow this  
zyrolasting

[C++/Win] AdjustRect alternative

Recommended Posts

I want a 800x600 client, but end up with 797x578.
RECT r = {0,0,800,600};
AdjustWindowRect(&r,(WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME|WS_MAXIMIZEBOX)),false);

The documentation says I can not specify WS_OVERLAPPED, (set in WS_OVERLAPPEDWINDOW) which I can only guess is the source of my issue. What is an alternative method to calculating a window rect for my client before constructing a window? All I found on Google answered my question for when after the window is created and shown, which won't suffice. [Edited by - zyrolasting on December 24, 2009 6:14:19 PM]

Share this post


Link to post
Share on other sites
The adjusted window rect does not have left and top as zero. Use rect.right - rect.left to get the width. It gives you the dimensions of the entire window, if the client area is {0,0,800,600}, which starts at (-3, -22).

Share this post


Link to post
Share on other sites
Thanks! I assumed the context was similar to CreateWindow(), where only the top-left corner was in absolute coordinates.

Another issue, though. I get the correct client, but I want
my window to be 32 pixels off the top and left sides of the screen.
This does not accommodate for that.

// Generate window rect to accommodate
// desired client area.
RECT client = {32,32,32+m_ulWindowWidth,32+m_ulWindowHeight};
AdjustWindowRect(&client,ISDDXWINDOWSTYLE,false);

// Create the window to display the app on.
m_hWindow = CreateWindow(
m_szAppName,
m_szAppName,
ISDDXWINDOWSTYLE,
client.left,
client.top,
client.right - client.left,
client.bottom - client.top,
NULL,
NULL,
m_hInstance,
(LPVOID)this );

Share this post


Link to post
Share on other sites
I guess that would put your client rect at 32,32. To put the window at 32,32, simply specify .., 32, 32, rect.right-rect.left, rect.bottom-rect.top, .. to CreateWindow. You can use 0,0,800,600 for the client rect.

Share this post


Link to post
Share on other sites
Worked like a charm. Thanks so much for the speedy, informative replies!
Here is the final working snippet posted for reference.

// Generate window rect to accommodate
// desired client area.
RECT client = {0,0,m_ulWindowWidth,m_ulWindowHeight};
AdjustWindowRect(&client,ISDDXWINDOWSTYLE,false);

// Create the window to display the app on.
m_hWindow = CreateWindow(
m_szAppName,
m_szAppName,
ISDDXWINDOWSTYLE,
32,
32,
client.right - client.left,
client.bottom - client.top,
NULL,
NULL,
m_hInstance,
(LPVOID)this );

Share this post


Link to post
Share on other sites
another trick that might work for the fun of it (since you have overlapped window), is to use the WM_GETMINMAXINFO message: if the client dimensions are not the size that you want, u can expand the size of window dimensions by the short amount. this would guarantee ur client dimensions will always be 800x600 even if u try sizing the borders; of course that can be prevented using WM_NCHITTEST as well. might not work though since GetClientDimensions might not return the right values in WM_GETMINMAXINFO... just for fun.

Share this post


Link to post
Share on other sites

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