From: Franz Bachler on
Hello,

if I make a system("...") call under C from a GUI-Windows-Program to start
e.g. a console program then the screen flickers. Example:

system("compiler.exe arg1 arg2");

As I've seen from other programs a flicker free call is possible so that it
seems that the called program works in the backgrounds.

How do to that (language C / C++)?

Greetings,
Franz

--
Franz Bachler, A-3250 Wieselburg
E-Mail: fraba (at) gmx.at
Homepage: http://members.aon.at/fraba
oder http://home.pages.at/fraba


From: Friedel Jantzen on
Am Fri, 7 May 2010 08:31:19 +0200 schrieb Franz Bachler:

> Hello,
>
> if I make a system("...") call under C from a GUI-Windows-Program to start
> e.g. a console program then the screen flickers. Example:
>
> system("compiler.exe arg1 arg2");
>
> As I've seen from other programs a flicker free call is possible so that it
> seems that the called program works in the backgrounds.
>
> How do to that (language C / C++)?

Hello Franz!
Try CreateProcess instead, using dwCreationFlags = CREATE_NO_WINDOW;

Regards,
Friedel
From: Ulrich Eckhardt on
Franz Bachler wrote:
> if I make a system("...") call under C from a GUI-Windows-Program to start
> e.g. a console program then the screen flickers. Example:
>
> system("compiler.exe arg1 arg2");
>
> As I've seen from other programs a flicker free call is possible so that
> it seems that the called program works in the backgrounds.
>
> How do to that (language C / C++)?

The compiler uses stdout/stderr, which causes a console window to be created
that you probably perceive as flicker. What you can do is redirect its
standard streams (search for "redirect stream win32") which should remove
the window. Note that there are programs that actually create a console
window explicitly or start to misbehave in some ways when their outputs are
redirected, for those there is little you can do.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: Jonathan de Boyne Pollard on
>
>
> The compiler uses stdout/stderr, which causes a console window to be
> created [...]
>
No. What causes the console window to be created is that the command
interpreter that %COMSPEC% points to is marked as a Windows Character
Mode executable. It cannot be determined ahead of time, i.e. before the
program is launched into a child process, whether a program will use its
standard handles. But the subsystem field in the PE header is available
ahead of time, and that is what is used to determine whether the child
process has a console.

From: Franz Bachler on
Hello all,

the solution is CreateProcess, this doesn't flicker under the NT-Line but it
flickers under 9x. Under 9x WinExec works but WinExec doesn't wait until the
subprocess terminated. Here helps only Sleep() with sufficient delay.

Greetings,
Franz

{
STARTUPINFO si;
PROCESS_INFORMATION pi;
OSVERSIONINFO osvi;
BOOL bS=FALSE;
TCHAR szCommand=TEXT("dosprog argument");

ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);

// Start the child process.
if (osvi.dwMajorVersion>=5)
{
bS=CreateProcess
(
NULL, // No module name (use command line)
szCommand, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
CREATE_NO_WINDOW, // Creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
);
}

if (bS)
{
WaitForSingleObject(pi.hProcess, INFINITE);

// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else
{
WinExec(szHelp, SW_HIDE);
Sleep(650);
}
}