Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Force redraw from Serialize function

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
cathalcourtney
Asked:
cathalcourtney
  • 4
  • 3
  • 2
1 Solution
 
prakash_rajCommented:
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
 
cathalcourtneyAuthor Commented:
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
 
prakash_rajCommented:
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: 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.

 
cathalcCommented:
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
 
prakash_rajCommented:
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
 
cathalcCommented:
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
 
prakash_rajCommented:
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
 
cathalcCommented:
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
 
cathalcourtneyAuthor Commented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now