I have created a simple MFC SDI Application with an Ribbon. The View for the Document is a FormView with on Edit Control.
If I now use CTRL+V to paste some Text in the Edit Control nothing happens. Same goes with CTRL+C to copy the Text inside the Edit Control. I could use the Context Menu if i right click inside the Edit Control. But how can i enable the Shortcuts? The CTRL + C etc is inside the Accelerator List. If i add the following to the MainForm
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_COMMAND(ID_EDIT_COPY, &CMainFrame::onCopy)
END_MESSAGE_MAP()
and the Function itself
void CMainFrame::onCopy() {
AfxMessageBox(L"Copy");
}
If i now press CTRL+C the MessageBox Pops up. But i could not copy the text of the Edit Control to the Clipboard. How could I chose between copy text from an Edit Text and doing something else if a different control is selected and CTRL+C is pressed(e.g. if i select text inside the Edit Control it should be copied to the clipboard. If i select e.g. an Item from a Tree View only a popup should shown)?
Use
ON_UPDATE_COMMAND_UI
to enable/disable command. UseON_COMMAND
to respond to the same command.You then have to forward the message to the edit control (
m_edit.Copy()
). You can do this directly inCMyView
class (remove the handler fromCMainFrame
)If there are more than one edit control,
GetFocus
will report which edit control has focus.CEdit::GetSel
will report if selection is available.Do the same with paste. Use
m_edit.CanPaste()
to see if paste is available. Usem_edit.Paste()
for paste command.Or you can do this in
CMainFrame
, you have to find the handle to the view class and edit control.Also make sure accelerator key is added.