Output Window

Started by
6 comments, last by Matthew Shockley 13 years, 12 months ago
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.
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Advertisement
Anyone?
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
I know just about everyone in this forum knows more about C++ then me, but no one replies...
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Please... Someone!!
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
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.
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

It returns the HWND of my custom made output window. Its my custom function.
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
"\r\n" works forsome wierd reason. Thanks!
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?

This topic is closed to new replies.

Advertisement