Two questions about Richedit

xiaoxiao2021-03-06  61

Question 1: Richeditctrl occurs when data is exchanged with DDX? why! When we are dragging a control to the program, we are usually dying is Ctrl W. Use the class wizard to associate a variable, then rely on DDX / DDV for data exchange, if we use the same method to associate with Richedit There is a problem with the variable of the cstring type, that is, if our data is greater than 64K, the data will be lost. By checking the MSDN, the WM_GETTEXT message is not designed to deal with the data greater than 64K in Richedit. The code creating the class to exchange the data of the control and CString variable with DDX_Text. Happens, the DDX_Text function is called the getWindowText function, and this function will issue a WM_GETTEXT message to the control to return the data in the control. The WM_GETTEXT message cannot accept more than 64K data, thus led to a loss of Richedit during data exchange. In order to solve this problem, we have to use the DDX_RICHText function. Add the following two functions to 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 ( '/ 0'); 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 After hWndCtrl, Value, we also need to modify the .clw file of the project, open the .clw file with the text mode. Refer to the format of the class: EXTRADDXCOUNT = 1EXTRADDX1 = 7 ;; textover64kb; cstring ;; richtext; retrieves text in Excess of 64kb from Richedit Controls If there is no previous step, we need to manually modify the code, put all DDX_Text is changed to DDX_RICHText. At the same time, you should move them outside the parsing control code. That is to remove: // {{AFX_DATA_INIT (...) //}} AFX_DATA_INIT / / {{AFX_DATA_MAP (...) //}} AFX_DATA_MAPREFERENCE: Q28044 BUG: Text From A Rich Edit Control Is Truncated Database Truncated Database Truncate Database (DDX) Question 2: When we use the class wizard to add En_Setfocus, en_killfocus is not responsive, I found that this response function is not called at all. Even a messagebox () function is not called. It turned out that the default message mapping added errors. The correct message mapping and response should be: ON_EN_SETFOCUS (IDC_RICHEDIT1, OnSetfocusRichedit1) ON_EN_KILLFOCUS (IDC_RICHEDIT1, OnKillfocusRichedit1) response function in the form of: afx_msg void OnSetfocusRichedit1 (); afx_msg void OnKillfocusRichedit1 (); but if we directly added with Class Wizard-generated The code is: ON_NOTIFY (En_Setfocus, IDC_Richedit1, OnsetFocusricHedit1) ON_NOTIFY (En_killFocus, IDC_Richedit1, onkillfocusrichedit1) We need to manually change the form.

There is also a question is that Richeditctrl sometimes does not appear in the list of control IDs of the class wizard. This requires us to add DDX / DDV functions. Do yourself! ^ _ ^ - Sampledlg.h --class csampledlg: public cdialog {public: csampledlg (cwnd * pparent = null);

// Dialog Data // {{AFX_DATA (csampledlg) Enum {IDD = IDD_SAMPLE_DIALOG}; cstract m_EDit; // Class Wizard EDIT Space Generated Variable //}} AFX_DATA

// Let's add a cricheditctrl m_richeditctrl to Richedit; .......

sampledlg.cpp - ...... void CSampleDlg :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CSampleDlg) DDX_Text (pDX, IDC_EDIT, m_edit); DDV_MaxChars (pDX , m_edit, 10); //}} AFX_DATA_MAP // manually add functions DDX_Control, DDX_Text and DDV_MaxChars DDX_Control (pDX, IDC_RICHEDIT1, m_richEditCtrl) is RICHEDIT; DDX_Text (pDX, IDC_RICHEDIT1, m_richedit); DDV_MaxChars (pDX, m_richedit, 10) } refrene: Q181664

转载请注明原文地址:https://www.9cbs.com/read-111625.html

New Post(0)