Thanks for clarifying that. I started reading up on this stuff last
classes better. I'll be working through the SCRIBBLE tutorial today,
and will work on a better design for the app. The suggestions and
few things up. BTW, the app is SDI, so your example is clearly
understood.
MK wrote:
Some informative suggestions there and it's starting to make sense to
use the document interface. The problem is that I don't know how to use
it, so I'll need to read up on it and look at some practical examples.
In the meantime, it would be great to clarify a few things.
Scott, once I have the document template, how do I send data to it (eg.
a file name), so it will update the tree control? I've written some
code to get the document template, but I don't know if it's ok... How
can I use pobjDocTemplate to do what I need to?
POSITION pos = theApp.GetFirstDocTemplatePosition();
CDocTemplate * pobjDocTemplate = theApp.GetNextDocTemplate(pos);
You should go through the SCRIBBLE tutorial that introduces examples of
most fundamental MFC concepts.
I don't think you've said whether your app is SDI or MDI. If SDI there
is only one doc object. Continue the above code with...
pos = GetFirstDocPosition();
CMyDoc* pDoc = (CMyDoc*)GetNextDoc(pos);
Now you can call your document. Suppose you add a doc function like...
pDoc->AddFile(fileName);
void CMyDoc::AddFile(LPCTSTR czFilename)
{
// You may wish to add czFilename to some internal data such as
// a list of files. Or, at minimum you could do this:
UpdateAllViews(NULL, HINT_NEW_FILE, (CObject*)czFilename);
}
where HINT_NEW_FILE is a #define in doc.h.
Having done all this, override OnUpdate in your view(s) to receive the
parameters passed to UpdateAllViews.
And why did we do all this? To improve maintainablility by reducing
dependencies. The dialog has no dependencies on anything. The view
depends only on the doc, no matter where its data may actually come
from. And the views have no dependencies on each other - a big feature
if future evolution brings more or different views.
--
Scott McPhillips [VC++ MVP]