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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    8

    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. ( a microcontroller is sending the number and ENTER and I can't select on the command prompt for the microcontroller).

    Here is my program:

    Code:
    #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 by +K.Flynn+; 07-13-2011 at 12:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to do not pop up the command prompt?
    By ZaC in forum C Programming
    Replies: 4
    Last Post: 06-30-2009, 04:58 AM
  2. Command Prompt
    By Trafalgar Law in forum Tech Board
    Replies: 3
    Last Post: 10-09-2008, 06:00 PM
  3. command prompt++
    By l2u in forum Tech Board
    Replies: 13
    Last Post: 04-29-2007, 12:21 AM
  4. Command Prompt here
    By Salem in forum Tech Board
    Replies: 0
    Last Post: 04-11-2005, 11:10 AM
  5. No command prompt please!
    By Lurker in forum Windows Programming
    Replies: 3
    Last Post: 03-07-2003, 04:00 PM

Tags for this Thread