Right-click RichEdit/edit in formview and respond to shortcut keys such as Ctrl + C.

Source: Internet
Author: User
I encountered this problem repeatedly and it was very difficult to query the information. I simply put it here for my friends to learn from.
Faq-it.org/apache/ ========================================================== ==========================================
Microsoft is so disgusting that it cannot easily add the right-click menu function item for formview or richeditctrl on dialog. After searching materials and using them, you need to use this method to achieve it:

Notes

1. The system command cannot appear in the right-click menu, for example, id_edit_undo/id_edit_copy/id_edit_paste/id_edit_cut/id_edit_selall. Otherwise, the message cannot be responded.
2. For menu items, message processing cannot be performed using oncommand. on_message must be used in message map and the good message function such as onmenuundo must be defined in the header file.
Begin_message_map (creferenceformview, cformview)
// {Afx_msg_map (creferenceformview)
On_message (id_menu_undo, onmenuundo)
On_message (id_menu_cut, onmenucut)
On_message (id_menu_copy, onmenucopy)
On_message (id_menu_paste, onmenupaste)
On_message (id_menu_clear, onmenuclear)
On_message (id_menu_select_all, onmenuselectall)
//} Afx_msg_map
End_message_map ()

3. You must call the oninitialupdate () function of formview or the oninitialdialog () function of dialog.
M_ctrlricheditreference.seteventmask (enm_mouseevents );
Indicates that the mouse event of richeditctrl is handled by the parent form.
4. Handle the following in the onnotify message of the parent form (formview or dialog:
Bool creferenceformview: onnotify (wparam, lparam, lresult * presult)
{
// Todo: add your specialized code here and/or call the base class
Key Aspect 1:

The richeditctrl sends the message "en_msgfilter" to the parent, now to get at which message has been reflected (because it cocould be a left click or a mouse move) we need to examine the message filter, So we cast lparam to msgfilter *


Msgfilter * lpmsgfilter = (msgfilter *) lparam;
Key Aspect 2:
If (wparam = idc_richedit_reference) & (lpmsgfilter-> nmhdr. Code = en_msgfilter)
& (Lpmsgfilter-> MSG = wm_rbuttondown ))

{
// If we get through here, we have trapped the right click event of the richeditctrl!
Cpoint point;
: Getcursorpos (& Point); // Where is the mouse?
Cmenu menu; // lets display out context menu :)
Uint dwselectionmade;
Verify (menu. loadmenu (idr_mnu_reference4re ));
Cmenu * pmenupopup = menu. getsubmenu (0 );
Assert (pmenupopup! = NULL );
Dwselectionmade = pmenupopup-> trackpopupmenu (tpm_leftalign implements TPM _ leftbutton implements TPM _ nonotify implements TPM _ returncmd ),
Point. X, point. Y, this
);

Pmenupopup-> destroymenu ();
Postmessage (dwselectionmade, 0, 0 );
}

Return cformview: onnotify (wparam, lparam, presult );
}

References:
Http://lib.training.ru/Lib/ArticleDetail.aspx? AR = 468 & l = N & MI = 17 & Mic = 344


---------------------------------------------------------------
The upper floor only supports Right-click menu response, adding, how to respond to shortcuts, and passing messages down:

Bool cformviewrecordeditor: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class
If (PMSG-> message = wm_keydown)
{
Switch (PMSG-> wparam)
{
Case 0x41: // selete all
Case 0x46: // Ctrl + F
Case 0x56: // Ctrl + V:
Case 0x58: // cut
Case 0x43: // copy
Case 0x5a: // undo
Case 0x59: // redo
If (getkeystate (vk_control) & 0x80 ))
{
M_ctlricheditfulltext.sendmessage (PMSG-> message, PMSG-> wparam, PMSG-> lparam );
Return true;
}
Break;
}
} // End: If (PMSG-> message );

Return cformview: pretranslatemessage (PMSG );
}

All of the above Code You can only apply the effect to richeditctrl on formview or propertypage. To respond to the shortcut key for edit that appears in the parent form, use the following code:

Bool cppfieldeditnormal: pretranslatemessage (MSG * PMSG)
{
// Todo: add your specialized code here and/or call the base class
If (PMSG-> message = wm_keydown)
{
Switch (PMSG-> wparam)
{
Case 0x41: // selete all
Case 0x46: // Ctrl + F
Case 0x56: // Ctrl + V:
Case 0x58: // cut
Case 0x43: // copy
Case 0x5a: // undo
Case 0x59: // redo
If (getkeystate (vk_control) & 0x80) & (m_ctleditfieldvalue.m_hwnd = getfocus ()-> m_hwnd ))
{
// M_ctleditfieldvalue.sendmessage (PMSG-> message, PMSG-> wparam, PMSG-> lparam); // This method cannot respond correctly
//: Postmessage (m_ctleditfieldvalue.m_hwnd, PMSG-> message, PMSG-> wparam, PMSG-> lparam); // This method cannot respond correctly.
// M_ctleditfieldvalue.sendmessage (wm_command, (wparam) id_edit_paste, (lparam) 0); // This method cannot respond correctly
: Postmessage (m_ctleditfieldvalue.m_hwnd, wm_paste, (wparam) 0, (lparam) 0); // This method can respond correctly !!
}
Return true;
}
Break;
}
} // End: If (PMSG-> message );

Return cpropertypage: pretranslatemessage (PMSG );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.