Re: How To Use wxShell or wxExecute Without Opening A Console Window

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

I'm using the 'start' command in Windows. That might be the culprit.

I assume you're using something like cmd.exe /C start <filename> to start the default application for a file and you're running your app with euiw.exe.

Running cmd.exe requires a console window, and since euiw.exe doesn't have one already, a new one gets created. The solution there is to not run cmd.exe to "start" a file.

...but wxExecute uses CreateProcess which only is for starting executables and you need to use ShellExecute which can launch a file into its default app.

...but wxEuphoria "classic" is based on wxWidgets 2.8 which does not have any such function. Starting with 2.9 they added wxLaunchDefaultApplication and that does use ShellExecute.

So I guess we need to write our own wxLaunchDefaultApplication which, peeking at the wxWidgets source code for Windows and Linux, is pretty simple. This version is further simplified.

include wxeu/wxeud.e 
 
ifdef LINUX then 
    include std/filesys.e 
    constant XDG_OPEN = locate_file("xdg-open",getenv("PATH")) 
elsifdef WINDOWS then 
    include std/dll.e 
    include std/machine.e 
    constant SW_SHOWDEFAULT = 10, shell32 = open_dll("shell32.dll"), 
        xShellExecute = define_c_func(shell32,"ShellExecuteA",{C_HANDLE, 
        C_POINTER,C_POINTER,C_POINTER,C_POINTER,C_INT},C_HANDLE) 
end ifdef 
 
public function wxLaunchDefaultApplication( sequence document ) 
ifdef LINUX then 
    if wx_execute(XDG_OPEN & ' ' & document) then 
        return wxTrue 
    end if 
elsifdef WINDOWS then 
    atom lpFile = allocate_string(document,1) 
    integer nShowCmd = SW_SHOWDEFAULT 
    if c_func(xShellExecute,{0,0,lpFile,0,0,nShowCmd}) > 32 then 
        return wxTrue 
    end if 
end ifdef 
    return wxFalse 
end function 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu