-
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 ;)
-
-
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.
-
You could also go "low-tech" with system().
gg
-
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!
-
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;
}
-
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.
-
>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",
-
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
-
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~
-
While you're learning, there's a "mid-tech" solution as well.
gg