|
-
April 24th, 1999, 06:38 PM
#1
outputing text to screen, please help
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.
-
April 24th, 1999, 07:40 PM
#2
Re: outputing text to screen, please help
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.
-
April 24th, 1999, 07:50 PM
#3
Re: outputing text to screen, please help
How do you declare this bool variable?
-
April 30th, 1999, 10:00 PM
#4
Re: outputing text to screen, please help
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.
-
May 1st, 1999, 01:27 AM
#5
Re: outputing text to screen, please help
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();
}
-
June 17th, 1999, 10:08 AM
#6
Re: outputing text to screen, please help
How would you do that with multiline text??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|