I want to put this code into separate window so that the results are displayed in a custom window not in a command prompt

#include <iostream>
#include <string>

using namespace std;



void main()
{
	system("title Find Mac From IP");
	system("cls && Color DF");
	cout<<"--------------------------------------------------------------------------------\n";
	cout<<"          This Utility is designed to test the client connectivity\n";
	cout<<"                   and get the MAC address of the System \n";
	cout<<"--------------------------------------------------------------------------------\n";
    std::string ip1,ipc1;
    cout<<"Enter the Ip Address:\t ";
    cin >> ip1;
    ip1 = "ping " + ip1;
    system(ip1.c_str());
    ipc1 = "nbtstat -A" + ip1;
	system(ipc1.c_str());
		
}

Edited 6 Years Ago by bijayswain: n/a

I want to put this code into separate window so that the results are displayed in a custom window not in a command prompt

#include <iostream>
#include <string>

using namespace std;



void main()
{
	system("title Find Mac From IP");
	system("cls && Color DF");
	cout<<"--------------------------------------------------------------------------------\n";
	cout<<"          This Utility is designed to test the client connectivity\n";
	cout<<"                   and get the MAC address of the System \n";
	cout<<"--------------------------------------------------------------------------------\n";
    std::string ip1,ipc1;
    cout<<"Enter the Ip Address:\t ";
    cin >> ip1;
    ip1 = "ping " + ip1;
    system(ip1.c_str());
    ipc1 = "nbtstat -A" + ip1;
	system(ipc1.c_str());
	system("prompt $");
	system("shift");
	
}

Well, now you are moving into the Windows API.

Thats a big difference from the console application.

If you are using Visual C++, you could take a look at the template code when creating a Win32 Project.

Alternately, for a very simple application you could use the Windows Forms Application type (also in VC++), which gives easy toolbox for adding labels, textbox, well all those different things you see around in windows.
I usually use the Windows Forms Application for creating tools for other things. Fx a calculator with custom functionality, or a password generator, or a value converter.

It takes some time getting into this Windows (crap) coding, and I know you'll love having to convert stuff :D

Atleast I hope you can get started, or look at something.

std::string ip1,ipc1;
    cout<<"Enter the Ip Address:\t ";
    cin >> ip1;
    ip1 = "ping " + ip1;
    system(ip1.c_str());
    ipc1 = "nbtstat -A" + ip1;
	system(ipc1.c_str());

The above won't work. Why? Think about the value of string ip1. After ip1 = "ping " + ip1" the string is something like "ping 192.1.1.1". Then when you way "nstat -A" + pi1" the string will be "nstat -A ping 192.1.1.1". I doubt that is the intent of what you want. You need to keep the ip address in a different string so that it doesn't change.

system("prompt $");
	system("shift");

C programs are not batch files, and can not be treated like one. The above two lines are fine in batch file but do nothing at all in C programs. In a C program if you want to display the $ symbol then just say this: print("$"); And there is no equivalent of Shift in C programs, other than maybe incrementing an integer.

Edited 6 Years Ago by Ancient Dragon: n/a

Windows only allow one console window to be assigned by one thread.

You may save the output to a file and capture it.

#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
    cout<<"Write to console now.\n"<<flush;
    freopen("C:\\myFile.txt","w+t",stdout); /* Redirect standard output to file. */
    cout<<"Write to file!\n"<<flush; /* REMEMBER "flush" or "endl"! */
    system("ping 127.0.0.1");
    freopen("CONOUT$","w+t",stdout); /* Redirect standard output back to console. */
    cout<<"Write to console again!\n"<<flush;
    return 0;
}

Read the file later in order to print out the result to a window created by yourself later.

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