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?

Recommended Answers

All 4 Replies

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.

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?

Yes, use winapi to open and close the console. I've forgotten what the calls are.

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.