我正在使用 MFC Feature Pack 构建一个项目。这个项目是否我有一个包含 的窗口CView,其中包含一个CListCtrl衍生对象。该对象包括LVS_EDITLABELS标志。
不知何故,我无法CListCtrl通过两次单击(不是双击)图标标签来编辑图标标签。在我通过单击选择项目后,第二次单击只会使项目闪烁(向下按钮将文本背景变为白色,向上按钮将其变为蓝色)并且编辑控件永远不会出现。
我将这个问题简化为最简单的形式,即使使用普通CListCtrl对象我也无法编辑标签。
我还发现:
这个问题出现在VS2008中。在VS2003内置的类似项目中不会出现这种情况。
如果我构建 a
CListView而不是CView+ ,我可以编辑标签CListCtrl。如果我构建一个
CFormView并将其CListCtrl放入资源对话框中,我也可以编辑标签。
下面是一些最简单形式的代码:.h 文件:
// vwTerminaisTeste.h
//
#pragma once
// vwTerminaisTeste view
class vwTerminaisTeste : public CView
{
DECLARE_DYNCREATE(vwTerminaisTeste)
protected:
vwTerminaisTeste(); // protected constructor used by dynamic creation
virtual ~vwTerminaisTeste();
CListCtrl m_lstTerminais;
protected:
DECLARE_MESSAGE_MAP()
virtual void OnDraw(CDC* /*pDC*/);
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
和 .cpp 文件:
// vwTerminaisTeste.cpp : implementation file
//
#include "stdafx.h"
#include "vwTerminaisTeste.h"
// vwTerminaisTeste
IMPLEMENT_DYNCREATE(vwTerminaisTeste, CView)
vwTerminaisTeste::vwTerminaisTeste()
{
}
vwTerminaisTeste::~vwTerminaisTeste()
{
}
BEGIN_MESSAGE_MAP(vwTerminaisTeste, CView)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
// vwTerminaisTeste message handlers
void vwTerminaisTeste::OnDraw(CDC* /*pDC*/)
{
CDocument* pDoc = GetDocument();
}
int vwTerminaisTeste::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_lstTerminais.Create(WS_CHILD | WS_VISIBLE | LVS_EDITLABELS, CRect(0,0,1,1), this, 0);
m_lstTerminais.InsertItem(0, "Teste", 0);
return 0;
}
void vwTerminaisTeste::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if (IsWindow(m_lstTerminais.GetSafeHwnd()))
m_lstTerminais.MoveWindow(0, 0, cx, cy);
}
这样我就无法编辑标签。要将其更改为,CListView我只需将其替换CView为CListViewand m_lstTerminaisby GetListCtrl(),并删除OnCreateandOnSize实现。这样它就起作用了。
注意:vwTerminaisTeste是从 -派生类中创建CSplitterWndEx的。CMDIChildWndEx