Sign in to follow this  

Output Window

This topic is 2791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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");
	Mess.append(newLine);
	std::wstring oMess(Buffer);
	oMess.append(strtowstr(Mess));
	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

This topic is 2791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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