Sign in to follow this  

Cannot resize window with this code *SOLVED*

This topic is 3309 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

I enumerated some simple constants of expected resolutions to resize my window to. After looking around online, I tried writing this function. The window simply will not resize. I made the entire function tree for it return values to determine success, and apparently, they were successful! I cannot figure out what's wrong with it yet, so can someone help me determine where I flopped? Rather than post all 3 functions responsible, here's the one I believe is the problem code. I base this on the fact this is the only one that contains code I do not fully understand. This is in scope of my Engine, and any member access or anything arbitrary should have self explanatory names.
bool CIsoDev_Engine::D3D_TweakPresentationParams(int ScreenWidth, int ScreenHeight)
{
	RECT newRect = {0, 0, ScreenWidth, ScreenHeight};
	if (!AdjustWindowRectEx(&newRect, GetWindowStyle(WindowHandle), GetMenu(WindowHandle) != NULL, GetWindowExStyle(WindowHandle)))
	{
		char Err[256];
		sprintf(Err,"QE - (ERROR)(WIN) - Could not resize window. Attempted to make resolution: %ix%i", ScreenWidth, ScreenHeight);
		REPORT(Err); // OutputDebugString Macro
		return false;
	}
	D3DVIEWPORT9 viewport;

	viewport.X      = 0;
	viewport.Y      = 0;
	viewport.Width  = newRect.right;
	viewport.Height = newRect.bottom;
	viewport.MinZ   = 0.0f;
	viewport.MaxZ   = 1.0f;

	D3D_Param.BackBufferWidth = newRect.right;
	D3D_Param.BackBufferHeight = newRect.bottom;
	D3D_Param.BackBufferFormat = D3DFMT_UNKNOWN; // Use current color depth
	D3D_Device->SetViewport(&viewport);
	return true;
}



[Edited by - zyrolasting on November 19, 2008 12:46:09 AM]

Share this post


Link to post
Share on other sites
Noted and fixed, thanks!

I have another window related question before I close this up if that's alright...
I have a child window that displays a splash screen for a couple of seconds before the app begins. I want both this screen, and the main app to center themselves on my screen when they start.

How would I do this and have the app determine the resolution of my monitor at the time?

Share this post


Link to post
Share on other sites
to get the resolution

int ScreenWidth = GetDeviceCaps(HORZRES);
int ScreenHeight = GetDeviceCaps(VERTRES);

then you have to get the width and height of the window you want to center,

you could use GetWindowRect(), which takes a rect, and fills it with the size in screen coords

RECT WindowRect;
GetWindowRect(hHandleToSplashWindow,&WindowRect);

WindowWidth = WindowRect.right - WindowRect.left;
WindowHeight = WindowRect.bottom - WindowRect.top;


then the X of the window would be: (ScreenWidth - WindowWidth) /2

the Y would be: (ScreenHeight - WindowHeight)/2

usually i wouldn't give so much code, but since i was programming, i'm kinda in the mood

Share this post


Link to post
Share on other sites
You can get the desktop window with
GetDesktopWindow();
http://msdn.microsoft.com/en-us/library/ms633504.aspx

This returns the handle of the desktop then you can get the client rectangle of the desktop.
HWND desktop;
desktop = GetDesktopWindow();
Rect rc;
GetClientRect(desktop,&rc);

Then you have to center your windows to this client rectangle.

MoveWindow(yourWindow,(rc.right-yourWindowWidth)/2,( rc.bottom-yourWindowHeight) /2,yourWindowWidth,yourWindowHeight,TRUE);

Something like that should work.

Share this post


Link to post
Share on other sites

void CenterWindowInRect(HWND Window, long RectX, long RectY, long RectWidth, long RectHeight)
{
RECT WindowRect = { 0 };
GetWindowRect(Window, &WindowRect);
long WindowWidth = WindowRect.right - WindowRect.left;
long WindowHeight = WindowRect.bottom - WindowRect.top;

long WindowX = ((RectWidth / 2) - (WindowWidth / 2)) + RectX;
long WindowY = ((RectHeight / 2) - (WindowHeight / 2)) + RectY;
MoveWindow(Window, WindowX, WindowY, WindowWidth, WindowHeight, TRUE);
}

void CenterWindowInWindow(HWND Container, HWND Window)
{
RECT WindowRect = { 0 };
GetClientRect(Container, &WindowRect);
CenterWindowInRect(Window, WindowRect.left, WindowRect.top,
(WindowRect.right - WindowRect.left), (WindowRect.bottom - WindowRect.top));
}

void CenterWindowOnScreen(HWND Window)
{
CenterWindowInWindow(GetDesktopWindow(), Window);
}





This is the code from my old engine that did my window centering (so it's tested.)
HTH!

Share this post


Link to post
Share on other sites

This topic is 3309 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