AdjustWindowRect trouble

Started by
6 comments, last by Wavarian 18 years, 7 months ago
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!
Advertisement
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
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]
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.
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.
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.
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 dimensionsWindowWidth = 320; //Required widthWindowWidth += (2 * GetSystemMetrics(SM_CXFIXEDFRAME)); //Add frame widthsWindowHeight = 240; //Required heightWindowHeight += GetSystemMetrics(SM_CYCAPTION); //Titlebar height//WindowHeight += GetSystemMetrics(SM_CYMENU); //Uncomment for menu bar heightWindowHeight += (3 * GetSystemMetrics(SM_CYFIXEDFRAME)); //Frame heights


That should get you the correct window dimensions when using the WS_OVERLAPPED window style.
Progress is born from the opportunity to make mistakes.

My prize winning Connect 4 AI looks one move ahead, can you beat it? @nickstadb
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.

This topic is closed to new replies.

Advertisement