当前,当对话框按如下方式调整大小时,我正在重新定位对话框控件:
// Get the list control rect.
CRect listRect;
list->GetWindowRect(&listRect);
ScreenToClient(listRect);
// Get the dialog Rect.
CRect dialogRect;
GetWindowRect(&dialogRect);
ScreenToClient(dialogRect);
list->MoveWindow(listRect.left, listRect.top,
dialogRect.right - (2 * listRect.left), dialogRect.bottom - 100);
这在 Windows XP 中运行良好,但当我在 Windows Vista 中尝试时,定位不正确。我认为这必须归因于 Windows Vista 对话框中更大的对话框边框和标题,以及 GetWindowRect
在文档中具有以下条目的事实:
The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.
所以我的问题是,在调整对话框大小时如何重新定位对话框控件,以便它们在操作系统之间保持一致?谢谢
最佳答案
你应该使用 GetClientRect而不是 GetWindowRect 后跟 ScreenToClient——前者返回窗口客户端部分的范围(即无边框),而后者检索整个窗口的范围,包括非客户端部分(尽管在客户端坐标中)。
// Get the list control rect.
CRect listRect;
list->GetWindowRect(&listRect);
dlg->ScreenToClient(&listRect);
// Get the dialog Rect.
CRect dialogRect;
dlg->GetClientRect(&dialogRect);
list->MoveWindow(listRect.left, listRect.top, dialogRect.right - (2 * listRect.left), dialogRect.bottom - 100);
关于c++ - 在调整对话框大小时重新定位对话框控件,以便它们在使用 mfc C++ 的操作系统之间保持一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4460229/