Home > Software engineering >  Use MFC CRichEdit controls
Use MFC CRichEdit controls

Time:01-09

Recently in the use of MFC to develop software meets a very confused problem, software USES CRichEdit control that is used to display the log color, I have also successfully used the control,
The software on some colleagues computer can run normally, also can display the color normal font, but on individual colleagues computer can not run normally, and we use computer system are win10, development environment, also on no development environment of computer software can run normally, I use the development environment is Visual Studio 2008.
RichEdit the add library I also loaded, the software after the log area shows part of collapse, through the breakpoints view, is a function of the RichEdit GetWindowTextW () function is a problem, prompt access conflict, but the content of the show before certainly also calls the function, then also no problem, I don't know what is causing this kind of phenomenon,

CodePudding user response:

Direct operation in this thread?

CodePudding user response:

For, is in the child thread operation, the function as follows, but the software works on some computers, not on some computer, don't know how this
Void IMEICHECKDlg: : AddLogString (cstrings strLog, a COLORREF color)
{
Cstrings log=CurrentTime ();
StrLog +=_T (" \ r \ n ");

Int nOldLines=0;
Int nNewLines=0;
Int nScroll=0;
Long nInsertionPoint=0;
CHARFORMAT cf;
NOldLines=m_richEdit. GetLineCount ();
Cf. CbSize=sizeof (CHARFORMAT);
Cf. DwMask=CFM_COLOR;
Cf. The dwEffects=0;
Cf. CrTextColor=RGB (0, 0);
NInsertionPoint=m_richEdit. GetWindowTextLengthW ();
NInsertionPoint=1;
M_richEdit. SetSel (nInsertionPoint, 1);
M_richEdit. SetSelectionCharFormat (cf);
M_richEdit. ReplaceSel (log);

Cf. CrTextColor=color;
NInsertionPoint=m_richEdit. GetWindowTextLengthW ();
M_richEdit. SetSel (nInsertionPoint, 1);
M_richEdit. SetSelectionCharFormat (cf);
M_richEdit. ReplaceSel (strLog);

NNewLines=m_richEdit. GetLineCount ();
NScroll=nNewLines - nOldLines;
M_richEdit. LineScroll (nScroll);

return;
}

CodePudding user response:

Check strLog

CodePudding user response:

Try to modify the parameter type
Void AddLogString (cstrings & amp; StrLog, a COLORREF color)

Debug version, install remote debugger in the melt machines, remote debugging under


CodePudding user response:

Remote debugging tools to install??

CodePudding user response:

The
reference 3 floor schlafenhamster response:
check strLog
strLog is to use a new line

CodePudding user response:

Should or thread operation problem,
Open source file RichEdit afxcmn. Look inl, part I stick up,
 
Const _AFXCMN_INLINE BOOL CRichEditCtrl: : CanUndo ()
{ASSERT (: : IsWindow (m_hWnd)); Return (BOOL) : : SendMessage (m_hWnd, EM_CANUNDO, 0, 0); }
Const _AFXCMN_INLINE BOOL CRichEditCtrl: : CanRedo ()
{ASSERT (: : IsWindow (m_hWnd)); Return (BOOL) : : SendMessage (m_hWnd, EM_CANREDO, 0, 0); }
Const _AFXCMN_INLINE UNDONAMEID CRichEditCtrl: : GetUndoName ()
{ASSERT (: : IsWindow (m_hWnd)); Return (UNDONAMEID) : : SendMessage (m_hWnd, EM_GETUNDONAME, 0, 0); }
Const _AFXCMN_INLINE UNDONAMEID CRichEditCtrl: : GetRedoName ()
{ASSERT (: : IsWindow (m_hWnd)); Return (UNDONAMEID) : : SendMessage (m_hWnd, EM_GETREDONAME, 0, 0); }
Const _AFXCMN_INLINE int CRichEditCtrl: : GetLineCount ()
{ASSERT (: : IsWindow (m_hWnd)); Return (int) : : SendMessage (m_hWnd, EM_GETLINECOUNT, 0, 0); }
Const _AFXCMN_INLINE BOOL CRichEditCtrl: : GetModify ()
{ASSERT (: : IsWindow (m_hWnd)); Return (BOOL) : : SendMessage (m_hWnd, EM_GETMODIFY, 0, 0); }
_AFXCMN_INLINE void CRichEditCtrl: : SetModify (BOOL bModified/*=TRUE */)
{ASSERT (: : IsWindow (m_hWnd)); : : SendMessage (m_hWnd, EM_SETMODIFY, bModified, 0); }
_AFXCMN_INLINE BOOL CRichEditCtrl: : SetTextMode (UINT fMode)
{ASSERT (: : IsWindow (m_hWnd)); Return (BOOL) : : SendMessage (m_hWnd, EM_SETTEXTMODE, (WPARAM) fMode, 0). }


RichEdit own function is achieved by SendMessage, these functions is thread-safe,
GetWindowText is a function of CWnd, this will not work across threads,
 
Int CWnd: : GetWindowText (_Out_z_cap_post_count_ (nMaxCount, return + 1) LPTSTR lpszString, _In_ int nMaxCount) const
{
ASSERT (: : IsWindow (m_hWnd) | | (m_pCtrlSite!=NULL));

If (m_pCtrlSite==NULL)
Return: : GetWindowText (m_hWnd, lpszString nMaxCount);
The else
{
Cstrings STR.

M_pCtrlSite - & gt; GetWindowText (STR);
Checked: : tcsncpy_s (lpszString nMaxCount, STR, _TRUNCATE);
Return lstrlen (lpszString);
}
}


So you should use the CRichEditCtrl your member function was no problem, even if the debug to the positioning error, is also puzzling, meaningless,
My word is much, give points,
  • Related