New Console Window

This is a discussion on New Console Window within the C++ Programming forums, part of the General Programming Boards category; I am currently working on an 'ecosystem' program in console. It is going well all except for one thing... I ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    New Console Window

    I am currently working on an 'ecosystem' program in console.

    It is going well all except for one thing...

    I would like it if when the user pressed a predefined key a new console window/program would pop up and would scroll through the information/statistics of the other program.

    Pulling information from the other program should be easy enough with the usual file i/o, but how do I get a new window to pop up?

    Btw I am using Microsoft Visual C++ 6.0

    Not sure if this is doable, but one can always dream
    MSVC++~

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Just to be clear, as far as I know, each win32 program can only have one console window at any given time... although, you can have as many 'real' windows as you want.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    You could also go "low-tech" with system().

    gg

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    Man that CreateProcess deal is totally raping me...

    so many offshoots...and of course MSDN always has a nice way of explaining everything ;P

    but ill get it...it will just take me a while and quite a few tries...

    but thanks!

  6. #6
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    If this is any help, here's some code to start and stop a process.
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    HANDLE StartProcess(char *sExe)
    {
    	BOOLEAN bResult = FALSE;
    	STARTUPINFO SI;
    	PROCESS_INFORMATION pi;
    
    	SI.cb = sizeof(STARTUPINFO); 
    	SI.lpReserved = NULL;
    	SI.lpDesktop=NULL;
    	SI.lpTitle = (char*) sExe;
    	SI.dwX = 400;
    	SI.dwY = 200;
    	SI.cbReserved2=0;
    	SI.lpReserved2=NULL;
    	SI.dwFlags= STARTF_USEPOSITION;
    	SI.wShowWindow=SW_SHOWNORMAL;   
    	SI.hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
    	SI.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
    	SI.hStdError=GetStdHandle(STD_ERROR_HANDLE);
    
    	bResult = CreateProcess ((LPTSTR)sExe,	        
    						(LPTSTR)NULL,				
    						(LPSECURITY_ATTRIBUTES)NULL,
    						(LPSECURITY_ATTRIBUTES)NULL,
    						(BOOL) TRUE,				
    						(DWORD) CREATE_NEW_CONSOLE, 
                            GetEnvironmentStrings(),	
    						NULL,						
    						(LPSTARTUPINFO)&SI,			
    						(LPPROCESS_INFORMATION)&pi	
    						);
    	return pi.hProcess;
    }
    
    int main()
    {
    	HANDLE h;
    
    	printf("Starting process\n");
    	Sleep(1000);
    
    	if( h = StartProcess("test2.exe") )
    	{
    		printf("Process started\n");
    		Sleep(5000);
    		TerminateProcess(h, 0);
    		printf("process terminated\n");
    	}
    	else
    		printf("Failed to start process\n");
    
    	return 0;
    }

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    Oh yea that helps alot

    cept one thing that doesnt compute...is the
    Code:
    CreateProcess ((LPTSTR)sExe
    what is sExe?

    I guess I can run about looking for it...

    Thanks for all of the other stuff though, it really helps having a template to compare to.

  8. #8
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    >what is sExe?
    just the string of the filename past to the StartProcess() function. StartProcess(char *sExe)

    You could just pass the filename directly the CreateProcess() function instead.
    Code:
    CreateProcess ((LPTSTR) "Test2.exe",

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    Learning how to use CreateProcess() is good and all, but if you're simply going to use file I/O to communicate between the processes, system() is alot easier to call/use.

    gg

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    Yea im sure system is alot easier...but Im not really programming the ecosystem just to do it...its so I can learn as much as possible. So CreateProcess is probably the way to go.

    Thanks for all the help~

  11. #11
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    While you're learning, there's a "mid-tech" solution as well.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Window opening with Console Window
    By carrotcake1029 in forum Windows Programming
    Replies: 2
    Last Post: 12-23-2008, 02:32 PM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 02:22 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  4. win32 apps compiled with GCC start console window!
    By Citrus538 in forum Windows Programming
    Replies: 5
    Last Post: 02-18-2002, 09:35 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21