Can OnDraw be overridden to open a text file?

I have a MDI application. In one Doc-View instance,
on opening a Document file, I would like the View to
display a text file. The text file would have to be
updated as my program progresses.
Is this possible? Do I have to override the OnDraw function
of the View?

Who is Participating?
psdavisConnect With a Mentor Commented:
I'm sorry but my answer still stands as being the correct way.  

Let's see if we can at least clear up and explain the madness... :)

What you might encounter is if the user updates the text, or sizes the window, or covers the window with another dialog, or minimizes or a multitude of other things.  You will need to redraw the data from scratch at some time or another.

First off, the TextOut is incredibly easy to use.  You may just be missing a feature that you might not know exists.  When outputing the text, you can use the TA_UPDATECP parameter to update your current position.

If an application needs to update the current position when it calls TextOut, the application can call the SetTextAlign member function with nFlags set to TA_UPDATECP. When this flag is set, Windows ignores the x and y parameters on subsequent calls to TextOut, using the current position instead.

So your TextOut function is now just...

pDC.TextOut( 0, 0, text );

So when your data is added to your document, just TextOut the text in it's last known position and you should be appending the data just fine.

Now you will want to use the UpdateAllViews since the document will be updated.  If the view is doing the updates to the document, the UpdateAllViews will actually be quite moot and won't do much, but it is still good Windows practice.

Sure.  As you update the text in the document, throw out a UpdateAllViews to tell the view that it needs to be updated.  You can even use the hint mechanism inside of OnUpdate to draw only the text that is needed as well.


vmehroAuthor Commented:
Thanks psdavis.
Maybe, I did not make myself clear.
With an OnDraw function, I can do a DrawText or a TextOut.
And UpdateAllViews, etc.
That is not the way I wish to go.
I want to read the contents of a text file, and just display.
Like a printf().
My program would keep updating a text file. This text file would have to be displayed on the screen as a READ ONLY for the user.
I am (I guess) trying to use a printf on a view without the
hassle of TextOut, etc.
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Well, psdavis is correct. This is Windows and not DOS. There should be a moment when you need to update the screen. OnDraw is called by the system and not by you. You can explicitly invoke it using the proposed by psdavis technique. Of course you can try to override the OnDraw but you'll end up without any update of your window, except if you explicitly call a function that updates the screen. And printf is another story. What it has to do with drawing in Windows at all? The "hassle" of TextOut is needed because you are drawing in a graphics environment and not on a 80x25 characters screen.
Why don't you use CEditView then? It will be much more easy for you to use the "printf like" functionallity of the CEditView. Check out the GetEditCtrl().SetWindowText() combination of the CEditView.
vmehroAuthor Commented:
Thanks milenvk.

vmehroAuthor Commented:
My problem actually is not to simplify TextOut, but
to display a text file. Maybe, I don't understand fully well that
a document (that has a view) can be updated exactly like a text file can. I mean, my program can write to the document as
the program progresses.
Right now, the view displays the stuff I have in
I want the document to be continually changing. So, I need
to figure out a way to read the latest document and display
it. (Just as I would a text file).
After which, I can just do a OnDraw() with Update, etc...
I hope I make sense. If I don't, thanks for your time....

vmehroAuthor Commented:
Thanks psdavis. I am aware of the flag you mentioned.
I guess I did not use it the right way.

All Courses

From novice to tech pro — start learning today.