Two questions about RichEdit

Source: Internet
Author: User

Problem 1:richeditctrl data loss occurs when using DDX for data exchange? why!

When we drag a control into the program, usually the hair is ctrl+w, with the Class wizard to the control associated with a variable, and then rely on DDX/DDV for data exchange, if we use the same method to give RichEdit a CString type of variable will have a problem, Is that if our data is greater than 64K, the data will be lost.

By checking MSDN, the Wm_gettext message was not designed to be handled when the RichEdit data was greater than 64K. The Class Wizard generates code that uses DDX_Text to exchange data for controls and CString variables. Exactly, the DDX_Text function calls the GetWindowText function, which emits a wm_gettext message to the control to return the data in the control. Wm_gettext messages cannot accept more than 64K of data, which results in the loss of RichEdit in the event of a data exchange.

To solve this problem, we need to use the Ddx_richtext function. Add the following two functions to the project

DWORD CALLBACK es2memcallback (dword_ptr dwcookie,lpbyte pbbuff, Long CB, long *PCB)
{
lptstr& lpszstrfill = * (lptstr*) Dwcookie;
memcpy (Lpszstrfill, pbbuff, *PCB = cb);
Lpszstrfill + + cb;
*lpszstrfill = TCHAR (' ");
return 0;
}
void Afxapi Ddx_richtext (cdataexchange* pDX, int nIDC, cstring& value)
{
extern void Afxapi Afxsetwindowtext (HWND Hwndctrl, LPCTSTR lpsznew);
HWND Hwndctrl = Pdx->prepareeditctrl (NIDC);
if (pdx->m_bsaveandvalidate)
{
int nlen =:: Getwindowtextlength (Hwndctrl);
LPTSTR Lpszstrfill = value. GetBufferSetLength (Nlen);
Editstream es = {(dword_ptr) &lpszstrfill, 0, es2memcallback};
:: SendMessage (Hwndctrl, Em_streamout, Sf_text, (LPARAM) &es);
Value. ReleaseBuffer ();
}
Else
{
Afxsetwindowtext (Hwndctrl, value);
}
}

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.