Application is Active?

  • Thread starter Thread starter Christian Reizlein
  • Start date Start date
C

Christian Reizlein

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,
 
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.Name.ToString() = "Form1" Then
MsgBox("Yes,Form1 is active")
Else
Msgbox("Nope,another form is active")
Else

Hope this helps,

Onur
 
Christian Reizlein said:
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 GetForegroundWindow Lib "user32.dll" () As IntPtr
Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd
As IntPtr, ByRef ProcessID As Int32) As IntPtr

'...

Dim hwnd As IntPtr
Dim ProcessID As Int32

hwnd = GetForegroundWindow
GetWindowThreadProcessId(hwnd, ProcessID)

MsgBox((ProcessID = Process.GetCurrentProcess.Id).ToString)



Armin
 
Back
Top