Sign in to follow this  
Samurai Jack

AdjustWindowRect trouble

Recommended Posts

Greetings! I want to create an WS_OVERLAPPED window with exact the Client Size I say. For exmple 320x240. I am using WindowXP Luna themes and when I say AdjustWindowRect this function says that instead 240 i should take 244 for the Window Creation parameters. But the Caption bar in WindowXP is at least 16 or 20 pixels in height. So what is wrong?! What kind of parameters should i use that i get 320x240 client region? Thank you in advance!

Share this post


Link to post
Share on other sites
Im not entirely sure, but i have recently started using wxWidgets for Windows programming and this might have the ability to do what you want built in.

It's defo worth a look!
[smile]

ace

Share this post


Link to post
Share on other sites
Edit: Ignore this post. The 244 is indeed for the height.

Quote:
says that instead 240 i should take 244 for the Window Creation parameters. But the Caption bar in WindowXP is at least 16 or 20 pixels in height.


But isn't the 244 for the width, not the height?
The extra 4 pixels is probably for the left and right borders.

[Edited by - Dante Shamest on August 30, 2005 7:42:17 AM]

Share this post


Link to post
Share on other sites
From here.

Note: that you cannot specify the WS_OVERLAPPED style.

And from here.

WS_OVERLAPPED:
Creates an overlapped window. An overlapped window has a title bar and a border. Same as the WS_TILED style.

So, specify WS_TILED rather than WS_OVERLAPPED.

Share this post


Link to post
Share on other sites
Are you sure that's not just the lower bound of the window and the upper bound is negative? Because AdjustWindowRect will change the size so that your original rectangle request does not move.

Share this post


Link to post
Share on other sites
Quote:
So, specify WS_TILED rather than WS_OVERLAPPED.


I don't think it matters, since both constants are the same, and equal 0.

WS_OVERLAPPED itself has no effect, which is why you shouldn't specify it.

Try WS_OVERLAPPEDWINDOW instead.

Share this post


Link to post
Share on other sites
I solved this problem a different way although I think its stupid how AdjustWindowRect[Ex]() doesn't support that window style.


int WindowWidth;
int WindowHeight;

//Get the required window dimensions
WindowWidth = 320; //Required width
WindowWidth += (2 * GetSystemMetrics(SM_CXFIXEDFRAME)); //Add frame widths

WindowHeight = 240; //Required height
WindowHeight += GetSystemMetrics(SM_CYCAPTION); //Titlebar height
//WindowHeight += GetSystemMetrics(SM_CYMENU); //Uncomment for menu bar height
WindowHeight += (3 * GetSystemMetrics(SM_CYFIXEDFRAME)); //Frame heights



That should get you the correct window dimensions when using the WS_OVERLAPPED window style.

Share this post


Link to post
Share on other sites
Here, try this instead.


void SetClientSize(HWND handle, int x, int y)
{
RECT r;

GetClientRect(handle, &r);

x -= r.right;
y -= r.bottom;

GetWindowRect(handle, &r);

x += (r.right - r.left);
y += (r.bottom - r.top);

SetWindowPos(handle, NULL, 0, 0, x, y, SWP_NOMOVE);
}



EDIT: Slight modification made.

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