c++ - 在调整对话框大小时重新定位对话框控件,以便它们在使用 mfc C++ 的操作系统之间保持一致

标签 c++ mfc dialog resize

当前,当对话框按如下方式调整大小时,我正在重新定位对话框控件:

// 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/

相关文章:

java - 无法显示安卓对话框

java - 保存截图 cocos2d-x android

c++ - G测试 : mocking non-virtual member function

C++ 静态成员函数中封闭类的类型

c++ - 工作线程中的同步 ioctl 与异步 ioctl

.net - 将大型 MFC 应用程序转换为 .net

JavaFX - 带有 2 个输入字段的对话框?

c++ - 创建一个连续的动态矩阵

c++ - 在同一解决方案中的项目之间传递 CString

javascript - ImageJ Javascript 脚本中的文件打开对话框