Auto Scrolling a Single Line PropertySheet Tab Control

Environment: all versions of windows. VC6, Win32.

When using property sheets with a large number of pages (for whatever reason) and where there is limited space available, it is often useful to use the single line version. This displays a spin control on the tab control to allow the user to scroll the various tabs into view.

The problem: When the user needs to scroll left they must continually go over to the spin control that is normally on the right hand side to scroll the tabs and then return to select the page they need.

A solution: The technique I present below gets around this problem by automatically scrolling the tabs by one when the selected tab is on the edge thus bringing the next tab into view. There may be more elegant ways to solve this but this gives you the gist.

This solution was developed primarily for use on a maximised property sheet whilst using a PocketPC, on these devices it is not possible to use the Ctrl+Tab and Ctrl+Shift+Tab keyboard shortcuts. The solution though applies equally to desktop solutions.

The PostMessage parameters were determined by using Spy++ on the msctls_updown32 window.

HWND hTabCtrl = NULL;
HWND hWndSpin = NULL;

// Call this function whenever a propertsheet page 
// receives a PSN_SETACTIVE notification:

void AutoScroll(HWND hWndMain)
{
   if(hTabCtrl)
   {
      int iItem;
      RECT rItemRect,rWindow;
     
      GetWindowRect(hWndMain,&rWindow);
     
      iItem = TabCtrl_GetCurSel(hTabCtrl);
      TabCtrl_GetItemRect(hTabCtrl,iItem,&rItemRect);

      if(rItemRect.left < 10)
      {
         PostMessage(hWndSpin,WM_LBUTTONDOWN,1,0x9000A);
         PostMessage(hWndSpin,WM_LBUTTONUP,1,0xD000D);
      }
     
      if(rItemRect.right > rWindow.right-40)
      {
         PostMessage(hWndSpin,WM_LBUTTONDOWN,1,0x70016);
         PostMessage(hWndSpin,WM_LBUTTONUP,1,0x6001B);
      }
   }
}

// Add this code snippet to your property sheet initialisation:

   case PSCB_INITIALIZED:
   {
      // Find the hWnd for the spin control on the tab control

      TCHAR classname[100];

      hTabCtrl = PropSheet_GetTabControl(hWndDlg);

      HWND hWndFind = GetWindow(hTabCtrl,GW_HWNDFIRST);

      while(hWndFind)
      {
         GetClassName(hWndFind,classname,100);

         if(lstrcmp(_T("SysTabControl32"),classname) == 0)
            hWndFind = GetWindow(hWndFind,GW_CHILD);
         else if(lstrcmp(_T("msctls_updown32"),classname) == 0)
         {
            hWndSpin = hWndFind;
            break;
         }
         else
            hWndFind = GetWindow(hWndFind,GW_HWNDNEXT);
     };
  }


Comments

  • Do you have a demo project?

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: Danielle

    ?

    Please let me know. My email address is brinasas@yahoo.com

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

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds