8.3.4 Moving and Sizing a Control

To move or size a control, use the MoveWindow function. This function moves the control to the specified coordinates in the parent window's client area and sets the control to the given width and height. The following example shows how to use MoveWindow to move and size a control:

MoveWindow(hButtonWnd, 10, 10, 30, 12, TRUE);

This example moves a control to the coordinates (10,10) in the client area and sets the width and height to 30 and 12 pixels, respectively. The value TRUE specifies that the control should be repainted after being moved.

Windows automatically moves a control when moving the parent window. A control's position is always relative to the upper-left corner of the parent's client area, so when the parent window moves, the control remains fixed in the client area but moves relative to the screen. Although Windows does not size a control when it sizes the parent window, it sends a WM_SIZE message to the parent window to indicate the new size of the parent window. You can use this message to specify a new size for the control.