Persistence [Previous] [Next]

Persistence

If you build an application in ATL, you have to create your own persistence scheme. The ATL Scribble sample uses a simple comma-separated data format for storing the points to a file. The File Open and File Save common dialog boxes provide the file selection user interface. A sketch is persisted by enumerating over the points that define the user's strokes and writing them to the file, as you can see in this section from CStroke:

void CStroke::Save(FILE* file)
{
    int nPoints = m_points.size();
    _ftprintf(file, _T("%d\n"), nPoints);
    POINTITERATOR it;
    for(it = m_points.begin(); it != m_points.end(); it++)
    {
        POINT pt = *it;
        _ftprintf(file, _T("%d,%d\n"), pt.x, pt.y);
    }
}

Of course, you can choose whichever file format you prefer, such as XML.