Add a line at the end of a multiline edit box using var_args. Author: Luca Cavalli
/* *****************************************************************
* NAME: AppendText
* DESCRIPTION: Append a text line to a message window.
* PARAMS: hWnd (IN) -> window handle
* nCtrlID (IN) -> edit window ID
* szFormat (IN) -> formatting string, same as
printf()
* ... (IN) -> variable number of parameters
* RETURN: None.
* NOTE: Add \r\n at the end of the string to start a new line.
* ******************************************************************
*/
void AppendText(HWND hWnd, UINT nCtrlID, LPCTSTR szFormat, ...)
{
static TCHAR szMessage[MAX_STRING_LENGHT]; // text message
va_list args;
// argument list
LONG nTxtLen;
// lenght of text message
/* move caret at the end of text */
nTxtLen = SendDlgItemMessage(hWnd, nCtrlID, WM_GETTEXTLENGTH, 0, 0);
SendDlgItemMessage(hWnd, nCtrlID, EM_SETSEL, (WPARAM)nTxtLen,
(LPARAM)nTxtLen);
SetFocus(GetDlgItem(hWnd, nCtrlID));
va_start(args, szFormat);
_vstprintf(szMessage, szFormat, args);
va_end(args);
/* add the text line */
SendDlgItemMessage(hWnd, nCtrlID, EM_REPLACESEL, (WPARAM)FALSE,
(LPARAM)szMessage);
}