Ok so ive written a console program which is great, and now i want to create a thread that makes a window (winAPI) and can commuunicate with the console window. Well to describe it properly, i would like the window thread to send predetermined text (by clicking buttons) to the console when the console waits for consin, and i would like the console to send all of its cout to the window thread to be displayed somewhere.

Ive never used the winAPI before, and have a very limited idea of how it works. The first thing my main function does is this-

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

Which creates my window thread, then it goes on to execute the console code. I am lost as to where to start. I know where my message loop and windows procedure is (its in a different source file), but ive no idea where to start to get to where i want to go. Could anyone give me a nudge in the right direction?

Are you using Visual Studio? If you are, its wizard will start you out in a number of useful different places. If you don't have Visual Studio try finding some other commercial or open source product that has a wizard.

My suggestion is create a plain windows application, and use the Windows API to open and close a console. I'm attaching a sample WinMain application as a starting place.

Within this very sparse framework, you can create a Dialog resource and the necessary code to get that launched within the initial Windows frame.

There are also other wizards that generate MFC applications as well.

I also suggest getting hold of documentation for the Windows API and look into using the console API.

Attachments
// example.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.

	return 0;
}
========================================================================
       WIN32 APPLICATION : example
========================================================================


AppWizard has created this example application for you.  

This file contains a summary of what you will find in each of the files that
make up your example application.

example.cpp
    This is the main application source file.

example.dsp
    This file (the project file) contains information at the project level and
    is used to build a single project or subproject. Other users can share the
    project (.dsp) file, but they should export the makefiles locally.
	

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
    These files are used to build a precompiled header (PCH) file
    named example.pch and a precompiled types file named StdAfx.obj.


/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.


/////////////////////////////////////////////////////////////////////////////
// stdafx.cpp : source file that includes just the standard includes
//	example.pch will be the pre-compiled header
//	stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers

#include <windows.h>


// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

My problem is that i have already started my program, and it is fairly big now and compiles correctly and everything,

#include "stdafx.h"
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <map>
#include <Windows.h>
#include <fstream>
#include <complex>
#include "proto.h"
#include "ftp.cpp"
using std::string;
using std::stringstream;
using std::cin;
using std::cout;

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{

    HMODULE hInstance = GetModuleHandle( (char *)lpParameter);
    _tWinMain(hInstance,NULL,(char *)lpParameter,SW_SHOW);
    return 0;
}

int main(int argc, char* argv[])
{
    DWORD dwThreadID = 0;
    HANDLE hThread =  CreateThread(NULL,0,ThreadProc,argv[0],0,&dwThreadID);/* i assume this creates the window thread*/

//Console continues here
return 0;
}

Would it be easier to use the winapi to open and close the console? how could i switch around my code to do this? And then we go back to the original problem of where do i start to get the window to send preset data to the console?

This article has been dead for over six months. Start a new discussion instead.