windowed pixel resolution

Started by
8 comments, last by Kija 18 years, 8 months ago
Hi all, my application should handle both windowed mode and fullscreen. But I just want to support standard resolutions, like 800x600, 1024x768 and so on. I create my window with WS_OVERLAPPED | WS_CAPTION as flags, so it's a bare minimum, it's a caption bar at the top, there is no minimize / maximize / close buttons and it isn't possible to resize the window. Just the way I want it. Except that the rendering area of the window is smaller than 1024x768 (or whatever my resolution is). This is because the topic / caption bar at the top and the borders of the window "steals" some pixels of the 1024x768 window. So how would I create a window that has a 1024x768 rendering / direct3d area? I guess one solution would be to calculate how many pixels in x and y direction the borders steal and increase the windowed size by that but ... it would be a horrible way to solve it. This is quite important since I want to load textures onto a equally big area of the screen so I get pixel accuracy. Say that I have a 256x256 pixel texture and load it onto a 256x256 pixel big quad in screen space coordinates. Then the texture looks just the way as it should look. But if the rendering area is smaller than 1024x768 the 256x256 quad will be a bit smaller too and the texture needs to be resized to fit the new, smaller quad. And to those of you who think that a 256x256 pixel quad will still be 256x256 pixels even if the "rendering part" of the window is smaller: It won't be in my case since I will be using shaders for transformations and then I need to convert all screen space coordinates to clip space coordinates. And that would make for example a 256 pixel wide quad to be (256.0f / 1024.0f) clip space coordinates wide. Right? :) And if the _real_ x width of the screen is less than 1024.0f this quad would be smaller than 256 pixels. I'm new to Direct3D and very new to shaders so please correct me on every point where I'm wrong :P
Advertisement
AdjustWindowRect.

That should do exactly what I want, but it doesn't? I may be wrong here but I tell it to do a 1024x768 window and I get 1021x746? Without it I get 1018x743, so the AdjustRect changes it 3x3 pixels.

Here's the code:
	LPRECT rect = new RECT;	rect->left = rect->top = 40;	rect->right = 1024;	rect->bottom = 768;	int flags = (WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);	AdjustWindowRect(rect, flags, FALSE);	hWnd = CreateWindow(APP_TITLE, APP_TITLE, flags, rect->left, rect->top, rect->right, rect->bottom, GetDesktopWindow(), NULL, windowClass.hInstance, NULL);	GetClientRect(hWnd, rect);	char s[1000];	sprintf(s, "width: %i && height: %i", rect->right, rect->bottom);	logger.Log(s);


As you see, I call GetClientRect right after to check it. What am I missing?
Your initial Rect that you pass to AdjustRect has a top and left of 40, instead of 0. Is there some reason behind that, as I'd expect you to use 0.
left = top = 0 does not alter the result. Still the same. I just used 40 because of some reason the top title / caption field was above the screen when I used 0. So the direct3d rendering area started at 0,0. Instead of the top left corner of the title / caption field.
Quote:Original post by Kija
left = top = 0 does not alter the result. Still the same. I just used 40 because of some reason the top title / caption field was above the screen when I used 0. So the direct3d rendering area started at 0,0. Instead of the top left corner of the title / caption field.


That would happen because it is making the client part of the window the same size as the screen, which means the caption would go offscreen.
RECT::right and RECT::bottom are not the width and height. They are the right and bottom. I can't see how the result's the same when using 0 for top and left (in which case right and bottom will be the width and height).

Sure you tried this?
RECT rect;rect.left = 0;rect.top = 0;rect.bottom = 768;rect.right = 1024;DWORD flags = (WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);AdjustWindowRect(&rect, flags, FALSE);


In your first post you say you're using WS_OVERLAPPED and WS_CAPTION for your flags, but when you call AdjustRect you don't specify them?

int flags = (WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);

You forgot to say WS_OVERLAPPED, which would include WS_BORDER, which is probably where you're losing your three pixels (left, right and bottom borders).
Parameters

lpRect
[in, out] Pointer to a RECT structure that contains the coordinates of the top-left and bottom-right corners of the desired client area. When the function returns, the structure contains the coordinates of the top-left and bottom-right corners of the window to accommodate the desired client area.
dwstyle
[in] Specifies the window style of the window whose required size is to be calculated. Note that you cannot specify the WS_OVERLAPPED style.
bMenu
[in] Specifies whether the window has a menu.
GroZZleR, I removed WS_OVERLAPPED since the MSDN tells me so:
Quote:MSDN: AdjustWindowRect Function
dwstyle
[in] Specifies the window style of the window whose required size is to be calculated. Note that you cannot specify the WS_OVERLAPPED style.


Coder, yep, the result would be the same even if left and top were set to 0, however... Your post and especially njpauls post gave me the answer. AdjustWindowRect changes top and left too :)

I send this to it:
left: 0 top: 0 right: 1024 bottom: 768
and I get this:
left: -3 top: -22 right: 1027 bottom: 771

So if I use right - left as width and bottom - top as height, it all goes well. I should've realised this when the window went above the screen... Well well, as I said: I'm new to this :)

Thanks for the quick replies everyone

This topic is closed to new replies.

Advertisement