Help, mGalaxy stays on top??

Get answers to questions about using mGalaxy.
Post Reply
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Hello, first of all I realy love this program! Thanx!

The problem I encounterd is after launching some pc game mGalaxy stays open.
The game does start and I can hear the sounds of the running game.
With alt-tab and select the running game it stays in the background.
I must close mGalaxy to be able to play the game.

I hope this can be fixed somehow  :D  (sorry for the bad english)

Greets PP
Aeliss
Hero Member
Hero Member
Posts: 900
Joined: Thu Apr 04, 2013 5:55 pm

Try with kind of script to test.

Code: Select all

    ;Parsing
    Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
    local $app = StringLeft ( $CmdLineRaw, $count + 4 )
    local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
    if not $command then exit 0
       
    $PID = Run ('"' & $app & '" ' & $command)
     
    while _WinWaitActivePID($PID)
       sleep(500)
    wend
     
   WinSetState(_GetHwndFromPID($PID),"",@SW_SHOW)
     

While ProcessExists ( $PID )
   sleep(500)
WEnd

    Exit 0
     
    ;functions

     Func _WinWaitActivePID($iPid)
        While 1
            Local $list = WinList()
            For $i = 1 To $list[0][0]
                If $list[$i][0] <> "" And IsVisible($list[$i][1]) Then
                    If WinGetProcess($list[$i][1]) = $iPid AND WinActive($list[$i][1]) Then Return $list[$i][0]
                EndIf
            Next
        WEnd
    EndFunc
     
    Func IsVisible($handle)
        If BitAND(WinGetState($handle), 2) Then
            Return 1
        Else
            Return 0
        EndIf
    EndFunc


Func _GetHwndFromPID($PID)
	$hWnd = 0
	$winlist = WinList()
	Do
		For $i = 1 To $winlist[0][0]
			If $winlist[$i][0] <> "" Then
				$iPID2 = WinGetProcess($winlist[$i][1])
				If $iPID2 = $PID Then
					$hWnd = $winlist[$i][1]
					ExitLoop
				EndIf
			EndIf
		Next
	Until $hWnd <> 0
	Return $hWnd
EndFunc;==>_GetHwndFromPID

Last edited by Aeliss on Wed Oct 09, 2013 5:35 pm, edited 1 time in total.
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Hi, thanx for the response.

So I copied the code and compiled it with AutoIt(x86)
Its now "AutoIt.exe", i placed it in the system32 folder (pc games direct to cmd.exe)

Still the same.. Am I doing it right?  ???
User avatar
mgalaxy
Administrator
Administrator
Posts: 1190
Joined: Tue Dec 05, 2006 7:46 pm

1) Compile the script
2) Name it "mGalaxy_Script.exe"
3) Put it in the same folder than the application (in your case C:\Windows\System32 or any other folder where you should have copy/paste "cmd.exe" application)
4) In mGalaxy_Runway, verify that, for the chosen system, "Use script file.." is checked.
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

YES!!

Thanx for the help, it works perfect now.

Greets PP  8)
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Oeps, I was to fast.

When closing the game, its stuck, like the script is endless loop.

I checked task manager and the mGalaxy_Script.exe is taking much cpu usage.

I had to end the task for getting the mGalaxy window back.
Aeliss
Hero Member
Hero Member
Posts: 900
Joined: Thu Apr 04, 2013 5:55 pm

Yep sorry was my fault, there was an infinite loop, try this version

Code: Select all

;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0

