Solved

Redrawing window to display new message

Posted on 1998-08-25
1
242 Views
Last Modified: 2013-11-19
I wish to repaint my window so that the appropriate
message is sent as soon as a flag is set.
My code follows:
void CTextView::OnDraw(CDC* pDC)
{
      extern int text_out_flag;
      int j;
      CMainDoc* pDoc = GetDocument();

      CRect rect;
      GetClientRect(rect);
      pDC->SetTextAlign(TA_BASELINE | TA_CENTER);
//      pDC->SetTextColor(pDoc->m_colorData);
      pDC->SetBkMode(TRANSPARENT);
      // center in the window
      if (!text_out_flag)
      {
            pDC->TextOut(rect.Width() / 2, rect.Height() / 2,
            (LPCTSTR)pDoc->GetLine(0), pDoc->GetStringSize());
      }
      else //if (text_out_flag) //0824
      {
    CMDIChildWnd *pFrame =
             (CMDIChildWnd*)AfxGetApp()->m_pMainWnd;

      
            pFrame->InvalidateRect(rect, TRUE);//            pDoc->SwitchView();
            //pFrame->ValidateRect(rect);
/*            pFrame->RedrawWindow(rect, NULL, RDW_VALIDATE | RDW_UPDATENOW | RDW_ERASE);*/
            for (j=0; j<2; j++) {
                  pDC->TextOut(130, (j+2) * 30,
                  (LPCTSTR)pDoc->GetLine(j), strlen (pDoc->m_strData[j]) );
            }
      }
}

When my text_out_flag is 0, I want one message and when it is set to 1, I want another message on my View.
I have tried Invalidate(), RedrawWindow(), etc to no avail.
Please advice.
TIA.
vivek
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
1 Comment
 
LVL 2

Accepted Solution

by:
milenvk earned 50 total points
ID: 1321281
I found some general errors in your code:

1.When text_out_flag is 1 you try to invalidate or redraw the window in the OnDraw() function uncoditionally. In this way you'll end up in an eternal loop. See what happes: if text_out_flag == 1 you invalidate the window, which in turn calls your OnDraw() function which again invalidates the window and so on... Do the invalidation in the place where you change text_out_flag and leave only the drawing functionality in the OnDraw().

2. You invalidate the main frame window, which should invalidate all the children but this will not happen using RedrawWindow() unless you include the RDW_ALLCHILDREN flag.

3. You get the client rectangle of your view and then you use it in the invalidate and redraw functions. The main frame is totally different window and has a rectangle different than the view.

The standard way of handling changes in MFC is when the change occur to call CDocument::UpdateAllViews() function. This will assure proper redraw of all the visible views of the document. And finally in it is a good practice to keep the data in the document. In this way when the data change you can easily handle the change in a document command handler and call CDocument::UpdateAllViews(). In any case avoid having global variables other than theApp since they tend to turn your code into spagetti and they are really against the object oriented idea.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 92
How to know only "File created" with EventLog 3 35
Window placement 17 101
zeroFront challenge 7 137
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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