FLTK logo

Re: [fltk.general] Use worker thread to call Fl_Window and Fl_run

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Use worker thread to call Fl_Window and Fl_run Greg Ercolano Oct 01, 2020  
 
> Any suggestions to force this window to the top of all other windows? My GUI (code that I cannot change) may be pushing a cmd window to the top as I am using popen/pclose and windows starts a cmd window when you use pipes.

	You won't have luck using popen() on windows, it's a very weak implementation.

	It's best to reimplement its functionality using a combo of WIN32 API functions
	CreatePipe() to create the in & out pipes, and assign those to STARTUPINFO
	as the hStdInput and hStdOutput/hStdError members, and then pass the STARTUPINFO
	to CreateProcess().

	It's a bit of work to do so, but I've found it to work reliably, and no DOS window.

--- snip
    PROCESS_INFORMATION pi;
    memset(&pi, 0, sizeof(pi));

    [..]

    HANDLE stdinReadPipe  = 0;
    HANDLE stdinWritePipe = 0;
    if ( CreatePipe(&stdinReadPipe, &stdinWritePipe, &sa, 0) == 0 ) { ..error.. }

    HANDLE stdoutReadPipe  = 0;
    HANDLE stdoutWritePipe = 0;
    if ( CreatePipe(&stdoutReadPipe, &stdoutWritePipe, &sa, 0) == 0 ) { ..error.. }

    STARTUPINFO si;
    memset(&si, 0, sizeof(si));
    si.cb          = sizeof(si);
    si.dwFlags     = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
    si.wShowWindow = SW_HIDE;          // <-- yoo hoo
    si.hStdInput   = stdinReadPipe;
    si.hStdOutput  = stdoutWritePipe;
    si.hStdError   = stdoutWritePipe;

    [..]

    if (CreateProcess(NULL,                     // app name
                      (char*)cmd,               // command to exec
                      NULL,                     // proc secure attribs
                      NULL,                     // thread secure attribs
                      TRUE,                     // handle inheritence
                      CREATE_NEW_PROCESS_GROUP, // creation flags
                      NULL,                     // environ block
                      NULL,                     // current dir
                      &si,                      // startup info
                      &pi))                     // process info
    {
        // OK - Parent: close pipes we're not interested in.
        //      Only interested in stdoutReadPipe to get stdout/err from child.
        //
        if ( stdinReadPipe   != 0 ) { CloseHandle(stdinReadPipe); stdinReadPipe = 0; fdstdin = 0; }     // fdstdin + stdinReadPipe same
        if ( stdinWritePipe  != 0 ) { CloseHandle(stdinWritePipe);  stdinWritePipe  = 0; }
        if ( stdoutWritePipe != 0 ) { CloseHandle(stdoutWritePipe); stdoutWritePipe = 0; }

        [..]
    }
    else
    {
        ..error..
        if ( stdinReadPipe   != 0 ) { CloseHandle(stdinReadPipe);   stdinReadPipe   = 0; }
        if ( stdinWritePipe  != 0 ) { CloseHandle(stdinWritePipe);  stdinWritePipe  = 0; }
        if ( stdoutWritePipe != 0 ) { CloseHandle(stdoutWritePipe); stdoutWritePipe = 0; }
    }

--- snip

-- 
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/5660329b-d97a-afeb-e8cd-5fd4e978bcd5%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.