Reputation: 2697
I'm creating a new process which calls a console application. I want to change the colors of this child process's console window.
The reason is that I can't redirect the console's stdout because the application manipulates the console cursor. Instead I'm stripping the console frame, clipping the info I want and embed the console in my application wholesale. I just want to change the colors so it fits in better.
I know of the SetConsoleTextAttribute
function but I don't know how to get to the stdout handle of the child process to use it.
Anyone have any ideas?
Upvotes: 0
Views: 546
Reputation: 101756
The documentation for DuplicateHandle says:
Console handles can be duplicated for use only in the same process
(They are not real handles) so even if you could inject code into the child you could not go down this route.
I'm assuming the parent application does not already have a console (You can only have one per process without doing horrible hacks), if that is the case you should be able to use AllocConsole()
, GetStdHandle()
, SetConsoleTextAttribute()
, CreateProcess()
and finally FreeConsole()
(You don't need FreeConsole if you only run one child process at the time)
The other option is to use cmd.exe: cmd.exe /T:?? /C childapplication.exe
(Replace ?? with the color values you find by running color /?
in cmd)
Upvotes: 2