Weekly Hours Selector | CodeGuru

Weekly Hours Selector

Environment:Windows NT 4 SP5, Visual C++ 6 SP3 Ever wanted a grid selector like the one used in User Manager for Domains or the one in Replication Schedules for Exchange.  I couldn’t find a good enough, small enough or cheap enough control anywhere, so I created my own.  It has 2 simple methods (GetHoursArray & […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 15, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment:Windows NT 4 SP5, Visual C++ 6 SP3

Ever wanted a grid selector like the one used in User Manager for Domains or
the one in Replication Schedules for Exchange.  I
couldn’t find a good enough, small enough or cheap enough control anywhere, so I created my own. 
It has 2 simple methods (GetHoursArray & SetHoursArray), and 2 simple events
(Verbose & Click).

  • The control is set using the Mouse, Keyboard or call to SetHoursArray(VARIANT
    osaArray) method.
  • The control is read by using the call to VARIANT GetHoursArray() method.

An Entire Week can be kept in 84 Bytes if each interval is 15 Minutes in
length.
i.e.) (24HoursPerDay * 60MinutesPerHour * 7DaysPerWeek) /
15MinsPerQuarter = 672Bits / 8BitsPerByte = 84Bytes

// Variables (l_ocal & m_ember)
CHoursSelector 	m_hsTimes;	// Defined in the Class Wizard

 COleSafeArray	l_osaHours;	// Set based on the return from GetHoursArray
 char		l_szArray[84];	// Assigned with a loop

 // Reading from the Control
 unsigned char 	cBits;
 l_osaHours = m_hsTimes.GetHoursArray();

 for( long x=0; x<84; x++ )	{
  l_osaHours.GetElement( &x, &cBits );
  l_szArray[x]= cBits;
 }

 // Check a point in time (here it's 10:15am Jan 5, 2000)
 COleDateTime	l_odtDate(2000, 01, 05, 10, 15, 00);

 // Sunday=0
 long	lOffset = ( ( ( l_odtDate.GetDayOfWeek() - 1 ) * 1440 ) +
  ( l_odtDate.GetHour() * 60 ) + l_odtDate.GetMinute() ) / 15;

 int	nByte = lOffset / 8;
 int	nBit = lOffset - (nByte * 8);

 if( ( ( l_szArray[nByte]>> nBit ) & 0x01 ) == 0x01 )	{
  // Item is Set
 }


 // Writing to the Control
 unsigned char	cBits = (1 << nBit);
 l_szArray[nByte] |= cBits;

 for( long x=0; x<84; x++ )	{
  l_osaHours.PutElement( &x, &l_szArray[x] );
 }

 m_hsTimes.SetHoursArray(l_osaHours);

Downloads

Download demo project – 40 Kb
Remember to run "REGSVR32 <ocxpath>\HoursSelector.ocx"
Download source – 44 Kb

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. © 2026 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.