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

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds