Click to See Complete Forum and Search --> : outputing text to screen, please help


Danielle Harvey
April 24th, 1999, 06:38 PM
When I output text to the screen within the view class's OnDraw function,
the text stays up on the screen. I can erase the screen by using the Invalidate()
command.

I use the following code which outputs text in a different function,

void TextView::OnForward()
{
CClientDC cDC(this);
CDialog dlg;

if (dlg.DOModal() == IDOK)
cDC.TextOut(10,10,"hi");
}

When I run the program, I get 2 words in the SDI/MDI child, but when I
use the mouse to move the program or do some scrolling, the text outputted
by the OnForward() function disappears and the text from the OnDraw()
function stays. How can I get the text in the OnForward() function to stay
there until I tell it I want it to disappear?

I am confused, frustrated, and desperate for a resolution. Please, any response
any one can give me will be greatly appreciated.

question
April 24th, 1999, 07:40 PM
I think the question is the message handle you used.It just work as what it look like.When you scroll the window,the view will call OnDraw and OnPrepare won't be called any more,so it look wrong.You can declare a variable to hold the text and use a bool variable to test whether to show it or not and do this in the OnDraw.Ok.

Danielle Harvey
April 24th, 1999, 07:50 PM
How do you declare this bool variable?

Jerry Coffin
April 30th, 1999, 10:00 PM
This is the primary reason for using the document/view architecture in the first place. The document stores enough information for the view to be able to redraw itself when needed. In your case, you probably want a CString variable in the CDocument-derived class associated with your view. This string will store the string you currently want displayed in the view:

CString MyString;

this will need to be a public variable inside of the CDocument class.

Then, in your OnDraw, you'll have something like:

pDC->TextOut(pDoc->MyString);

and in OnForward, you'll have something like:

GetDocument()->MyString = "hi";
UpdateAllViews();

the call to UpdateAllViews will force all the views of the document to redraw themselves to display the new string. This string will be displayed until it gets changed again...


The universe is a figment of its own imagination.

Sean Lee
May 1st, 1999, 01:27 AM
Sorry, Jerry Coffin. I used your post.
Danielle, I added a few code to Jerry Coffin's original code to answer your question.
----------------------------------------

This is the primary reason for using the document/view architecture in the first place. The document stores enough information for the view to be able to redraw itself when needed. In your case, you probably want a CString variable in the CDocument-derived class associated with your view. This string will store the string you currently want displayed in the view:

BOOL m_bShowString;
CString MyString;

this will need to be a public variable inside of the CDocument class.

Then, in your OnDraw, you'll have something like:

if (pDoc->m_bShowString) {
pDC->TextOut(pDoc->MyString);
}

and in OnForward, you'll have something like:

if (dlg.DOModal() == IDOK) {
GetDocument()->m_bShowString = TRUE;
GetDocument()->MyString = "hi";
UpdateAllViews();
}
else {
GetDocument()->m_bShowString = FALSE;
UpdateAllViews();
}


the call to UpdateAllViews will force all the views of the document to redraw themselves to display the new string. This string will be displayed until it gets changed again...


The universe is a figment of its own imagination.

----------------------------------------
And there is another solution.
You may use one variable.

OnDraw:

if (!pDoc->MyString.IsEmpty()) {
pDC->TextOut(pDoc->MyString);
}

OnForward:

if (dlg.DOModal() == IDOK) {
GetDocument()->MyString = "hi";
UpdateAllViews();
}
else {
GetDocument()->MyString.Empty();
UpdateAllViews();
}

alcon17
June 17th, 1999, 10:08 AM
How would you do that with multiline text??