Wince Edit Control copy/paste
Author: Lai yuping (aulyp@163.com)
In Windows CE, when you write an MFC program, the Edit Control is frequently used. However, by default, the content you input on the control does not support copying and pasting, there is no right-click menu, which is very inconvenient. I found no detailed information on Google. I can only read the help documentation of E. In fact, it is not difficult to implement it. The following is the step, share it with you.
1) Respond to the wm_rbuttondown message in pretranslatemessage. (For more information about how to reload pretranslatemessage in MFC, see my other blog .)
Bool newsmsdlg: pretranslatemessage (MSG * PMSG) <br/>{< br/> DWORD regvalue; <br/> bool bproces; <br/> // static bool com7state; <br/> switch (PMSG-> message) <br/>{< br/> case wm_rbuttonup: /* Right click message */<br/> {<br/> If (getfocus () = getdlgitem (idc_edit_newwrite )) // The Judgment focus is not in the box <br/>{< br/> retailmsg (1, (text ("Right button/R/N "))); <br/> point Pt = {0}; <br/> getcursorpos (& pt ); // obtain the mouse clicking position <br/> // ------ generate the corresponding menu ------------------------- <br/> cmenu menu; <br/> menu. createpopupmenu (); // generate a menu object <br/> menu. appendmenu (mf_string, contenteditcopy, l "copy"); <br/> menu. appendmenu (mf_string, contenteditpaste, l "Paste"); <br/> menu. trackpopupmenu (0, PT. x, PT. y, this); // plistctrl <br/> menu. destroymenu (); <br/>}< br/> break; <br/> default: break; <br/>}< br/> return cdialog:: pretranslatemessage (PMSG); <br/>}< br/>
2) Respond to menu events
All menu messages in MFC are processed in oncommand and the oncommand function is reloaded. The specific method is to open the header file of the dialog window where your editcontrol is located, and then focus the mouse on the class, view the "properties" window,
Then process menu operations in oncommand, such as copying/pasting
Bool newsmsdlg: oncommand (wparam, lparam) </P> <p >{</P> <p> int menuid = loword (wparam ); </P> <p> switch (menuid) </P> <p >{</P> <p> case contenteditcopy: // copy </P> <p >{</P> <p>: sendmessage (getdlgitem (idc_edit_newwrite)-> getsafehwnd (), wm_copy, 0, 0 ); </P> <p> break; </P> <p >}</P> <p> case contenteditpaste: // paste </P> <p >{</P> <p>: sendmessage (getdlgitem (idc_edit_newwrite)-> getsafehwnd (), wm_paste, 0, 0 ); </P> <p> break; </P> <p >}</P> <p> default: break; </P> <p >}</P> <p> return cdialog: oncommand (wparam, lparam ); </P> <p >}</P> <p>
Here, the editcontrol control in your program can be used to copy and paste data.