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 …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds