Weekly Hours Selector
Posted
by Jeff Palmer
on January 15th, 2000

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 KbRemember to run "REGSVR32 <ocxpath>\HoursSelector.ocx"
Download source - 44 Kb

Comments
This is crap...
Posted by Legacy on 12/03/2002 12:00amOriginally posted by: Tester
This is the biggest piece of crap that I have seen in quite a while...
Not only does the programmer not comment their code... ( as mentioned by another commentor ) but the control does not scale up or down, the code has "magic numbers" in it, the code is not scalable, and the code uses .odl instead of .idl ....
ReplyThis is a very good example of how NOT to produce an activeX control.
One Problem - not related to this issue
Posted by Legacy on 06/25/2002 12:00amOriginally posted by: Vel
I am experiencing a problem with virtual method.
Here is the problem description. Could you pl. help me solve this issue? I am extremely sorry for asking your time.
I am having the following classes:
Section
MySection
TimeSection ProgramSection
MySection inherits from Section.
TimeSection and ProgramSection inherit from MySection.
I am having many virtual functions both Section & MySection.
As usual, the derived class objects are used in the application and many methods in MySection & Section are polymorphic.
I have a method LoadFieldData() in MySection (virtual) & implemented them in ProgramSection.
The above is the existing application design. Pl. note that LoadFieldData() is not implemented in TimeSection.
I have added the implementation of LoadFieldData() method to TimeSection also for my need now.
There was a method CreateProjection() defined as virtual in MySection and implemented in all the derived classes. I am encountering a problem in invoking this method.
I invoke the method CreateProjection() as given below
MySection *pMySec;
pMySec = new TimeSection
pMySec->CreateProjection()
When I debug the application, I found that another function DisplayData() (this is yet another virtual function in MySection & implemented in TimeSection & ProgramSection) is being called.
Its really surprising to me.
I just moved the declaration of CreateProjection() to the bottom most possible place and re-compiled & rebuilt the application.
Now, I found that another function (say Xyz() ) is being called.
I tried the above techniq few more times and finding this abnormal behaviour consistently.
Could you pl. help in solving this issue?
What I need is:
I need to add the LoadFieldData() method to TimeSection class and make sure I call this method without affecting the existing functionality. What I am finding is, the code that was working fine earlier (invocation of CreateProjection() ) is not working fine now.
Environment : Sun Solaris 2.6, Sun C++ 4.2
Thanks in Advance,
Regards
ReplyVel
time
Posted by Legacy on 05/22/2002 12:00amOriginally posted by: rich
how do i use this
ReplyDialog bOx
Posted by Legacy on 01/10/2002 12:00amOriginally posted by: vjchithra
I have gone thru u'r site,an informative thing for VC++.
Replyi have a requirement to call the windows login Dialog Box thru VC++ or call windows login file to check my user names and passwords thru VC++.
kindly provide some useful hints w.r to that
thanks in advance
http://go.to/fnx
Posted by Legacy on 01/05/2002 12:00amOriginally posted by: Nil
Yeah, but I have another source, maybe you want to see...
mail me if you want
Replygood, simple & nice
Posted by Legacy on 11/27/2001 12:00amOriginally posted by: mohd sharil
good
Replyi am trying to solve this 20 yrs back problem..Y2k
Posted by Legacy on 09/18/2001 12:00amOriginally posted by: Nikhilesh Shukla
Hi all,
actually here I am trying to solve one problem..
in this problem.. sombody has written one function that
will calculate yrs using system time i mean.. ticks( no of secs from 1970 to till date) so they calcu lated in this manner..
ReplyThanks!!
Posted by Legacy on 05/07/2001 12:00amOriginally posted by: Inho Park
Good---
ReplyThank you!!
Problem with datetimeControl
Posted by Legacy on 01/23/2001 12:00amOriginally posted by: Rajasekhar
Hello!
I am placing a datetime control in my evc project.I want to set the time to hh:mm AM/PM only.This information is in the CString , like '12:30 PM'.I want to set this to the DatetimeControl.How to convert it to any datetime(CTime,COleDateTimeCtrl) object?
Please help me in this regard.
email to chavasekhar@rediffmail.com
ReplyRegards..
Rajasekhar
Yes but...
Posted by Legacy on 07/31/2000 12:00amOriginally posted by: J Martin
What I heard was "if it was difficult to write, it should be difficult to understand"
ReplyLoading, Please Wait ...