Jump to content
  • Advertisement
Sign in to follow this  
Matthew Shockley

Output Window

This topic is 3007 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!