SHARE
Facebook X Pinterest WhatsApp

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 […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Nov 30, 2001
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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,0×70016);
         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);
     };
  }

Recommended for you...

Video Game Careers Overview
CodeGuru Staff
Sep 18, 2022
Dealing with non-CLS Exceptions in .NET
Hannes DuPreez
Aug 5, 2022
Online Courses to Learn Video Game Development
Ronnie Payne
Jul 8, 2022
Best Online Courses to Learn C++
CodeGuru Staff
Jun 25, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.