Application is Active?

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,
 
K

kimiraikkonen

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top