Returning to Blitz after ExecFile()

Blitz3D Forums/Blitz3D Programming/Returning to Blitz after ExecFile()

napole0n(Posted 2004) [#1]
I'm working on a MAME frontend using Blitz3D, so I want to start MAME from my Blitz3D menu, and automatically return when the user quits MAME, so that he can select a different game or shutdown.

However, whenever I start MAME using the Blitz command ExecFile(command$), control is never returned to the Blitz menu after quitting MAME, but to the Windows desktop instead. It stays minimized on the taskbar and is not activated. This is how I call the program:

Function updateScene()
	If KeyHit(28)
	    
	    ExecFile(mamepath$+mameexe$+" "+mamepath$+rompath$+romtitle$+" "+options$)
	End If
End Function 


Running from the shell or a compiled .exe with or without Debugging on don't seem to matter. Any ideas?


jfk EO-11110(Posted 2004) [#2]
You have to switch to windowed mode before you run an external Exe. If you run it from fullscreen, the blitz app will be paused until it gets focus again. If you run the exe from within a blitz windowed app, the blitz app will continue running in the background as a active thread. There is only one problem: when you switch to windowed mode, all graphics and 3d stuff has to be reloaded since it does reinitialize the grahpics.
switching to windowed mode can be done using:
Graphics3D 400,300,32,2
or
EndGraphics
etc.

Then you could use a userlib to check if the external exe window is still existing on the desktop, and continue the blitz app when the other exe window can't be found anymore.


REDi(Posted 2004) [#3]
I came across the same problem with my mame frontend project, Its quite annoying, but I got around the problem by writing another "launcher app" (with Blitz+), in windowed mode that handles the execution.

1. "Launcher app" executes the "menu app"
2. When a game is selected the "menu app" writes a file containing the required rom and emulator, and then ends.
3. "Launcher app" gets focus and reads file
4. "Launcher app" executes the emulator with selected rom.
5. When the game is finished the focus is passed back to the "Launcher app" which starts back at step 1.

Doing it like that also stops the desktop poping up every time you execute something, just size the window to cover the entire screen :)
BTW you can also use the window as a logo/loading screen!


REDi(Posted 2004) [#4]
Another thought, maybe you could use Blitz3D in windowed mode, with a graphics width/height bigger than the screen, then reposition the window with API commands so that the window frame can't be seen.

Then it should work and give the apperance of full screen mode!

But I'm not too sure if your graphics will still be intact after executing the emulator in fullscreen mode.


napole0n(Posted 2004) [#5]
Windowed is not an option, because the app needs to run at 320x240 so it can be shown on an arcade monitor. With windowed mode, I'll have to use 640x480 at least, which gives me an interlaced display.

Thanks anyway, I think I'll stick with MameWAH or ArcadeOS for now.


jfk EO-11110(Posted 2004) [#6]
Papa Lazarou - I tried to do that, but for some reason a window cannot be bigger than the current resolution - at least in some windows versions. I even tried a code that will hide the window border and then made the inner window to fit the screen size - theoreticly. But windows refused to do that and used to keep a bar reserved. A bar of about the size of the desktop bottom bar with the start button.

NapoleOn - sorry to hear this won't solve your problem. It's tricky, indeed.


REDi(Posted 2004) [#7]
@napoleOn
When I built my arcade machine I didn't use an arcade monitor, because I wanted it to play my own blitz games as well :) (and other PC games)

@jfk
Oh I see, shame it doesn't work with a window bigger than the screen, In my frontend I just did it (with blitz+) like this:

Win = CreateWindow("",0,0,GraphicsWidth(),GraphicsHeight(),Win,0)

works great!


Bot Builder(Posted 2004) [#8]
Well, have you tried scaling windows down to 320x240? then, Right click on the start menu, hit properties, and uncheck keep taskbar ontop of other windows. You might also need to use API commands to move the window about. The real prob is getting windows to 320 by 240.....


Spinduluz(Posted 2004) [#9]
Try this , something I got together some while ago.
It's not tested all that much so don't be suprised if strange things happens =).
But hope it can help you.

;---------------------------------------------------------------
; Exec and wait by Thomas Jansson aka Spindeln
;---------------------------------------------------------------

;---------------------------------------------------------------
; Userlib
;---------------------------------------------------------------

;
;.lib "kernel32.dll"
;
;api_lstrcpy%(bank*,String$):"lstrcpyA"
;api_CreateProcess%(lpAppName%,lpCLine%,lpProcAtt%,lpThreadAtt%,bInhHan%,dwCreFlags%,lpEnv%,lpCurDir%,lpStartInf%,lpProcInf):"CreateProcessA"
;api_WaitForSingleObject%(hHandle,dwMilliseconds):"WaitForSingleObject"
;api_MulDiv%(a*,b%,c%):"MulDiv"
;api_CloseHandle(Handle%):"CloseHandle"
;
;.lib "user32.dll"
;api_FindWindow%(Class%,Title$):"FindWindowA"
;api_ShowWindow%(hWnd%,nCmdShow%):"ShowWindow"
;

;---------------------------------------------------------------
; Windows constants
;---------------------------------------------------------------

Const STARTF_USESHOWWINDOW    		= $00000001
Const CREATE_DEFAULT_ERROR_MODE   	= $04000000
Const SW_HIDE             			= 0
Const SW_SHOW             			= 5
Const INFINITE            			= $FFFFFFFF  ; Infinite timeout

;---------------------------------------------------------------
; Ptr by Koriolis and (or) soja
;---------------------------------------------------------------

Function Ptr%(Bank)

	Return api_MulDiv(Bank,1,1)

End Function 

;---------------------------------------------------------------
; Exec
;---------------------------------------------------------------

Function Exec%(FileName$,CurrentDirectory$)

	If FileName$ = "" Then Return False

	Local STARTUPINFO 		  = CreateBank(68)
	Local PROCESS_INFORMATION = CreateBank(16)
	Local FileNameBank		  = CreateBank(Len(FileName$)) 
	Local FileNameStr         = api_lstrcpy(FileNameBank,FileName$)
	Local CurDirBank		  = 0
	Local CurDirStr			  = 0
	
	If CurrentDirectory$<>"" Then
	
		CurDirBank = CreateBank(Len(CurrentDirectory$))
		CurDirStr  = api_lstrcpy(CurDirBank,CurrentDirectory$)
	
	EndIf
	
	PokeInt(STARTUPINFO,0,BankSize(STARTUPINFO))
	PokeInt(STARTUPINFO,4,0)
	PokeInt(STARTUPINFO,8,0)
	PokeInt(STARTUPINFO,12,0)
	
	PokeInt(STARTUPINFO,16,0)
	PokeInt(STARTUPINFO,20,0)
	PokeInt(STARTUPINFO,24,0)
	PokeInt(STARTUPINFO,28,0)
	PokeInt(STARTUPINFO,32,0)
	PokeInt(STARTUPINFO,36,0)
	PokeInt(STARTUPINFO,40,0)
	PokeInt(STARTUPINFO,44,STARTF_USESHOWWINDOW)
	
	PokeShort(STARTUPINFO,48,SW_SHOW)
	PokeShort(STARTUPINFO,50,0)
	PokeByte(STARTUPINFO,52,0)

	PokeInt(STARTUPINFO,53,0)
	PokeInt(STARTUPINFO,57,0)
	PokeInt(STARTUPINFO,61,0)
	
	If Not api_CreateProcess(0,FileNameStr,0,0,False,CREATE_DEFAULT_ERROR_MODE,0,CurDirStr,Ptr(STARTUPINFO),Ptr(PROCESS_INFORMATION))
		
		If CurDirBank <> 0 Then FreeBank(CurDirBank)
		FreeBank(FileNameBank)
		FreeBank(STARTUPINFO)
		FreeBank(PROCESS_INFORMATION)

		RuntimeError("Could not create process")
		
	EndIf
	
	api_WaitForSingleObject(PeekInt(PROCESS_INFORMATION,0),INFINITE)
	
	api_CloseHandle(PeekInt(PROCESS_INFORMATION,0))
	api_CloseHandle(PeekInt(PROCESS_INFORMATION,4))

	If CurDirBank <> 0 Then FreeBank(CurDirBank)
	FreeBank(FileNameBank)
	FreeBank(STARTUPINFO)
	FreeBank(PROCESS_INFORMATION)

End Function

;---------------------------------------------------------------
; Main
;---------------------------------------------------------------

Const Title$ = "Exec test"

AppTitle(Title$)

Graphics3D(640,480,32)

hWnd = api_FindWindow(0,Title$) 

If hWnd = 0 Then RuntimeError("No blitz handle sucker!")

Camera = CreateCamera()
PositionEntity(Camera,0,0,-5)
Light = CreateLight()
Cube = CreateCube()

While Not KeyDown(1)

	RenderWorld()
	UpdateWorld()
	
	TurnEntity(Cube,1,1,1)
	
	If KeyDown(59) Then 
		api_ShowWindow(hWnd,SW_HIDE)
		Exec("notepad.exe","")
 		api_ShowWindow(hWnd,SW_SHOW)
	EndIf
	
	Text 0,0,"Press F1 to start notepad"
	Text 0,10,"Then close notepad to get back in business"

	Flip()

Wend