如何将控件从 MFC 窗体的底部移动到顶部?

2 mfc visual-c++

在 VC++ 6.0 (MFC) 中,如何将控件(例如:Button、EditBox 和 Static Text)从窗体底部移动到窗体顶部。

sha*_*oth 5

您可以使用 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 );
Run Code Online (Sandbox Code Playgroud)