gpt4 book ai didi

c++ - CEditView 不显示文本

转载 作者:行者123 更新时间:2023-11-27 23:35:35 25 4
gpt4 key购买 nike

我有一个派生自 CEditView 的 View 。它是只读的。我想将文本设置为一种日志记录,但屏幕上没有显示任何内容。如果我在 GetEditCtrl().GetWindowText(temp); 之后检查调试器中的 temp,我可以看到文本确实在内部发生变化,但我在屏幕上看不到任何内容。

// 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
}

最佳答案

问题似乎出在您发布的代码之外的其他地方。我使用从 CEditView 派生的 View 创建了一个新的 MFC 应用程序,并且您用来添加文本的代码工作正常,尽管我确实必须将文字 "\r\n" 包装在一个显式临时 CString,如:

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

关于c++ - CEditView 不显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/422081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com