?
Solved

Force redraw from Serialize function

Posted on 2003-02-25
9
Medium Priority
?
298 Views
Last Modified: 2013-12-27
Hi
I am using MFC for windows CE and I am loading pretty large documents into my application so I want to periodically update the view as I am loading in the document in my Serialize function.

I have tried UpdateAllViews(NULL) and CView's Invalidate()but neither of these not call my OnDraw function in my View Class.

Any help greatly appreciated

Cathal
0
Comment
Question by:cathalcourtney
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:prakash_raj
ID: 8026880
Hi Cathal,

ok.. UpdateAllViews(NULL) calls OnUpdate() of each views.

I wonder if you are doing any optimizing work in your View's OnUpdate() method.. Could you please tell what exactly you do there??

Cheers,
Prakash
0
 

Author Comment

by:cathalcourtney
ID: 8028368
hi Prakash,
Bit of a newbie to MFC, thought UpdateAllViews() forced a repaint of all views and automatically called the OnDraw() function. I didn't have an OnUpdate function, so I added that and included a call to OnDraw in that function and it kinda works now. The application doesn't display any menu bar until the serialize function finishes though.

Dont suppose you have any ideas about this?? My Serialize function is called from CDocument::OnOpenDocument() and the file open dialog is displayed until this function finishes. So I am getting the text that I want to print off ontop of this dialog and no menu bar

Thanks for your help
Really appreciate it

Cathal
0
 
LVL 3

Expert Comment

by:prakash_raj
ID: 8031677
Hi Cathal,

Hope you added OnUpdate using Classwizard..

And for the other things, seems you need to modify your code a little. Could you post them??

Cheers,
Prakash
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Expert Comment

by:cathalc
ID: 8040817
Hi Prakash,
Used the class wizard for the OnUpdate function alright, I have tried a few different things but I still cant get the menu to appear during the serialize function.

here is my on draw, The call to OnOpenDocument is the same as CDocument::OnOpenDocument except I have take out the wait cursor in it. I had this in my OnOpenFile function initially but I thought if I put it in my OnDraw function I would get the menu. In my OnUpdate function all I do is get and instance of CClientDC and call the OnDraw function. In my serialize function all I am doing is reading in the file and I periodically call UpdateAllViews().

void CEBookReaderView::OnDraw(CDC* pDC)
{
  CString PageNumber;
  CEBookReaderDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  static BOOL temp = FALSE;

  pDC->SelectObject(&pDoc->m_Font);
     
  if (pDoc->m_BookReady == TRUE
&& pDoc->m_LineListReady == FALSE)
  {
    pDoc->OnOpenDocument(pDoc->m_FileName);
  }
     

  if (pDoc->m_LineListReady)
  {
   // line number of current page
   pDoc->m_StartLine =
     (pDoc->m_PageNumber-1)*(pDoc->m_LinesPerPage);
         
   pDC->SetTextColor(pDoc->m_FontColor);

   // Print out page
   for (unsigned int k = 0;
     (k < pDoc->m_LinesPerPage); k++)
   {
     pDC->ExtTextOut(pDoc->m_Margin,
    pDoc->m_Margin + (k+1)*pDoc->m_LineHeight, 0, NULL,
    pDoc->m_LineList[pDoc->m_StartLine+k], 0);
}

  // If there is text highlighted, highlight it
  if (pDoc->m_IsTextHighlighted == TRUE)
  {    
    // next click gets rid of highlighted text
    pDoc->m_ClickCount = 2;
    pDoc->HighlightText();
  }

   // Check if annotations on the page
      and display them if there are

   pDoc->CheckIfAnnotationOnPage(pDC);

   // Check if bookmarks and Change font for
       page number if there are

    for (k = 0 ; k <10 && 
     pDoc->m_BookMarkedPages[k].pageNumber != 0; k++)
    {
      if (pDoc->m_BookMarkedPages[k].pageNumber ==
          pDoc->m_PageNumber)
        pDC->SetTextColor(pDoc->m_BookmarkColor);
    }

    // Print out the page number
    PageNumber.Format(_T("<< %i / %i >>"),
    pDoc->m_PageNumber, pDoc->m_NumberOfPages);
         
    pDC->ExtTextOut((pDoc->m_PageWidth)/2-pDoc->m_Margin,
        pDoc->m_PageHeight+pDoc->m_Margin, 0, NULL,  
        PageNumber, 0);    
}

else
{
    CBitmap ReaderLogo;
         
    ReaderLogo.LoadBitmap(ID_READERLOGO);
    BITMAP bmpinfo;
    ReaderLogo.GetBitmap(&bmpinfo);
    CDC dcMemory;
    dcMemory.CreateCompatibleDC(pDC);
     
    CBitmap* pOldBitMap =
    dcMemory.SelectObject(&ReaderLogo);
    CRect rect;
    GetClientRect(&rect);
    int nX = rect.left + (rect.Width()
    -  bmpinfo.bmWidth) / 2;
    int nY = rect.top + (rect.Height()
       - bmpinfo.bmHeight)/2;

    pDC->BitBlt(nX, nY, bmpinfo.bmWidth, bmpinfo.bmHeight, &dcMemory,0,0,SRCCOPY);

    dcMemory.SelectObject(pOldBitMap);
}
     
}



