Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Redrawing window to display new message

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

879 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