I have created a Dialog Box in a c++ windows application (using ATL lib) and I have set on it three buttons. The button lie as usual at the bottom of the Dialog Box. I want by the resize of the Dialog Box, the button to retain their position at the bottom of it. In other words, they should keep a constant (low) distance from the bottom margin and the on side (right or left) of the Dialog Box. To bring this into effect, I try to move the buttons accordingly while the Dialog Box size is changed. I use the following code (as example only with the OK button), but the only result is the button to disappear during the resize. How should I modify the code in order for the button to retain its distance from the bottom and the right side of the Dialog Box?
LRESULT RenameFolderDlg::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
RECT r;
GetWindowRect(&r);
CWindow okB(GetDlgItem(IDOK));
RECT okR;
okB.GetWindowRect(&okR);
okB.MoveWindow( r.right - 80 , r.bottom - 40, okR.right - okR.left, okR.bottom - okR.top, 1);
return 0;
}
Instead of
you shall use
because the coordinates returned by
GetWindowRectare relative to the upper-left corner of the screen, whileMoveWindowcalled for a child control expects they are relative to the upper-left corner of the parent window’s client area.