使用 SW_MAXIMIZE 时在对话框中锚定按钮

发布于 2024-08-11 11:12:43 字数 179 浏览 1 评论 0原文

这应该是一个简单的:

我有一个带有 2 个按钮的 CDialog。 使用 m_pMainWnd->ShowWindow(SW_MAXIMIZE); 始终以全屏方式打开对话框(无标题栏 \ 状态等...)

我希望我的按钮能够捕捉到屏幕边缘。

没有调整大小或任何东西。

This should be a simple one:

I have a CDialog with 2 buttons.
The dialog is always opened in full screen (No title bar \ Status, etc...) using m_pMainWnd->ShowWindow(SW_MAXIMIZE);

I want my buttons to snap to the edge of the screen.

There are no resizing or anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以酷 2024-08-18 11:12:43

您知道对话框的宽度(GetClientRect)。您知道按钮的宽度。

假设您要捕捉到右边缘...

在您的 CDialog::OnSize 内:

 // Grab the CDialog's rect.
 CRect winRect;
 GetClientRect( &winRect );

 // Grab the button's rect.
 CRect buttonRect;
 button.GetClientRect( &buttonRect );

 // Now we need to set the top, left of the button to the right edge - the button width.
 // The y position will remain the same.
 button.SetWindowPos( NULL, winRect.right - buttonRect.Width(), buttonRect.top, 0, 0, SWP_NOZORDER | SWP_NOMOVE );

You know the width of the dialog (GetClientRect). You know the width of the buttons.

Assuming you are snapping to the right edge ...

Inside your CDialog::OnSize:

 // Grab the CDialog's rect.
 CRect winRect;
 GetClientRect( &winRect );

 // Grab the button's rect.
 CRect buttonRect;
 button.GetClientRect( &buttonRect );

 // Now we need to set the top, left of the button to the right edge - the button width.
 // The y position will remain the same.
 button.SetWindowPos( NULL, winRect.right - buttonRect.Width(), buttonRect.top, 0, 0, SWP_NOZORDER | SWP_NOMOVE );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文