CEditView does not show text

I have a view that is derived from CEditView. It is read-only. I would like to set the text as some kind of registration, but nothing appears on the screen. If I check temp

in the debugger after GetEditCtrl().GetWindowText(temp);

I see that the text does change internally, but I can't see anything on the screen.

// HistoryView.cpp : implementation file
//

#include "stdafx.h"
#include "HistoryView.h"


// CHistoryView

IMPLEMENT_DYNCREATE(CHistoryView, CEditView)

CHistoryView::CHistoryView()
{

}

CHistoryView::~CHistoryView()
{
}

BEGIN_MESSAGE_MAP(CHistoryView, CEditView)
END_MESSAGE_MAP()


// CHistoryView diagnostics

#ifdef _DEBUG
void CHistoryView::AssertValid() const
{
    CEditView::AssertValid();
}

#ifndef _WIN32_WCE
void CHistoryView::Dump(CDumpContext& dc) const
{
    CEditView::Dump(dc);
}
#endif
#endif //_DEBUG


// CHistoryView message handlers

void CHistoryView::OnInitialUpdate()
{
    CEditView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class
    GetEditCtrl().SetReadOnly(TRUE);
}

//!
/*!
*/
void CHistoryView::AddRow(CString message)
{
    CString temp;
    GetEditCtrl().GetWindowText(temp);

    if(temp.IsEmpty())
    {
        GetEditCtrl().SetWindowText(message);
    }
    else
    {
        GetEditCtrl().SetWindowText(temp + "\r\n" + message);
    }

    GetEditCtrl().LineScroll(2, 0);
    //GetEditCtrl().UpdateWindow(); // no effect
}

      

0


source to share


4 answers


It turns out that the third party UI toolkit reverse engineered the View (who knows why?), So my pointer to it was outdated. So I did update another view!



0


source


The problem seems to lie somewhere different than the code you posted. I created a new MFC application with a view derived from CEditView and the code you use to add the text worked fine, although I had to wrap the literal "\r\n"

inside an explicit temp CString

like in:



GetEditCtrl().SetWindowText(temp + CString("\r\n") + message);

      

+2


source


As Joel says, the problem lies elsewhere. But there is a big problem with what you are doing. Copying text from a control, appending to a line, and then setting the text will have terrible performance if you add multiple lines of text to the element.

In the past, when I needed a window to display log messages, I created a view containing the control CListBox

. To add a row, call CListBox::AddString

, then when the list has the maximum number of rows, call CListBox::DeleteString

to remove the oldest item. Thus, adding rows is always fast and the amount of memory used by the control grows indefinitely.

If the text is for display only and you don't need to edit it, then I would suggest you use CListBox

.

Hope this helps!

+2


source


In addition to ChrisN's answer, if you want to keep CEdit, you can use

// sets cursor to end of text
int nCurrentLength= GetEditCtrl().GetWindowTextLength();
GetEditCtrl().SetSel(nCurrentLength,nCurrentLength); 

// appends text
GetEditCtrl().ReplaceSel("\r\nMynew line"); 

      

0


source







All Articles