I’ve created a simple form in C, and added some controls to it. But with the edit control, I can’t append text to it, like the List Box control. All I can do is to get the text from the Edit Control, add the required lines to it, then set the text again. This is the code I wrote to do this job.
void AddText(HWND EditControl, char *NewData)
{
int TextLen = GetWindowTextLength(EditControl);
char *Result = malloc(TextLen + strlen(NewData) + 1);
if (Result == NULL) return;
GetWindowText(EditControl, Result, TextLen + 1);
memcpy(&Result[TextLen], NewData, strlen(NewData));
SetWindowText(EditControl, FinalText);
free(Result);
return;
}
Is there anyway I could append text to the Edit Control directly? Without the need to get the data then set it again?
Nothing particularly wrong with doing it this way, this executes at human time. So little point in making it faster than the user can observe. As an alternative, you can use EM_SETSEL to set the selection to the end of the existing text, selecting nothing, EM_REPLACESEL to append the text. The trick used by Winforms’ TextBoxBase.AppendText().