I am a beginner with win32 programs, and am trying to integrate my console into a window.

My console program starts a new thread which creates a window.

DWORD dwThreadID = 0;
   HANDLE hThread =  CreateThread(NULL,0,ThreadProc,argv[0],0,&dwThreadID);

i want to create a miniature output textbox within my window, which reads the output of the console and displays it, and im guessing i have to do this in the windows procedure somewhere around here.

case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		break;

ive found the console functions like ReadConsole() and WriteConsole() on MSDN, but im unsure if these are the kind of thing that im looking for, and im not sure if the threads can even communicate with eachother like that, or how it's possible.

Where should i start?

I should point out that i could make a new console from a win32 program, but i dont know how to create the console or where to put the console code, and i have to go back to the original problem of how to get the console text displayed in my window, and how to send strings to the console

call CreateThread() or _beginthread() in WM_CREATE, not WM_PAINT.

Creating a console from GUI is simple -- just call AllocConsole(); Example

void ConsoleThread(void* p)
{
	HANDLE hStdin = 0;
	HANDLE hStdout = 0;
	DWORD dwCharactersWritten = 0;
	if( AllocConsole() == 0)
	{
		return;
	}
	HWND hConsoleWnd = GetConsoleWindow();
	hStdin = GetStdHandle(STD_INPUT_HANDLE);
	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
	while(1)
	{
		WriteConsole(hStdout,"Hello\n",6,&dwCharactersWritten,0);
		Sleep(2000);
	}
}

You can read the characters that are on the console windows by calling win32 api functgion ReadConsoleOutput()

Thanks, yes AllocConsole() makes me a console just fine i see. I cant really understand what the function you gave me does. What do i need to pass to it?

The function I posted would be the thread created by either CreateThread() or _beginthread(). Read the online docs (use google for that) and you will find out what the parameter to the function means. In most cases you can just pass NULL as the parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.