locked
is Process in Front, on Focus? RRS feed

  • Question

  • Hello,

    with Process.GetProcessesByName("notepad") can is see is Notepad open. but i Need the info is Notepad in front, on Focus in use now? what is the command for this?

    Sunday, November 10, 2019 7:55 AM

Answers

  • i have found the command :-)

    Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
      Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpdwProcessId As Int32) As Int32
     

    Private Function GetActiveAppProcess() As Process
                Dim activeProcessID As IntPtr
    
                'Getting handle of foreground window (the active application) and returning it to activeProcessHandle
                GetWindowThreadProcessId(GetForegroundWindow(), activeProcessID)
    
                Return Process.GetProcessById(pActiveProcessID)
            End Function

    • Marked as answer by mod2509 Sunday, November 10, 2019 8:07 AM
    Sunday, November 10, 2019 8:07 AM