Application is Active?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Reizlein

    Application is Active?

    How do i know if my application is the current active window?
    i have tryied using me.focused but that only work if the form is focused, if
    a child control is focused it then returns false and i want to know if my
    application is the current active one in windows so i dont need to flash the
    window to get user attention or bring it to front.

    Thanks,

  • kimiraikkonen

    #2
    Re: Application is Active?

    On Apr 29, 3:58 am, "Christian Reizlein" <creizl...@hotm ail.com>
    wrote:
    How do i know if my application is the current active window?
    i have tryied using me.focused but that only work if the form is focused, if
    a child control is focused it then returns false and i want to know if my
    application is the current active one in windows so i dont need to flash the
    window to get user attention or bring it to front.
    >
    Thanks,
    Christian,
    You can take a look at Form's ActiveForm and ActiveMDIchild
    properties. For instance, if you want to determine that your current
    active form is Form1 by name;

    If Me.ActiveForm.N ame.ToString() = "Form1" Then
    MsgBox("Yes,For m1 is active")
    Else
    Msgbox("Nope,an other form is active")
    Else

    Hope this helps,

    Onur

    Comment

    • Armin Zingler

      #3
      Re: Application is Active?

      "Christian Reizlein" <creizlein@hotm ail.comschrieb
      How do i know if my application is the current active window?
      i have tryied using me.focused but that only work if the form is
      focused, if a child control is focused it then returns false and i
      want to know if my application is the current active one in windows
      so i dont need to flash the window to get user attention or bring it
      to front.
      Maybe there's a shorter way...: (perhaps even a managed one that I did
      not find).

      Declare Function GetForegroundWi ndow Lib "user32.dll " () As IntPtr
      Declare Function GetWindowThread ProcessId Lib "user32.dll " (ByVal hwnd
      As IntPtr, ByRef ProcessID As Int32) As IntPtr

      '...

      Dim hwnd As IntPtr
      Dim ProcessID As Int32

      hwnd = GetForegroundWi ndow
      GetWindowThread ProcessId(hwnd, ProcessID)

      MsgBox((Process ID = Process.GetCurr entProcess.Id). ToString)



      Armin

      Comment

      Working...