Window resize glich

Started by
14 comments, last by TomCatFort 15 years, 4 months ago
I have a very strange problem here. I have a window, and I want to resize it. But the other windows in the background (including the desktop) don't reapaint themselfs. I think they don't get WM_REPAINT for some reason. So I can see the old part of the window before the resizing. Here's me code:

void AppWindow::ResizeClientArea(int newWidth, int newHeight)
{
	//resize client area and put the window in the center of the work area
	RECT client, window, work;
	POINT difference;
	GetClientRect(windowHandle_, &client);
	GetWindowRect(windowHandle_, &window);
	difference.x = (window.right - window.left) - client.right;
	difference.y = (window.bottom - window.top) - client.bottom;
	SystemParametersInfo(SPI_GETWORKAREA, 0, &work, 0);
	if (windowedMode_)
		SetWindowPos(windowHandle_, 0, 
			(work.right  - newWidth  * (doubleSizeMode_ ? 2 : 1)) / 2,
			(work.bottom - newHeight * (doubleSizeMode_ ? 2 : 1)) / 2,
			newWidth  * (doubleSizeMode_ ? 2 : 1) + difference.x,
			newHeight * (doubleSizeMode_ ? 2 : 1) + difference.y,
			SWP_SHOWWINDOW);
	else
		SetWindowPos(windowHandle_, 0, 0, 0, 1024, 768, SWP_SHOWWINDOW);
}
PS: sorry for the grammar, but it's 1:00AM and I got very tired trying to solve this problem.
Advertisement
SetWindowPos "If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized." Check out SetWindowPlacement and if that doesn't work then DeferWindowPos and related functions.

By the way, the client area of an app window is the space beneath the menu and above the status bar and doesn't include the window frame or title bar. So if the method is supposed to change the size and position of the entire window, including the chrome, you might want to change it's name from ResizeClientArea to ResizeWindow or (since it's already a window) just Resize.

Here are a couple of additional links that might be helpful.

How To Translate Client Coordinates to Screen Coordinates
Window Coordinate System
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Yes. I want to resize the client area. The problem only apers when I'm change the windows style with SetWindowLong. I'm tried to wait for the WM_styleCHANGED message and do the resizing when I got that message but it don't help.
If you use SetWindowLong to modify a windows style you should use SetWindowPos with the following flags.

From MSDN in SetWindowPos:

If you have changed certain window data using SetWindowLong, you must call SetWindowPos to have the changes take effect. Use the following combination for uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Just to check; you mean WM_PAINT, not WM_REPAINT, right?
Evil Steave: Yes.

Endurion: If I do that my window wont resize.

Okey. I tell you once again, my problem is not how to resize the window. My problem is when the window is smaler after the resize, than the image of the window before the resize is still there becouse the backgroung wont repaint itself. Other words I still part of the window after the resize. And the only way to make it disapear is to force the other windows to repaint themselfs, eg.: switching beatween aplications ar refresh the desktop.
Have you tried calling InvalidateRect(windowHandle_, NULL, TRUE); after updating the window?
I don't want to repaint my window. I want to repaint the whole screen.

Given that you want to shrink the client area without shrinking the window, you'll need to invalidate the entire window so that the area that used to be beneath the client area is repainted. That's what EvilSteve is showing you how to do.

[Edited by - LessBread on December 18, 2008 1:06:51 PM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
I tried InvalidateRect(windowHandle_, NULL, TRUE); just before doing the resizing. But the result is the same.


Here how I doing this:
1. Call SetMode: this function set the windows style and set two internal variable (windowedMode, and doubleSize)
2. After I got WM_styleCHANGE I call ResizeClientArea:
first its aples the new style with SetWIndowPos(..., SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); Than it calculates the differences beatweeen the window rect and client rect and resize the window to have the desired client with and place it to the center. If doubleSize is true than the clientRect size will be larger (2X). If windowed is false it's means that the app is in full screan mode.
3. After the window have the desired tyle and size I tell direct3D to reset the device (not implemented yet);

DirectD renders into the client are but after the resizing the tilte and other non client parts of the window is visible too, so the problem have to be something else.

This topic is closed to new replies.

Advertisement