Assuming the cursor is on some point inside the textbox, with this code you can edit the line the cursor is on:
GetCtrlAttribute (panel, control, ATTR_TEXT_SELECTION_START, &idx);
GetTextBoxLineIndexFromOffset (panel, control, idx, &line);
GetTextBoxLineOffset (panel, control, line, &start);
GetTextBoxLine (panel, control, line, msg);
sprintf (target, "%.*s%c%s", idx - start, msg, asciiCode, msg + idx-start);
ReplaceTextBoxLine (panel, control, line, target);
SetCtrlAttribute (panel, control, ATTR_TEXT_SELECTION_START, ++idx);
Here some explanations:
ATTR_TEXT_SELECTION_START attribute gives you the start of selected text. If no text is selected (which should be your case) gives you the position of the cursor in bytes (=characters) from the start of the textbox
From this value, I determine the line the cursor is in and the offset of the first character of the line (from which the position of the cursor inside the line can be determined).
Next I update the line and write it back to the textbox.
The last line of code restores cursor position after the new character written (ReplaceTextBoxLine places the cursor at the beginning of the line).
This should solve your problem
Roberto