Any Ideas???????

Thanks again for your help

Cathal
0
 
LVL 3

Expert Comment

by:prakash_raj
ID: 8040930
Hi,

I would suggest to re-organize your code!

First Do not call OnOpenDocument during onDraw().

The better approach would be like First Serialize the document, keep the list of things which needs to be drawn ready, THEN call OnDraw..

I dont know the other parts of the program, but as for as i could see now, When you serialize, load all the data members of your document [like m_LineList].. Until then dont call draw!

Cheers,
Prakash

0
 

Expert Comment

by:cathalc
ID: 8041026
Hey Prakash
This is what I am trying to do though!! My application is a Book Reader and in my serialize function I am calculating the lines in the book, but this takes too long for very large files so I want to display the first page of the book and then periodically update the view as I am calculating the lines in the book.

The way it is working at the moment I am getting the first page printed to the screen and my serialize function periodically updates this, but I cant get the menu bar to appear while I am doing this.

I thought putting the OnOpenDocument in the OnDraw might fix this, but no joy there.

Do you know if it is possible to do this??

Thanks again!

Cathal
0
 
LVL 3

Accepted Solution

by:
prakash_raj earned 200 total points
ID: 8041084
Hi Cathal,

then I would suggest to re-work on serialize().

ideally the file has to be read completely before drawing. but if you want to display the first page atleast in the beginning, then you might to a trick like :

First read the few lines which are enough to show as the first page! display them.. and with the wait cursor ON, read the rest of the file in the background[as a separate thread maybe].. Once it's done, Refresh the view to display the actual content which is ready now!

Does this make sense to you?

Cheers,
Prakash
0
 

Expert Comment

by:cathalc
ID: 8041092
Hey Prakash
This is what I am trying to do though!! My application is a Book Reader and in my serialize function I am calculating the lines in the book, but this takes too long for very large files so I want to display the first page of the book and then periodically update the view as I am calculating the lines in the book.

The way it is working at the moment I am getting the first page printed to the screen and my serialize function periodically updates this, but I cant get the menu bar to appear while I am doing this.

I thought putting the OnOpenDocument in the OnDraw might fix this, but no joy there.

Do you know if it is possible to do this??

Thanks again!

Cathal
0
 

Author Comment

by:cathalcourtney
ID: 8053270
Thanks Prakash
I was kinda hoping there would be an easier way around it, but I guess using a seperate thread for the serialize function is the way to go.

Thanks for all your help!!

Cathal
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I think the most popular question in our Windows Mobile Programming zone is about the backlight - we all want to keep it on when our application is running. Few years ago the function SystemIdleTimerReset() did this job. On our side we had to detec…
Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

764 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