Clearing the Buffer in a MFC View
-
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
-
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
The output view is just a control isn't it ? So SetWindowText("") should clear it. Christian Graus - Microsoft MVP - C++
-
The output view is just a control isn't it ? So SetWindowText("") should clear it. Christian Graus - Microsoft MVP - C++
-
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
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