Discussion Locked

VC ++ Application Console

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am building a console based application using VC++ 6.0. I need to get the handle to the console window. Is there any way i can get a handle to output console window?

3 replies

by peter ritchie

There are many handles dealing with the "console window". The correct answer relates to what you want to do with the console window.

If you want to control the console (as a "window" then you'll need the handle received from the GetConsoleWindow() Win32 API function. This returns the console window's window handle. One caveat: this funiton is not defined in any of the Visual C++ headers. You'll have to prototype it yourself in order to use it, for example:
#include
HWND GetConsoleWindow(VOID);
void main(void){
HWND hwnd = ::GetConsoleWindow();
}
More info: http://msdn.microsoft.com/library/psdk/winbase/conchar_3eif.htm

If you're looking for one of the standard input/output handles and to output/input text to/from the console window you can do that with one of several handles. These handles can be retrieved with the function GetStdHandle(nStdHandle) with the following values for nStdHandle: STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE. Redirection can be accomplished with the SetStdHandle() function. Check out http://msdn.microsoft.com/library/psdk/winbase/conchar_7k9x.htm and http://msdn.microsoft.com/library/psdk/winbase/conchar_7y79.htm

This discussion is closed to new replies.