Automatically arrange visible controls below the tab control


How to Help Your Business Become an AI Early Adopter

Here is some code for realigning the controls present on a property sheet. The code realigns the controls that are beneath the tab control, which have the WS_VISIBLE style. The controls are repositioned from right to left, in reverse tab order, and being separated by a standard distance. This is handy for realigning the controls after you have changed the visibile state of the buttons at the bottom of the property sheet. You can also use this function during OnInitDialog(..) as the visible state of the controls is obtained by checking the window style of the child control, and not by using IsWindowVisible(..).

void CPropertySheetDerivedClass::AutoArrangeButtons() 
	CWnd* pWnd = GetDlgItem(ID_APPLY_NOW);
	if (pWnd && ::IsWindow(pWnd->m_hWnd))
		// Get the last control in the tab order - (tab order is the same as creation order)
		pWnd = pWnd->GetWindow(GW_HWNDLAST);

		// Get the tab control
		CTabCtrl* pTabCtrl = GetTabControl();

		// Get the child identifier of the tab control
		int nTabControlID = ::GetWindowLong(pTabCtrl->m_hWnd, GWL_ID);

		// Child control identifier
		int nControlID = 0;

		// The window rect of the tab control.
		CRect rcTAB(0, 0, 0, 0);



		CRect rcTemp(0, 0, 0, 0);


		int nLeft = rcTemp.right;
		int nSpacing = rcTemp.right - rcTAB.right;

		// do this bit while we have a control to do something with
			// Get the ID of the current child control
			nControlID = ::GetWindowLong(pWnd->m_hWnd, GWL_ID);
			// Do not make changes to the tab control!!
			if (nControlID != nTabControlID)
				// do some stuff


				// Is the child control visible? - Don't use IsWindowVisible as the parent
				// also has to be visible for that to return TRUE;
				BOOL bChildIsVisible = ((pWnd->GetStyle() & WS_VISIBLE) == WS_VISIBLE);

				// Make sure we are below the TAB control
				if (( > rcTAB.bottom) && bChildIsVisible)
					// Move each control
					nLeft -= nSpacing + rcTemp.Width();
					pWnd->MoveWindow(nLeft,, rcTemp.Width(), rcTemp.Height());
			// Go back in the TAB order again
			pWnd = pWnd->GetWindow(GW_HWNDPREV);

Last updated: 29 April 1998


  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Agencies that integrate back-office processed with cloud-based services, advanced analytics and talent management solutions can reduce costs, maximize efficiencies and transform employee recruitment and retention. Learn more by reading this interview brief by GovLoop with Infor industry thought leaders.

  • The software-defined WAN (SD-WAN) has emerged as the solution for enterprises embracing cloud computing as a means to realizing digital transformation. In this IDC brief, learn why the need for SD-WAN will be even greater than the need for SDN in the data center, especially when an organization's application profile is migrating toward public cloud services and where customer engagement is most valued.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date