You're asking for some very specific functionality. It sounds like you are either building a scheduling app or are trying to display a log of things that have happened in the past. This is called a Gantt Chart. You can buy Gannt Chart controls for MFC on the web. Google for some.
There's more to your question than just how to paint it; You cannot and should not be using a CListCtrl as your data structure. You seem to have an array of objects that are start & end times. For example:
struct Range {
int startTime;
int endTime;
};
std::vector<Range> events;
Once you have put your events into this simple vector, you will have to loop through all of the elements and compare the start/end times to see if they overlap the Range that you are considering:
typedef std::vector<Range> RangeVec;
typedef RangeVec::iterator RangeIter;
void is_between(int time, const Range& r)
{
return time >= r.start && time <= r.end;
}
void findRanges(RangeVec *matches, const RangeVec& input, const Range& query)
{
for (RangeIter it = input.begin(); it != input.end(); ++it) {
if (is_between(it.start, query) || is_between(it.end, query) ||
(it.start <= query.start && it.end >= query.end))
{
matches->push_back(*it);
}
}
You can now loop through your matches and display them however you want. If you are brave, it's rather easy to write a custom control with a subclassed CWnd::OnPaint() that just draws rectangles as long as your overlapped range representing each match.