Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A problem of using CScrollView [modified]

A problem of using CScrollView [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphicshostingcloud
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    whiteclouds
    wrote on last edited by
    #1

    Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:

    class CEditorView : public CScrollView
    {
    ......
    private:
    CBitmap m_bmpMem;//cache
    ......
    }
    void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
    {
    CSize sizeTotal;
    //Calculate the size of View
    GetViewSize(sizeTotal);
    SetScrollSizes(MM_TEXT, sizeTotal);

    CDC \*pDC,memDC;
    CBitmap \*pOldBmp;
    
    pDC = GetDC();
    ASSERT(pDC != NULL);
    
    memDC.CreateCompatibleDC(pDC);
    memDC.SetMapMode(m\_nMapMode);
    
    m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy);
    pOldBmp = memDC.SelectObject(&m\_bmpMem);
    OnDraw(&memDC);
    memDC.SelectObject(pOldBmp);
    
    ReleaseDC(pDC);
    InvalidateRect(NULL);
    UpdateWindow();
    

    }
    void CEditorView::OnDraw(CDC* pDC)
    {
    CEditorDoc* pDoc = GetDocument();
    ASSERT(pDoc != NULL);
    /*
    Draw the content in View through pDC.
    */
    }
    void CEditorView::OnPaint()
    {
    CPaintDC dc(this); // device context for painting
    CDC MemDC;
    CBitmap *pOldBitmap;
    CSize size;

    OnPrepareDC(&dc);
    
    size = GetTotalSize(); 
    
    // Need a memory DC
    MemDC.CreateCompatibleDC(&dc);
    
    //Set MapMode
    MemDC.SetMapMode(m\_nMapMode);
    
    // Select in the bitmap
    pOldBitmap =  MemDC.SelectObject(&m\_bmpMem);
    
    // Blt it
    dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY );
    
    // Clean up
    MemDC.SelectObject(pOldBitmap);
    
    CScrollView::OnPaint();
    

    }

    Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds

    There is some white cloud floating on the blue sky. That's the landscape I like.

    modified on Monday, March 8, 2010 4:45

    R 2 Replies Last reply
    0
    • W whiteclouds

      Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:

      class CEditorView : public CScrollView
      {
      ......
      private:
      CBitmap m_bmpMem;//cache
      ......
      }
      void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
      {
      CSize sizeTotal;
      //Calculate the size of View
      GetViewSize(sizeTotal);
      SetScrollSizes(MM_TEXT, sizeTotal);

      CDC \*pDC,memDC;
      CBitmap \*pOldBmp;
      
      pDC = GetDC();
      ASSERT(pDC != NULL);
      
      memDC.CreateCompatibleDC(pDC);
      memDC.SetMapMode(m\_nMapMode);
      
      m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy);
      pOldBmp = memDC.SelectObject(&m\_bmpMem);
      OnDraw(&memDC);
      memDC.SelectObject(pOldBmp);
      
      ReleaseDC(pDC);
      InvalidateRect(NULL);
      UpdateWindow();
      

      }
      void CEditorView::OnDraw(CDC* pDC)
      {
      CEditorDoc* pDoc = GetDocument();
      ASSERT(pDoc != NULL);
      /*
      Draw the content in View through pDC.
      */
      }
      void CEditorView::OnPaint()
      {
      CPaintDC dc(this); // device context for painting
      CDC MemDC;
      CBitmap *pOldBitmap;
      CSize size;

      OnPrepareDC(&dc);
      
      size = GetTotalSize(); 
      
      // Need a memory DC
      MemDC.CreateCompatibleDC(&dc);
      
      //Set MapMode
      MemDC.SetMapMode(m\_nMapMode);
      
      // Select in the bitmap
      pOldBitmap =  MemDC.SelectObject(&m\_bmpMem);
      
      // Blt it
      dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY );
      
      // Clean up
      MemDC.SelectObject(pOldBitmap);
      
      CScrollView::OnPaint();
      

      }

      Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds

      There is some white cloud floating on the blue sky. That's the landscape I like.

      modified on Monday, March 8, 2010 4:45

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      whiteclouds wrote:

      What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()?

      Read the comments[^]

      W 1 Reply Last reply
      0
      • W whiteclouds

        Hi, All! I am developing an application to show the Text file. Now I derive a class from CScrollView. But I find that the view will flicker at the time I scroll the window when the text is too long to show in one page. So I declare a variable of CBitmap as a member of ScrollView class. Then in the member function of OnUpdate(), I declare a variable of CDC to create a compatibleDC and select the CBitmap into it. After that, I try to draw the view, save the view into CBitmap and Bitblt it into the Device Context of the window in the member funcation OnPaint(). Code:

        class CEditorView : public CScrollView
        {
        ......
        private:
        CBitmap m_bmpMem;//cache
        ......
        }
        void CEditorView::OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/)
        {
        CSize sizeTotal;
        //Calculate the size of View
        GetViewSize(sizeTotal);
        SetScrollSizes(MM_TEXT, sizeTotal);

        CDC \*pDC,memDC;
        CBitmap \*pOldBmp;
        
        pDC = GetDC();
        ASSERT(pDC != NULL);
        
        memDC.CreateCompatibleDC(pDC);
        memDC.SetMapMode(m\_nMapMode);
        
        m\_bmpMem.CreateCompatibleBitmap(pDC,sizeTotal.cx,sizeTotal.cy);
        pOldBmp = memDC.SelectObject(&m\_bmpMem);
        OnDraw(&memDC);
        memDC.SelectObject(pOldBmp);
        
        ReleaseDC(pDC);
        InvalidateRect(NULL);
        UpdateWindow();
        

        }
        void CEditorView::OnDraw(CDC* pDC)
        {
        CEditorDoc* pDoc = GetDocument();
        ASSERT(pDoc != NULL);
        /*
        Draw the content in View through pDC.
        */
        }
        void CEditorView::OnPaint()
        {
        CPaintDC dc(this); // device context for painting
        CDC MemDC;
        CBitmap *pOldBitmap;
        CSize size;

        OnPrepareDC(&dc);
        
        size = GetTotalSize(); 
        
        // Need a memory DC
        MemDC.CreateCompatibleDC(&dc);
        
        //Set MapMode
        MemDC.SetMapMode(m\_nMapMode);
        
        // Select in the bitmap
        pOldBitmap =  MemDC.SelectObject(&m\_bmpMem);
        
        // Blt it
        dc.BitBlt( 0, -size.cy, size.cx, size.cy, &MemDC, 0, -size.cy, SRCCOPY );
        
        // Clean up
        MemDC.SelectObject(pOldBitmap);
        
        CScrollView::OnPaint();
        

        }

        Question: 1. After I do as above, no text can be shown. I find that it will be shown only when I make the Message Declaration of OnPaint as comment. I don't know how to resolve it. I hope some one could be kind to tell me how to do. Thks! 2. What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()? Pls help me! Thks a lot!! whiteclouds

        There is some white cloud floating on the blue sky. That's the landscape I like.

        modified on Monday, March 8, 2010 4:45

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        Commenting out your handler forces the Doc/View to call its own OnPaint method. In fact, drawing is handled by the OnDraw function in this case. I presume that the CScrollView::OnPaint(); at the end of your handler erases the result of the code above it.

        1 Reply Last reply
        0
        • R Rage

          whiteclouds wrote:

          What on earth the relation between OnPaint() and OnDraw()? Why the content can't be seen when I add the function OnPaint()?

          Read the comments[^]

          W Offline
          W Offline
          whiteclouds
          wrote on last edited by
          #4

          Thank Rage! The message u provide is very useful. And I had make it clear. By the way, I had resolved this problem. This problem was caused by the wrong parameters when calling dc.BitBlt(...) in the function OnPaint(). :)

          There is some white cloud floating on the blue sky. That's the landscape I like.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups