如何从MFC表单的底部到顶部移动控件?

时间:2009-04-28 04:52:51

标签: visual-c++ mfc

在VC ++ 6.0(MFC)中,控件如:Button,EditBox和Static Text如何从表单底部移动到表单顶部。

1 个答案:

答案 0 :(得分:4)

您可以使用CWnd :: MoveWindow()来移动控件。 CWnd :: GetDlgItem()将检索给定控件ID的CWnd。

从窗口的类中调用一些伪代码,这些窗口是控件的父级:

RECT windowRect;
GetClientRect( &windowRect );// Bounds of the current window

CWnd* controlWindow = GetDlgItem( controlId );
RECT controlRect;
controlWindow->GetWindowRect( &controlRect );//control rectangle
ScreenToClient( &controlRect );//control rectangle in the coordinate system of the parent

const int vertOffset = windowRect.top - controlRect.top;//how much to adjust
controlRect.top += vertOffset;
controlRect.bottom += vertOffset;
controlWindow->MoveWindow( &controlRect );