March 05, 2021, 07:40:46 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Like stats
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bmx] Run program (Windows-only) by BlitzSupport [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Run program (Windows-only) by BlitzSupport [ 1+ years ago ] (Read 1034 times)
BlitzBot
Jr. Member
Posts: 1
Total likes: 0
[bmx] Run program (Windows-only) by BlitzSupport [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:42 AM »
Title :
Run program (Windows-only)
Author :
BlitzSupport
Posted :
1+ years ago
Description :
This gives a little more control over launching graphical applications on Windows than other methods available, eg. OpenURL, system_, CreateProcess, etc.
(Whether or not the minimise/maximise/hide flags have any effect depends on the program, though most should work correctly; the one I actually intended this for, Google Chrome, basically ignores all of the SW_SHOW parameters!)
Code :
Code: BlitzMax
?Win32
' See http://msdn.microsoft.com/en-gb/library/windows/desktop/bb762153(v=vs.85).aspx
' for explanation of each constant...
Const
SW_HIDE =
0
Const
SW_SHOWNORMAL =
1
Const
SW_SHOWMINIMIZED =
2
Const
SW_SHOWMAXIMIZED =
3
Const
SW_MAXIMIZE =
3
' No idea why this duplicate exists...
Const
SW_SHOWNOACTIVATE =
4
Const
SW_SHOW =
5
Const
SW_MINIMIZE =
6
Const
SW_SHOWMINNOACTIVE =
7
Const
SW_SHOWNA =
8
Const
SW_RESTORE =
9
Const
SW_SHOWDEFAULT =
10
Extern
"win32"
Function
ShellExecuteA
(
window:
Int
, op:
Byte
Ptr
, file:
Byte
Ptr
, params:
Byte
Ptr
, dir:
Byte
Ptr
, show:
Int
)
End
Extern
' RunProgram parameters: exe = path to executable file, params = valid parameters for executable, showflag = one of the above constants, dir = working directory for program
Function
RunProgram:
Int
(
exe:
String
, params:
String
=
""
, showflag:
Int
= SW_SHOWNORMAL, dir:
String
=
""
)
If
dir =
""
Then
dir = ExtractDir
(
exe
)
Print dir
If
ShellExecuteA
(
0
,
"open"
.ToCString
(
)
, exe.ToCString
(
)
, params.ToCString
(
)
, dir, showflag
)
>
32
Return
True
Else
Return
False
EndIf
End
Function
?
' Run one instance maximised, one minimised and one normal...
RunProgram
"notepad.exe"
,
""
, SW_SHOWMAXIMIZED
Delay
500
RunProgram
"notepad.exe"
,
""
, SW_SHOWMINIMIZED
Delay
500
RunProgram
"notepad.exe"
' You can also run programs "hidden"; if you try this, you'll have to use Task Manager to kill notepad.exe afterwards!
' RunProgram "notepad.exe", "", SW_HIDE
' NB. Notepad is normally in the default Windows path, hence no need to provide the full path in this case; however, most programs will need the full path to the executable.
Comments :
Henri(Posted 1+ years ago)
Hi,I'm wondering how would this work when used in "batch mode". For example you have a commandline program that modifies files or creates something according to program parameters and you would use ShellExecute to run this program 1000 times in a row. Would each start as it's own process and then you might run out of resources ? Would there be a way to wait (not freeze program flow) until process ends ?-Henri
BlitzSupport(Posted 1+ years ago)
I only just saw this, sorry! You can force each call to wait until the program exits by amending the code to use <a href="
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762154(v=vs.85).aspx
" target="_blank">ShellExecuteEx[/url]. There's a 'no async' flag that can be set to do this.
Henri(Posted 1+ years ago)
Better late then never ;-)
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bmx] Run program (Windows-only) by BlitzSupport [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal