Solved

Can OnDraw be overridden to open a text file?

Posted on 1998-09-17
7
285 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 100 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now