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