;Get more info
$count = StringInStr($command, '"', 0 , 1, 1)
local $link = StringTrimLeft ( $command, $count  )
$link = StringTrimRight ( $link, 1 )
Local $aDetails = FileGetShortcut($link)
If @error Then exit
local $tmp = StringSplit($aDetails[0], "\")
local $apptorun = $tmp[$tmp[0]]

;run command
$PID = Run ('"' & $app & '" ' & $command)

;wait for application launched
While not(ProcessExists($apptorun))
   sleep(500)
WEnd

;try to put in front
WinSetState(_GetHwndFromPID($apptorun),"",@SW_SHOW)

;wait for close
While ProcessExists($apptorun)
   sleep(500)
WEnd

;try to resolve bug
;while not(WinActive("mGalaxy.exe"))
;   WinActivate("mGalaxy.exe","")
;   sleep(100)
;wend

;WinActivate("mGalaxy.exe","")
;WinSetState("mGalaxy.exe","",@SW_SHOW)


Exit 0





;functions
 
Func _WinWaitActivePID($iPid)
   While 1
       Local $list = WinList()
       For $i = 1 To $list[0][0]
           If $list[$i][0] <> "" And IsVisible($list[$i][1]) Then
               If WinGetProcess($list[$i][1]) = $iPid AND WinActive($list[$i][1]) Then Return $list[$i][0]
           EndIf
       Next
   WEnd
EndFunc
     
    Func IsVisible($handle)
        If BitAND(WinGetState($handle), 2) Then
            Return 1
        Else
            Return 0
        EndIf
    EndFunc
 
 
Func _GetHwndFromPID($PID)
        $hWnd = 0
        $winlist = WinList()
        ;Do
                For $i = 1 To $winlist[0][0]
                        If $winlist[$i][0] <> "" Then
                                $iPID2 = WinGetProcess($winlist[$i][1])
                                If $iPID2 = $PID Then
                                        $hWnd = $winlist[$i][1]
                                        ;ExitLoop
                                EndIf
                        EndIf
                Next
        ;Until $hWnd <> 0
        Return $hWnd
EndFunc;==>_GetHwndFromPID
This version is just a beta, sorry, but not enought time to finish it this night, I need to make something to prevent mGalaxy to stay behind when you close the application.
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Tested with 3 games, works perfect!!

Thanx for the fast help.

Does it need improvements? (beta?)

Greets PP
Aeliss
Hero Member
Hero Member
Posts: 900
Joined: Thu Apr 04, 2013 5:55 pm

Yep, there is still many bugs ATM, noone of Taito X game are working with it.
This version is bug free, no danger (no infinite loop), it works for all normal game I have installed on my computer.

Code: Select all

;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0

;Get more info
$count = StringInStr($command, '"', 0 , 1, 1)
local $link = StringTrimLeft ( $command, $count  )
$link = StringTrimRight ( $link, 1 )
Local $aDetails = FileGetShortcut($link)
If @error Then exit
local $tmp = StringSplit($aDetails[0], "\")
local $apptorun = $tmp[$tmp[0]]


;run command
;Run ('"' & $app & '" ' & $command)
ShellExecute('"' & $link & '"')

;wait for application launched with protection loop
;wait for 5 s and exit if no application found
local $protloop = 10
While not(ProcessExists($apptorun))
    $protloop = $protloop - 1
   if ($protloop < 0) then exit 0
   sleep(500)
WEnd

;try to put in front
local $PID = GetProcessPID($apptorun)
local $WinName =  ProcessGetWindow($PID)
WinSetState($WinName,"",@SW_SHOW)
WinSetState($WinName,"",@SW_ENABLE)

;wait for close
While (ProcessExists($apptorun) or (ProcessExists("cmd.exe")))
   sleep(500)
WEnd

;try to resolve bug
WinSetState("mGalaxy.exe","",@SW_ENABLE)

Exit 0




;*********************************************************
;functions
;*********************************************************
 
Func _WinWaitActivePID($iPid)
   While 1
       Local $list = WinList()
       For $i = 1 To $list[0][0]
           If $list[$i][0] <> "" And IsVisible($list[$i][1]) Then
               If WinGetProcess($list[$i][1]) = $iPid AND WinActive($list[$i][1]) Then Return $list[$i][0]
           EndIf
       Next
   WEnd
EndFunc
     
Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Func GetProcessPID($name)
   Local $list = ProcessList($name)
   For $i = 1 To $list[0][0]
       If $list[$i][0] <> "" then
          Return $list[$i][1]
        Endif
   Next
   return 0
endFunc



Func ProcessGetWindow($PId)
    If IsNumber($PId) = 0 then
        SetError(1)
    Else
        Local $WinList = WinList()

        For $i = 1 To $WinList[0][0]
            If WinGetProcess($WinList[$i][0], "") = $PId Then
                return $WinList[$i][0]
            EndIf
        Next
        Return 0
    EndIf
 EndFunc
You can mix the  2 versions or make tries by removing/replacing the ";", I can explain functions if you want to modify the script (only 2/4 functions are used, but I let them for memory)
Last edited by Aeliss on Fri Oct 11, 2013 7:53 pm, edited 1 time in total.
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Tested, works perfect!  :D
Aeliss wrote: You can mix the  2 versions or make tries by removing/replacing the ";", I can explain functions if you want to modify the script (only 2/4 functions are used, but I let them for memory)
I have no knowledge of scripts, so me modifying it is not a good idea lol.

Thanx again, PP
Aeliss
Hero Member
Hero Member
Posts: 900
Joined: Thu Apr 04, 2013 5:55 pm

There is no danger, and I use simple syntax, lot of comment. autoit isn't really difficult.

On the next version mgalaxy will correct a problem when we close the application, so it s better to remove the last line.

Code: Select all

;try to resolve bug
WinSetState("mGalaxy.exe","",@SW_ENABLE)
The last working version I have test is

Code: Select all

;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0

;Get more info
$count = StringInStr($command, '"', 0 , 1, 1)
local $link = StringTrimLeft ( $command, $count  )
$link = StringTrimRight ( $link, 1 )
Local $aDetails = FileGetShortcut($link)
If @error Then exit
local $tmp = StringSplit($aDetails[0], "\")
local $apptorun = $tmp[$tmp[0]]


;run command
;Run ('"' & $app & '" ' & $command)
ShellExecute('"' & $link & '"')

;wait for application launched with protection loop
;wait for 5 s and exit if no application found
local $protloop = 10
While not(ProcessExists($apptorun))
    $protloop = $protloop - 1
   if ($protloop < 0) then exit 0
   sleep(500)
WEnd

;try to put in front
local $PID = GetProcessPID($apptorun)
local $WinName =  ProcessGetWindow($PID)
WinSetState($WinName,"",@SW_SHOW)
WinSetState($WinName,"",@SW_ENABLE)

;wait for close
While (ProcessExists($apptorun) or (ProcessExists("cmd.exe")))
   sleep(500)
WEnd

;To resolve bug in taito  Xom Tetris gran master
;local $list = ProcessList("game.exe")
;if $list[0][0] > 0 Then
;   local $PID = $list[1][1]
;   ProcessWaitClose($PID)
;endif

Exit 0




;*********************************************************
;functions
;*********************************************************

Func GetProcessPID($name)
   Local $list = ProcessList($name)
   For $i = 1 To $list[0][0]
       If $list[$i][0] <> "" then
          Return $list[$i][1]
        Endif
   Next
   return 0
endFunc

Func ProcessGetWindow($PId)
    If IsNumber($PId) = 0 then
        SetError(1)
    Else
        Local $WinList = WinList()

        For $i = 1 To $WinList[0][0]
            If WinGetProcess($WinList[$i][0], "") = $PId Then
                return $WinList[$i][0]
            EndIf
        Next
        Return 0
    EndIf
 EndFunc
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Thanx man works perfectly.  :D

Greets, PP
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Hi, now i have the same problem with the "Playstation Portable" (PPSSPP 0.9.8 for windows)
It runs in the background while mGalaxy stays on top. (I can hear the game launching)
I tried using the same script, that didn't work.

Hope some one can help, greets PP 8)
Last edited by PP-Arcade on Sun May 25, 2014 10:06 am, edited 1 time in total.
Aeliss
Hero Member
Hero Member
Posts: 900
Joined: Thu Apr 04, 2013 5:55 pm

I haven't problem with this app. Are you sure It was in fullscreen mode ?

I m using the official script

Code: Select all

;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0
   
HotKeySet("{ESC}", "Terminate")

$PID = Run ('"' & $app & '" ' & $command)

While ProcessExists ( $PID )
   sleep(500)
WEnd

Exit 0

;functions
Func Terminate()
    While ProcessExists ( $PID )
	  ProcessClose ( $PID )
    WEnd
    Exit 0
EndFunc
Look in the ppsspp configuration, there is an option like "force ppsspp stay on top"

Or try this script (But I really think it s useless)

Code: Select all

;Parsing
Local $count = StringInStr($CmdLineRaw, ".exe", 0 , 1, 1)
local $app = StringLeft ( $CmdLineRaw, $count + 4 )
local $command = StringTrimLeft( $CmdLineRaw, $count + 4 )
if not $command then exit 0
   
HotKeySet("{ESC}", "Terminate")

$PID = Run ('"' & $app & '" ' & $command)

while _WinWaitActivePID($PID)
   sleep(500)
wend


While ProcessExists ( $PID )
   sleep(500)
WEnd

Exit 0

;functions

Func Terminate()
    While ProcessExists ( $PID )
	  ProcessClose ( $PID )
    WEnd
    Exit 0
EndFunc

 Func _WinWaitActivePID($iPid)
    While 1
        Local $list = WinList()
        For $i = 1 To $list[0][0]
            If $list[$i][0] <> "" And IsVisible($list[$i][1]) Then
                If WinGetProcess($list[$i][1]) = $iPid AND WinActive($list[$i][1]) Then Return $list[$i][0]
            EndIf
        Next
    WEnd
EndFunc

Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc

Last edited by Aeliss on Sun May 25, 2014 12:17 pm, edited 1 time in total.
User avatar
PP-Arcade
Member
Member
Posts: 43
Joined: Wed Oct 09, 2013 2:19 pm

Hmm I overlooked that "stay on top" option
When in fullscreen press F11 to get that extra option.

Thanx man, works great now! Cheers, PP

(maybe good to include this info on the mGalaxy page "emulator settings")
Last edited by PP-Arcade on Sun May 25, 2014 2:20 pm, edited 1 time in total.
Post Reply