Unable to edit tags in CListCtrl

I am creating a project with Feature Pack MFC. This project has a window that includes CView, which includes the CListCtrl-derived object . The object includes a flag LVS_EDITLABELS.

Somehow I can’t edit the icon labels by CListCtrldouble-clicking (not double-clicking) on ​​the icon label. After I select an item with one click, the second click simply blinks over the item (the down button turns the text to white, the button returns it to blue) and the edit control never appears.

I have reduced this problem to its simplest form and even with a simple object CListCtrlI cannot edit labels.

I also found that:

  • This issue occurs in VS2008. This does not happen in a similar project built in VS2003.

  • I can edit labels if I create CListViewinstead of CView+ CListCtrl.

  • I can also edit tags if I create CFormViewand put CListCtrlin the resource dialog.

Here's some code in its simplest form: an .h file:

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

and .cpp file:

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

Thus, I cannot edit tags. To change it to CListView, I simply replaced CViewwith CListViewand m_lstTerminaisby GetListCtrl()and removed the implementations of OnCreateand OnSize. So it worked.

Note: vwTerminaisTestecreated from CSplitterWndExin the CMDIChildWndEx-derived class .

+3
source share
2 answers

, , , CView CFormView ListView, CListCtrl.

- , , .

+1

, , , VS2003. / ctrl vwTerminaisTeste / MDIChild . , . / - ...

BEGIN_MESSAGE_MAP(MySplitter, CSplitterWnd)
  ON_WM_SETFOCUS()
END_MESSAGE_MAP(...)

void MySplitter::OnSetFocus(CWnd* pOldWnd)
{
  // forward focus to the view window
  m_vwTerminaisTeste.SetFocus();
}

BOOL MySplitter::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
  // let the view have first crack at the command
  if (m_vwTerminaisTeste.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
    return TRUE;

  // otherwise, do default handling
  return MySplitter::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
+1

Source: https://habr.com/ru/post/1706585/


All Articles