How to get command prompt to close and reopen after 5 seconds.

Hello,

I hope you are having a good day and thank you for taking the time to help me.

I am trying to write a program that opens a command prompt, waits for a number and ENTER then displays a picture then the command prompt closes, waits 5 seconds and then reopens the command prompt and repeats.

The problem is that I can't get the command prompt to close even though I have
system("exit"); in my program.

The reason why I need the command prompt to reopen is because I don't have the ability to select it (clink on it) before I enter the number and ENTER(it is now lower on the Z order). ( a microcontroller is sending the number and ENTER and I can't select on the command prompt for the microcontroller). In other words, without the command prompt closing and opening back up again( to get back on top of the Z order), the microcontroller won't be able to input the number and ENTER so that the program will be able to display another picture.

How do I get my command prompt to stay on top of the Z order? <- This will solve the problem.
~or~
How do I close and re-open the command prompt so that it gets back on top of the Z order after the picture is displayed? <-This could also potentially solve the problem.


Here is my program:

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

#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std; 
int main(void)
{
	while(true)
        {
	        int i;  
	        cout << "READY FOR INPUT: \n";
	        cin  >> i;
		if(i==0)
		{
			system("exit");
			HINSTANCE hInst = ShellExecute(NULL,"open","explorer","C:\\one.png",0,SW_SHOWMAXIMIZED);
			Sleep(5);
		}
		if(i==1)
		{
			system("exit");
			HINSTANCE hInst = ShellExecute(NULL,"open","explorer","C:\\two.png",0,SW_SHOWMAXIMIZED);
			Sleep(5);
		}
		if(i==2)
		{
			system("exit");
			HINSTANCE hInst = ShellExecute(NULL,"open","explorer","C:\\three.png",0,SW_SHOWMAXIMIZED);
			Sleep(5);

		}
		if(i==3)
		{
			system("exit");
			HINSTANCE hInst = ShellExecute(NULL,"open","explorer","C:\\four.png",0,SW_SHOWMAXIMIZED);
			Sleep(5);
		}
	}
}


My computer info:
64-bit Dell running Windows 7 OS.
Eventually, I am thinking of making an array when the number entered is the offset of the ShellExecute() command but that will come later.
Last edited on
Topic archived. No new replies allowed.