开发者

Anchor buttons in a dialog when using SW_MAXIMIZE

This should be a simple one:

I have a CDialog with 2 buttons.开发者_JAVA技巧 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.


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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