Sver
Full Member
Posts: 145
|
Post by Sver on Oct 15, 2020 4:10:34 GMT -5
Snippet
'Run an external program from within an LB program and wait until the program has finished before continuing the LB program.
filedialog "Open","*.*",file$ if file$="" then end SEEMASKNOCLOSEPROCESS = 64 '0x40 Struct s, cbSize as ulong, fMask as ulong, hwnd as ulong,_ lpVerb$ as ptr, lpFile$ as ptr, lpParameters$ as ptr ,_ lpDirectory$ as ptr, nShow as long, hInstApp as ulong,_ lpIDList as long, lpClass as long, hkeyClass as ulong,_ dwHotKey as ulong, hIcon as ulong, hProcess as ulong s.cbSize.struct=len(s.struct) s.fMask.struct=SEEMASKNOCLOSEPROCESS s.hwnd.struct=0 s.lpVerb$.struct="Open" s.lpFile$.struct=file$ s.lpParameters$.struct="" s.lpDirectory$.struct=DefaultDir$ s.nShow.struct=_SW_RESTORE calldll #shell32 , "ShellExecuteExA",s as struct,r as long if r<>0 then hProcess=s.hProcess.struct else print "Error." end end if waitResult=-1 while waitResult<>0 calldll #kernel32, "WaitForSingleObject",_ hProcess as long,0 as long,_ waitResult as long wend print "Launched process has ended" END
|
|
|
Post by 1180michel on Mar 6, 2021 8:35:10 GMT -5
If this can help, here is a self-made function "runx" (for Run eXternal) in wich : file$=complete name of the file to be executed par$=parameters of the program to be executed (can be "") hide=1 : hide program during execution (0 if show) waitend=1 : wait the program to be terminated (0=don't wait)
Hope can help !
function runx(file$,par$,hide,waitend) Struct s, cbSize as ulong, fMask as ulong, hwnd as ulong,_ lpVerb$ as ptr, lpFile$ as ptr, lpParameters$ as ptr ,_ lpDirectory$ as ptr, nShow as long, hInstApp as ulong,_ lpIDList as long, lpClass as long, hkeyClass as ulong,_ dwHotKey as ulong, hIcon as ulong, hProcess as ulong s.cbSize.struct=len(s.struct) s.fMask.struct=64 'SEEMASKNOCLOSEPROCESS s.hwnd.struct=0 s.lpVerb$.struct="Open" s.lpDirectory$.struct=DefaultDir$ s.lpFile$.struct=file$ s.lpParameters$.struct=par$ if hide=0 then s.nShow.struct=_SW_MAXIMIZE else s.nShow.struct=_SW_HIDE runx=0 'http://www.vb-helper.com/howto_shellexecute.html calldll #shell32,"ShellExecuteExA",s as struct,r as long if r<>0 then hProcess=s.hProcess.struct else exit function end if
if waitend=1 then waitResult=-1 while waitResult<>0 calldll #kernel32, "WaitForSingleObject",_ hProcess as long,0 as long,_ waitResult as long wend end if
runx=hProcess end function
|
|