Draw Artifacts when resizing/repositioning windows.

I'm trying to figure out proper ways to resize and reposition windows and controls.

Problem is that i keep getting artifacts when they get redrawn.

http://img.idono.net/drawartifact.jpg


The main window holds 1 child window, wich in turn holds one window control(button).

I use EnumChildWindow to get all windows from the main window and send WM_SIZE message to those in the EnumChildProc.

Then i resize the windows that get the WM_SIZE message and enumerate the child windows, if any, and resize those.


Code for resizing and enumeration of child windows.
1
2
3
4
5
6
7
8
9
10
11
12
13

.....
RECT parentRect;

			HWND parent;
			parent = GetParent(m_hwnd);

			GetClientRect(parent, &parentRect);
			MoveWindow(m_hwnd, 0, 0, parentRect.right / 2, 200, TRUE);

			EnumChildWindows(m_hwnd, EnumChildProc, NULL);
....


EumProc for Window Controls.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
BOOL CALLBACK ChildWindow::EnumChildProc( HWND hwnd, LPARAM lParam ){
	RECT childRect;
	RECT parentRect;
	HWND parent;

	parent = GetParent(hwnd);
	GetWindowRect(parent, &parentRect);
	GetWindowRect(hwnd, &childRect);

	MoveWindow(hwnd, 
		(parentRect.right / 2)-((childRect.right - childRect.left) / 2), 
		(parentRect.bottom / 2)-((childRect.bottom-childRect.top) / 2),
		childRect.right - childRect.left,
		childRect.bottom - childRect.top,
		TRUE);

	return true;
}


I'm Guessing it has something to do with the render order. Been googling and searching MSDN for a solution or another way to resize/position. but i can't find any good material for it though.
You may need the class styles CS_HREDRAW and CS_VREDRAW applied when you call RegisterClass() or RegisterClassEx(). With these styles, the windows created will have their client area invalidated, forcing a WM_PAINT down the line.
Thx that helped.
Any reading material that can be recommended when it comes to positioning and resizing?
Not from the top of my head. You might want to learn appropriately the ways of Windows programming, though. In the books area, Programming Windows 5th edition by Charles Petzold.
It's a bit expensive. What about if i use this from wiki books?

http://en.wikibooks.org/wiki/Windows_Programming#Section_1:_Windows_Basics
Yes, the book is expensive. I have seen it reach the $300 mark @ Amazon when inventory dropped low. It is THE book you need, though, if you ever want to become a professional Windows programmer.

About the online book/tutorial you mention, I really don't know. Whatever works for you, I guess, but whatever the tutorial says, try to verify elsewhere. There are some ill-written tutorials out there (and some old ones) that are not ideal, to say the least. What I'm saying is: Read, but keep an open mind about what you read and other ways you find to do the same thing, because most likely one is better than the other, and you'll do yourself some good if you work out to find which one is.
Topic archived. No new replies allowed.