Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can OnDraw be overridden to open a text file?

Posted on 1998-09-17
7
290 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 94
has77  challenge 9 90
withoutTen challenge 14 131
Problem to open Excel file 15 178
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

837 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