What is the best way to schedule in MFC?

I have a list of items, each of which is associated with a start and end date. I want to do this, given the time and date range, to display only the elements that fall into this window, even partially.

What I am doing is creating CListCtrl with all the elements in it, and CListCtrl is sorted by default startup time. But given the time range, I don’t know how to look for the first element within the range.

Another problem with the list control is to display it as a list, whereas it would be nice if there was a control that could also show things that are parallel side by side.

I do this in a dialog application.

+3
source share
2 answers

You are requesting some specific functions. It looks like you are creating a planning application or trying to display a log of events that occurred in the past. This is called a Gantt chart . You can buy Gannt Chart controls for MFC online. Google for some.

There is more to your question than just drawing it; You cannot and should not use CListCtrl as your data structure. It seems you have an array of objects that start and end. For instance:

struct Range {
   int startTime; 
   int endTime;
};
std::vector<Range> events;

After you have placed your events in this simple vector, you have to iterate over all the elements and compare the start and 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);
    }
}

, . , CWnd:: OnPaint(), , .

+2

.

, , , . . , , , .

0

Source: https://habr.com/ru/post/1740631/


All Articles