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. Clearing the Buffer in a MFC View

Clearing the Buffer in a MFC View

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
4 Posts 3 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.
  • S Offline
    S Offline
    suzie100
    wrote on last edited by
    #1

    I have a Output view in my application which inherits from the MFC CScrollView. In the Output View the application displays text information. I want to provide a ability such that on clicking a button the entire content of the Output view gets cleared. I am a MFC newbiew and do not know how to achieve this. Any help/sample code will be greatly appreciated. Thanks, Susmita

    C M 2 Replies Last reply
    0
    • S suzie100

      I have a Output view in my application which inherits from the MFC CScrollView. In the Output View the application displays text information. I want to provide a ability such that on clicking a button the entire content of the Output view gets cleared. I am a MFC newbiew and do not know how to achieve this. Any help/sample code will be greatly appreciated. Thanks, Susmita

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The output view is just a control isn't it ? So SetWindowText("") should clear it. Christian Graus - Microsoft MVP - C++

      S 1 Reply Last reply
      0
      • C Christian Graus

        The output view is just a control isn't it ? So SetWindowText("") should clear it. Christian Graus - Microsoft MVP - C++

        S Offline
        S Offline
        suzie100
        wrote on last edited by
        #3

        SetWindowText("") does not do it. I saw in the code that when ever anything is displayed in that View, the view's OnDraw(CDC* pDC) Method is called. Do I need to explicitly call it when I need to clear it?

        1 Reply Last reply
        0
        • S suzie100

          I have a Output view in my application which inherits from the MFC CScrollView. In the Output View the application displays text information. I want to provide a ability such that on clicking a button the entire content of the Output view gets cleared. I am a MFC newbiew and do not know how to achieve this. Any help/sample code will be greatly appreciated. Thanks, Susmita

          M Offline
          M Offline
          MailtoGops
          wrote on last edited by
          #4

          Hi Susmita, I could not give you answer still I haven't understood what you do in displaying the text in output view. 1. Is your Output view has OnDraw(...) or OnPaint() message handler to paint your document data on the output view? 2. Clear has different meanings.. Clear the View means do you want to clear the data which is stored in Document object? 3. OR you won't clear the document object content, but do you want to display some background color on the view? For Option 3, what you can do is 1. Have one boolean variable which is funtioning like a toggle 2. When click the button to clear the view, set the bool to true (bClear = true. Now you have to Invalidate the view/window(Which will send WM_PAINT Message and call your OnDraw / OnPaint Message handler) 3. In the OnDraw/OnPaint handler check for the boolean flag (bClear) 4. if bClear is true, then do not call any paint related function Sample Code IMPLEMENT_DYNCREATE(CPaintTestView, CView) BEGIN_MESSAGE_MAP(CPaintTestView, CView) //{{AFX_MSG_MAP(CPaintTestView) ON_COMMAND(ID_VIEW_CLEAR, OnViewClear) ON_UPDATE_COMMAND_UI(ID_VIEW_CLEAR, OnUpdateViewClear) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() .. .. ... CPaintTestView::CPaintTestView() { m_bClear = false; } ///////////////////////////////////////////////////////////////////////////// // CPaintTestView drawing void CPaintTestView::OnDraw(CDC* pDC) { CPaintTestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (m_bClear) { } else { pDC->TextOut (20,20,"I Love Bangalore"); } } void CPaintTestView::OnViewClear() { m_bClear = !m_bClear; InvalidateRect(NULL,true); } void CPaintTestView::OnUpdateViewClear(CCmdUI* pCmdUI) { if (m_bClear) { pCmdUI->SetCheck (); } else { pCmdUI->SetCheck (false); } } I hope this will help you.. " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan

          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