Moving the Standard Buttons

We've already discussed moving of the standard buttons in the topic about resizing the property sheet. The standard buttons can be treated like any other window once you gets its window handle or a CWnd object to manipulate it. The code below shows how to move the standard buttons to the right and resize the property sheet appropriately.
	CRect rectWnd, rectBtn;
	GetDlgItem(IDOK)->GetWindowRect(rectBtn);
	GetWindowRect(rectWnd);
	int btnwidth = rectBtn. rectBtn.Width();
	int btnheight = rectBtn.Height();
	int offset = rectWnd.bottom - rectBtn.bottom;
	int btnleft = rectWnd.right-rectWnd.left;
	rectWnd.bottom = rectBtn.top;
	rectWnd.right += btnwidth + offset;
	MoveWindow(rectWnd);
	
	int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW };
	rectBtn.left = btnleft;
	rectBtn.right = btnleft + btnwidth;
	for( int i =0; i < sizeof(ids)/sizeof(ids[0]); i++)
	{
		rectBtn.top = offset + i * (offset+btnheight);
		rectBtn.bottom = rectBtn.top + btnheight;
		GetDlgItem(ids[i])->MoveWindow(rectBtn);
	}



Comments

  • Another way of moving the buttons

    Posted by Legacy on 12/24/2001 12:00am

    Originally posted by: Weiye

    Just thought of another way which is much more simpler in terms of the lines of code : 
    
    

    BOOL CMyPropertySheet::OnInitDialog()
    {
    // Call base class initialisation
    BOOL bResult = CPropertySheet::OnInitDialog();

    // WINDOWPLACEMENT structure
    WINDOWPLACEMENT wpWindowPlacement;

    // Get window placement of help button
    GetDlgItem(IDHELP)->GetWindowPlacement(&wpWindowPlacement);

    // Change button position
    wpWindowPlacement.rcNormalPosition.left -= 15;
    wpWindowPlacement.rcNormalPosition.right -= 15;

    // Set new button position
    GetDlgItem(IDHELP)->SetWindowPlacement(&wpWindowPlacement);

    return bResult;
    }

    Reply
  • Hiding and moving the standard propertysheet buttons

    Posted by Legacy on 10/09/1998 12:00am

    Originally posted by: Colin Johnson

    Zafir,
    
    

    I tried your code snippet for moving "OK" and "Cancel" after hiding
    "Apply" and "Help".

    It gave a weired result (OK and Apply were moved to top RHS of propertysheet).

    Here is an alternative technique that hides the "Apply" and "Help" buttons and moves "Cancel" and "OK" into their positions.


    BOOL CMyPropertySheet::OnInitDialog()
    {
    BOOL bResult = CPropertySheet::OnInitDialog();
    // Hide "Help" button
    CWnd* pWnd = GetDlgItem(IDHELP);
    ASSERT_VALID(pWnd);
    if (pWnd)
    {
    pWnd->ShowWindow(SW_HIDE);
    }
    // ...but remember its position
    CRect rectHelp;
    pWnd->GetWindowRect(&rectHelp);
    ScreenToClient(&rectHelp);
    pWnd = GetDlgItem(IDCANCEL);
    ASSERT_VALID(pWnd);
    // Move "Cancel" button to "Help" button's position
    if (pWnd)
    {
    pWnd->MoveWindow(&rectHelp);
    }
    // Hide "Apply" button
    pWnd = GetDlgItem(ID_APPLY_NOW);
    ASSERT_VALID(pWnd);
    if (pWnd)
    {
    pWnd->ShowWindow(SW_HIDE);
    }
    // ...but remember its position
    CRect rectApply;
    pWnd->GetWindowRect(&rectApply);
    ScreenToClient(&rectApply);
    pWnd = GetDlgItem(IDOK);
    ASSERT_VALID(pWnd);
    // Move "OK" button to "Apply" button's position
    if (pWnd)
    {
    pWnd->MoveWindow(&rectApply);
    }

    return bResult;
    }

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds