B4J Question [SOLVED] How to "see" which program is running now in front / what user have in front ?

Magma

Expert
Licensed User
Longtime User
Hi there... I know is a big title...

I don't need that to be a "B4J" solution - it can be cmd / line or poweshell script... but b4j will be the "best" :)

So that i need to know - is the program user works now on + in front... not all the apps are running in memory but the front one !!!

With powershell i can see with this command what is running now... but which is in front of all?

example:
B4X:
Get-Process | Where-Object { $_.MainWindowTitle } | Format-Table ID,Name,Mainwindowtitle ?AutoSize

   Id Name                 MainWindowTitle
   -- ----                 ---------------
3392 B4J                  xxxxxx - B4J
8988 B4J                  jRDC - B4J
4984 cmd                Administrator: Γραμμή εντολών - powershell
 
Last edited:

Sandman

Expert
Licensed User
Longtime User
Upvote 0

Magma

Expert
Licensed User
Longtime User
Thanks.... that gave me ideas...

powershell:
B4X:
$code = @'
    [DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
'@
Add-Type $code -Name Utils -Namespace Win32
while(1){
    $hwnd = [Win32.Utils]::GetForegroundWindow()
    Get-Process | 
        Where-Object { $_.mainWindowHandle -eq $hwnd } | 
        Select-Object processName, MainWindowTItle, MainWindowHandle
    sleep -Milliseconds 200
}

Can we "convert" it someway to "b4j"... ?
 
Upvote 0
Top