demonplus
demonplus

Reputation: 5801

Copy paste in CTreeView labels

I have a control derived from CTreeView in MFC SDI application (containing splitter, CTreeView and CDetailsView basically). What is working for me is editing labels in nodes of tree view by processing the end of edit

ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, &CNavigationView::OnTvnEndlabeledit)

I want to add copy/paste functionality with Ctrl+C and Ctrl+V. I think this deals with TVN_BEGINLABELEDIT and TVN_KEYDOWN but I can't figure out how to make this work correctly, may be some ideas or sample?

void CNavigationView::OnTvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMTVDISPINFO pTVDispInfo = reinterpret_cast<LPNMTVDISPINFO>(pNMHDR);
    if (pTVDispInfo && pTVDispInfo->item.pszText)
    {
    }
}

When I am trying to paste text from Notepad, pTVDispInfo->item.pszText is NULL according to debugger.

I am working in Visual Studio 2013, Windows 8.

Upvotes: 0

Views: 361

Answers (1)

xMRi
xMRi

Reputation: 15355

I suppose you already have an accelerator defined in you application that also uses Ctrl-V. So inside the inplace edit control you press Ctrl+V but this causes a WM_COMMAND message to be generated from the accelerator. The accelerator executes something that aborts the inplace edit job.

In such a case You need a PreTranslateMessage handler that checks if keyboard input arrives with Ctrl+C/Ctrl+V and directs this input to the edit control that is open instead of letting the frame window accelerator to handle it.

Just set a breakpoint and look into the callstack and check what is executed when the inplace edit stops.

Upvotes: 1

Related Questions