im adding lines to a richedit control and after a while it starts to overwrite text
i create the window like this in the main window proc WM_CREATE
HINSTANCE RichEditLibHinstance = LoadLibrary("Riched32.dll");
HWND RichEdithWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "RichEdit", "", WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY | CS_PARENTDC, 174, 0, 320, 240, hwnd, (HMENU)IDC_RICHEDIT, GetModuleHandle(NULL), NULL);
and i made a function to add a single line to the richedit control like this
void AddLinetoRichEdit(char* cpyText)
{
CHARFORMAT cfSysText;
ZeroMemory(&cfSysText, sizeof(CHARFORMAT));
cfSysText.cbSize = sizeof(CHARFORMAT);
cfSysText.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE;
cfSysText.crTextColor = RGB(255, 255, 255);
strcpy(cfSysText.szFaceName, "Courier New");
cfSysText.yHeight = -11;
int nCpyText = strlen(cpyText);
int nLength = GetWindowTextLength(RichEdithWnd);
SendMessage(RichEdithWnd, EM_SETSEL, nLength, nLength);
SendMessage(RichEdithWnd, EM_REPLACESEL, false, (LPARAM)cpyText);
SendMessage(RichEdithWnd, EM_SETSEL, nLength, nLength + nCpyText);
SendMessage(RichEdithWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfSysText);
SendMessage(RichEdithWnd, EM_SETSEL, nLength + nCpyText, nLength + nCpyText);
strcpy(cpyText, "\n");
nCpyText = strlen(cpyText);
nLength = GetWindowTextLength(RichEdithWnd);
SendMessage(RichEdithWnd, EM_SETSEL, nLength, nLength);
SendMessage(RichEdithWnd, EM_REPLACESEL, false, (LPARAM)cpyText);
SendMessage(RichEdithWnd, EM_SETSEL, nLength, nLength + nCpyText);
SendMessage(RichEdithWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfSysText);
SendMessage(RichEdithWnd, EM_SETSEL, nLength + nCpyText, nLength + nCpyText);
}
it does the job until the GetWindowTextLength returns somethin greater then 65,535 then it seams to start over and
starts adding the cpyText to the begining of the richedit control instead of appending it to the bottom.
ive tried calling getlasterror everywhere in my code and nothin returns anything besides "The operation completed successfully."
ive also watched nLength to see if it somehow goes back to 0 but it never does
i dont have any idea whats goin on..can anybody help me figure this out? please...
it happens when the nLength variable is higher then 65,535
i tried declaring it as
unsigned int nLength;
nothing changed
i tried
SendMessage WM_GETTEXTLENGTH
instead of the GetWindowTextLength function
nothing changed
i tried casting all wparam and lparam parameters in the SendMessge function
nothing changed
i tried using Riched20.dll instead of the riched32.dll
nothing changed
there has got to be a way to do this..somebody has got to know whats going wrong