[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Can OnDraw be overridden to open a text file?

Posted on 1998-09-17
7
Medium Priority
?
297 Views
Last Modified: 2013-11-20
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?

Thanks...
0
Comment
Question by:vmehro
  • 4
  • 2
7 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1322243
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.

Phillip

0
 

Author Comment

by:vmehro
ID: 1322244
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.
Thanks.
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1322245
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vmehro
ID: 1322246
Thanks milenvk.

0
 

Author Comment

by:vmehro
ID: 1322247
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
MyDoc::InitDocument().
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....

0
 
LVL 7

Accepted Solution

by:
psdavis earned 300 total points
ID: 1322248
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.

Phillip
0
 

Author Comment

by:vmehro
ID: 1322249
Thanks psdavis. I am aware of the flag you mentioned.
I guess I did not use it the right way.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question