[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Can OnDraw be overridden to open a text file?

Posted on 1998-09-17
7
Medium Priority
?
296 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
[X]
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
  • 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
Independent Software Vendors: 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 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