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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • VMware vCloud® Government Service provided by Carpathia® is an enterprise-class hybrid cloud service that delivers the tried and tested VMware capabilities widely used by government organizations today, with the added security and compliance assurance of FedRAMP authorization. The hybrid cloud is becoming more and more prevalent – in fact, nearly three-fourths of large enterprises expect to have hybrid deployments by 2015, according to a recent Gartner analyst report. Learn about the benefits of …

Most Popular Programming Stories

More for Developers

RSS Feeds