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;
}
Output Window
I have this code:
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.
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.
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.
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.
Also, what kind of window is returned by GetOutputWindow? This function doesn't seem to be a standard Win API function.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement