Opening New Window

May 7, 2008 at 12:23am
Hello, I am making a program where I want to open multiple windows and enter text and continue the program in it.

system("start")

Opens a new window, but how do I type and how do I enter more text into that window.

Thanks,
Cdo.
May 7, 2008 at 12:37am
You want your program to open another "cmd" window (on Windows I'm assuming) and then continue execution in this?

May 7, 2008 at 1:26am
yeh that is correct
May 7, 2008 at 8:21pm
this is not possible, isnt it?... as far as i know - kick me if im wrong - u can write in the window by using a windows window handle for it... but this is part of the windows programming, i think^^...
May 7, 2008 at 8:44pm
Well. The main problem that is associated with this is that you are assuming your program is going to be run in an environment where this is possible.

What if I loaded up DOS or booted to a command-line to run this? Then it wouldn't be able to do it.

Execution will always stay within your code. But I am sure you could redirect the output to another window you have opened. I don't think opening it with system("start") is the correct method.

I don't see what this would actually accomplish though? Whats the point in doing this?
May 7, 2008 at 8:59pm
My point of doing this is that I am working on a program that has multiple menus and I don't want it to all run in one window like I have the main menu, and then from each of those send it to another function and I want it to pop up the window to run the other function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//Pizza.cpp
//Created and Editted on May 7th, 2008

#include <iostream>
#include <iomanip>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::string;

string menu();
void recieved(float [], string []);
void inventory(float [], int, string [], int);
void used(float [], string []);
void convert();

string procede = "";

string menu()
{
	char choice = 'a';
	string type = "";
	//Purpose: To show the menu so the user can show
	//Recieves: Nothing
	//Returns: Nothing
	
	cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~          The Restraunt of Hashbrowns and Pizza          ~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "                                                           " << endl
		<< "::::::::::::::::::::::INSTRUCTIONS:::::::::::::::::::::::::" << endl
		<< "                                                           " << endl
		<< "            Please Enter the Letter of The Menu            " << endl
		<< "                                                           " << endl
		<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl
		<< "~~              a) Inventory Display                     ~~ " << endl
		<< "~~              b) Orders Recieved                       ~~" << endl
		<< "~~              c) Quantity Used                         ~~" << endl
		<< "~~              d) Conversions                           ~~" << endl
		<< ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl
		<< "Please enter a letter of your choice [a,b,c,d]: ";
	cin >> choice;
	cin.ignore(256,'\n');

	switch (choice)
	{
		case 'a':
		case 'A':
			type = "inventory";
			break;
		case 'b':
		case 'B':
			type = "recieved";
			break;
		case 'c':
		case 'C':
			type = "used";
			break;
		case 'd':
		case 'D':
			type = "convert";
			break;
		default:
			system("cls");
			cout << " You have not entered a valid choice! " << endl << endl;
			precede = menu();
	}
	return type;
}

void inventory(float amount[], int amountSize, string food[], int foodSize)
{
	system("cls");
	cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~               The Restraunt of Hashbrowns and Pizza              ~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
	cout << "#####################################################################" << endl
		<< "########                   The Inventory                     ########" << endl
		<< "#####################################################################" << endl << endl
		<< "* There are: " << endl << endl;
	for (int count = 0; count < 10; count++)
	{
		cout << amount[count] << " " << food[count] << endl;
	}

}
void used()
{
	cout << "USED PROCEDURE" << endl;
}
void recieved(float amount[], string food[])
{
	int chooseNum  = 0;
	cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~               The Restraunt of Hashbrowns and Pizza              ~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl
		<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
	cout << "####################################################################" << endl
		<< "#######             Supplies Recieved [BOXES]                #######" << endl
		<< "####################################################################" << endl << endl
		<< "Please choose an option to update: " << endl;
	for (int count = 0; count < 10; count++)
	{
		chooseNum = count + 1;
		cout << chooseNum << ") " << food[count] << " has " << amount[count] << " of boxes." << endl;
	}
	cout << "Please enter a number: ";
	cin >> chooseNum;
	cin.ignore(256,'\n');
	
	switch (chooseNum)
	{
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
		case 9:
		case 10:
			cout << "Please enter the number of boxes for " << food[(chooseNum-1)] <<" : ";
			cin >> amount[(chooseNum-1)];
			cin.ignore(256,'\n');
			break;
		default:
			system("cls");
			cout << "Please enter a correct option! You have been redirected to the main menu to retry.";
			precede = menu();
	}
	system("cls");
	cout << "The new updated inventory is: " << endl;
	for (int count = 0; count < 10; count++)
	{
		chooseNum = count + 1;
		cout << chooseNum << ") " << food[count] << " has " << amount[count] << " of boxes." << endl;
	}
	system("pause");
	

	//cout << "RECIEVED PROCEDURE" << endl;
}
void convert()
{
	cout << "CONVERT PROCEDURE" << endl;
}


int main()
{
	//Declare the Variables
	string names[10] = {"Pepperoni","Italian Sausage","Bacon","Green Pepper","Onion","Green Olives","Mushrooms","Pizza Sauce","Dough","Cheese"};
	float quantity[10];
	int convert [10];
	string procede = "";
	cin.ignore(256,'\n');
	for (int loop = 0; loop < 10; loop++)
	{
		quantity[loop] = 0.0;
	}
	for (int loop2 = 0; loop2 < 10; loop2++)
	{
		convert[loop2] = 0;
	}

	//Tell the user what is going to happen
	cout << "This program will track the inventory of the pizza company." << endl;
	procede = menu();
	//system("pause");
	if (procede == "inventory")
	{
		inventory(quantity, 10, names, 10);
	}
	else if (procede == "used")
	{

	}
	else if (procede == "recieved")
	{
		recieved(quantity, names);
	}
	else
	{

	}
	//system("cls");
	system("pause");

	return 0;
}


It is just in progress, that is the only thing I need help with. I am just displaying the contents in the main window for now.
May 7, 2008 at 9:28pm
Ok.

This is how I believe it can be done.

1) Create a new process from your application using a threading/process API. Win32API it's CreateProcess()

2) Using the handle to your process, acquire a handle to the window that was created.

3) Send messages to this window that corresponding with writing out to the window etc. This will involve inter-process communication. (e.g OpenMPI, TCP etc).

That is assuming it's a console app. Which judging by your code it most definitely is. Consoles are not designed to open and write to other ones easily. You have to remember they were developed before we had Explorer (Windows) and you couldn't swap between them.

you best bet is to clear the screen between each menu, and re-write it when required.


Topic archived. No new replies allowed.