我的工程时SDI的,有三个视图窗口,其中一个是用来显示文字提示信息的,继承CEditView:class MyShowView : public CEditView
{
}程序启动时,ShowView里已经显示若干文字, 但当该程序窗口被覆盖时,比如,开一个IE浏览器,盖住程序窗口,
然后再点击窗口使其显露出来, 此时ShowView里文字不能显示出来, 只有用鼠标去全选它,才能看到,按照我的想法, 当窗口由被盖住到显露出来时,系统会发送WM_ONPAINT消息,告诉整个窗口重绘,自然也包括ShowView
里的文字。不知为什么不行!各位帮忙!
{
}程序启动时,ShowView里已经显示若干文字, 但当该程序窗口被覆盖时,比如,开一个IE浏览器,盖住程序窗口,
然后再点击窗口使其显露出来, 此时ShowView里文字不能显示出来, 只有用鼠标去全选它,才能看到,按照我的想法, 当窗口由被盖住到显露出来时,系统会发送WM_ONPAINT消息,告诉整个窗口重绘,自然也包括ShowView
里的文字。不知为什么不行!各位帮忙!
updatevalue()
你说的updatevalue()这个是什么,似乎CEdit没这个方法
另外,我的View继承CEditView, 对应的doc还是普通的CDocument, 不知道有影响没有
是这样的,是不是OnPaint函数里把文字的颜色改了,或是其他地方把文字颜色改了
贴上我的代码:
里面有很注释掉的,是我测试的代码,都不行
另外,又做了一个测试,似乎在SDI下,一个doc对应多个view下, 如果这个view继承CEditView似乎
就有更新问题, 也不确定……等下加分!
/////////////////////////////////////////////////////////////////////////////
// MyShowViewIMPLEMENT_DYNCREATE(MyShowView, CEditView)MyShowView::MyShowView()
{
}MyShowView::~MyShowView()
{
}BEGIN_MESSAGE_MAP(MyShowView, CEditView)
//{{AFX_MSG_MAP(MyShowView)
ON_WM_PAINT()
ON_MESSAGE(WM_UPDATE_STATUS_TIP, OnUpdateStatusTip)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// MyShowView drawingvoid MyShowView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
// CEdit &editCtrl = this->GetEditCtrl();
// int len = editCtrl.GetWindowTextLength();
// if(len>0)
// {
// CString str;
// editCtrl.GetWindowText(str);
//
// editCtrl.SetSel(0, -1);
// editCtrl.Clear();
//
// editCtrl.SetWindowText(str);
// } //PostMessage(WM_UPDATE_STATUS_TIP, 1, 0);
// TODO: add draw code here
//old
// CEdit &editCtrl=this->GetEditCtrl();
// int len = editCtrl.GetWindowTextLength();
//
// CString showStr="";
// while(pDoc->m_tipsStart != pDoc->m_tipsEnd)
// {
// showStr += "\r\n"+pDoc->m_tips[pDoc->m_tipsStart];
// pDoc->m_tipsStart = (pDoc->m_tipsStart+1)%TIPS_BUFF_CNT;
// }
//
//// editCtrl.SetSel(len-1, len);
//// editCtrl.Clear();
//// len = editCtrl.GetWindowTextLength();
// editCtrl.SetSel(len, len);
//
// editCtrl.ReplaceSel(showStr+"\r\n...");
}
//更新打印的提示信息, 这里做了消息映射,由另一个view发送更新消息
LRESULT
MyShowView::OnUpdateStatusTip(WPARAM wParam, LPARAM lParam)
{
CMyDoc* pDoc = GetDocument();
CEdit &editCtrl=this->GetEditCtrl();
int len = editCtrl.GetWindowTextLength();
CString showStr="";
while(pDoc->m_tipsStart != pDoc->m_tipsEnd)
{
showStr += pDoc->m_tips[pDoc->m_tipsStart]+"\r\n";
pDoc->m_tipsStart = (pDoc->m_tipsStart+1)%TIPS_BUFF_CNT;
}
editCtrl.SetSel(len, len);
editCtrl.ReplaceSel(showStr);
//editCtrl.Invalidate(false); return 0L;
}BOOL MyShowView::PreCreateWindow(CREATESTRUCT& cs)
{
//MyShowView.TextOut() // TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CEditView::PreCreateWindow(cs);
}
// MyShowView message handlersvoid MyShowView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
this->OnDraw(&dc); // for test
//this->GetEditCtrl().Invalidate(false);
// Do not call CEditView::OnPaint() for painting messages
}void MyShowView::OnInitialUpdate()
{
//CEditView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class GetDocument()->pMyShowView = this;
GetEditCtrl().SetReadOnly(true);
}