0

Possible Duplicate:
Redirecting cout to a console in windows

I've created a child richedit window with CreateWindow and I wonder is it possible to redirect all cout calls so text would appear in RichEdit controll instead of console ?

Community
  • 1
  • 1
rsk82
  • 28,217
  • 50
  • 150
  • 240
  • 2
    @DavidSchwartz, not the same question at all - that one is for redirecting to console, this one is for redirecting to a richedit. – Mark Ransom Jan 14 '13 at 16:52

1 Answers1

0

As far as I know, you can't do that. You need to send window messages to set the text in the control.

That's not to say you can't use stream syntax. You could define your own ostream and use that instead of cout, then pass bytes into your window. It wouldn't help with any output that you don't generate, nor would it help if you mix printf calls (which you shouldn't really do).

paddy
  • 60,864
  • 6
  • 61
  • 103
  • 1
    There are horribly ugly ways if you're desperate enough. You can intercept console I/O and redirect it to a pipe. Then you can read from the other end of the pipe and use that to update your RichEdit control. – David Schwartz Jan 14 '13 at 13:44
  • Sheesh... I don't think I'd be that keen, even just for an exercise! =) Besides, I get the feeling that this is wanted as a replacement for the Console, rather than something to run alongside it. – paddy Jan 14 '13 at 13:46
  • @DavidSchwartz: *iteresting!* have you any code examples how to intercept console I/O. I asked for it several times and people said it is not possible. – rsk82 Jan 14 '13 at 13:47
  • You basically duplicate the write end of a pipe onto the descriptor that was writing to the console. Now all writes to the console will instead go to your pipe. You can then read from the other end of it. (Actually, you may need to hook your own `WriteConsoleA`.) – David Schwartz Jan 14 '13 at 13:47
  • Feeling game enough to turn that into an answer? =) – paddy Jan 14 '13 at 13:49
  • 1
    Never mind. I found [the easy way](http://stackoverflow.com/a/424236/721269) to do it. – David Schwartz Jan 14 '13 at 13:50
  • @paddy: yes, replacement, and my dream is to also intercept other winapi calls for the console like color and colorize richedit output. Console is really ugly it breaks lines, it has no notion of paragraphs and it is not possible to show unicode with it, and text cannot be copied alongside with color information. – rsk82 Jan 14 '13 at 13:51
  • @rsk82, the richedit control isn't really suited to acting like an output window because the update methods are limited. I once wrote a window class which works like Visual Studio's output window, but it was a real pain. There's lots of details I didn't anticipate before I started. – Mark Ransom Jan 14 '13 at 16:55
  • @MarkRansom: it is not suited from programmatical point of view, but is very suitable from wetware perspective. Richedit has paragraphs so you can easily see when line starts and ends if you set `PARAFORMAT` properties to space before and after paragraph. Human visual system is not well suited to monotonous stream of same sized chars like on a checkerboard. – rsk82 Jan 14 '13 at 17:18