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

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • On-demand Event Event Date: October 23, 2014 Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this webcast to learn why physical appliances are preferable to virtual backup appliances, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds