Sign in to follow this  
Matthew Shockley

Output Window

Recommended Posts

I have this code:
std::wstring strtowstr(const std::string &str) {
    // Convert an ASCII string to a Unicode String
    std::wstring wstrTo;
    wchar_t *wszTo = new wchar_t[str.length() + 1];
    wszTo[str.size()] = L'\0';
    MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, wszTo, (int)str.length());
    wstrTo = wszTo;
    delete[] wszTo;
    return wstrTo;

void Output(const char *Str) {
	HWND nWind = GetOutputWindow();
	int Length = GetWindowTextLength(nWind);
	wchar_t *Buffer = new wchar_t[Length+1];
	GetWindowText(nWind, Buffer, Length+1);
	std::string Mess(Str);
	std::string newLine("\n");
	std::wstring oMess(Buffer);
	SendMessage(nWind, WM_SETTEXT, 0, (LPARAM)oMess.c_str());
	delete [] Buffer;
For some reason, the newline character won't work. It just doesn't appear. I am probably doing something wrong(I do that alot), so could anyone help me make it where it goes to a newline everytime. And if you could, I would much appreciate if you could clean up my sloppy code.

Share this post

Link to post
Share on other sites
Are you sure strtowstr works? You should step through the code with a debugger and confirm that the newline is correctly appended to the original string and that the string is then correctly converted to a wstring.

Also, instead of using Mess.append(newLine) you can just do Mess += "\n". You should also consider using some whitespace and comments to make the code easier to read.

Share this post

Link to post
Share on other sites
Usually with Windows controls you use \r\n as new line.

Also, what kind of window is returned by GetOutputWindow? This function doesn't seem to be a standard Win API function.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this