Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Redrawing window to display new message

Posted on 1998-08-25
1
Medium Priority
?
248 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

715 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