Let's say you want to be able to log data to a Windows console window and want to use the convenience of printf.

The hole with this example is that it does not handle cases where the string exceeds the fixed array size.

Thanks to folks on this forum for the help.


void Log(const char* pszText)
{
   int nLength = GetWindowTextLength(hwndEdit); 
   SendMessage(hwndEdit, EM_SETSEL, (WPARAM)nLength, (LPARAM)nLength);
   SendMessage(hwndEdit,EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)pszText);
}

void Logf(char* fmt, ...)
{  char buf[1000];
   va_list ap;
   va_start (ap, fmt);
   vsprintf(buf, fmt, ap);
   va_end(ap);
   Log(buf);
}

-- MattWalsh - 02 Feb 2006

Topic revision: r1 - 03 Feb 2006 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback