Application Focus

N

NvrBst

Is there a quick way to see if my application has focus?

I've tried "this.Focused" but it doesn't return true if one of its
childen controls is what has focus (IE I just clicked a button to
check "this.Focused"). If I run the "this.myBtn.Focused" as the
button click event then I get "true". Ideally I would want something
like application.focused.

Thanks, NB
 
P

Peter Duniho

Is there a quick way to see if my application has focus?

Define "focus".
I've tried "this.Focused" but it doesn't return true if one of its
childen controls is what has focus (IE I just clicked a button to
check "this.Focused"). If I run the "this.myBtn.Focused" as the
button click event then I get "true". Ideally I would want something
like application.focused.

I see System.Windows.Window.IsActive, available in .NET 3.0 and later.
Prior to that, I'm not sure you can do it from .NET. You may have to use
p/invoke to get at the unmanaged function.

Pete
 
N

NvrBst

Define "focus".


I see System.Windows.Window.IsActive, available in .NET 3.0 and later.  
Prior to that, I'm not sure you can do it from .NET.  You may have to use  
p/invoke to get at the unmanaged function.

Pete

Ah, Window.IsActive is exactly what I want thanks :)

NB
 
N

NvrBst

Ah, Window.IsActive is exactly what I want thanks :)

NB- Hide quoted text -

- Show quoted text -

hehe another small question if possible. How exactly do I use the
Window.IsActive object? I've added the PresentationFramework.dll
reference to my application and can see the
"System.Windows.Window.IsActiveProperty", but this isn't what I want.

Basically, how do I get my application window using the
PresentationFramework? I see
"System.Windows.Window.GetWindow(System.Windows.Window.DependancyObject)",
but what is the DependancyObject that relates to my base applications
window?

Thanks, this is probably a basic question but I can't find any
examples of google using the .NET version of Window.IsActive.

NB
 
P

Peter Duniho

[...]
Basically, how do I get my application window using the
PresentationFramework? I see
"System.Windows.Window.GetWindow(System.Windows.Window.DependancyObject)",
but what is the DependancyObject that relates to my base applications
window?

I don't know. I know basically nothing about WPF. If you're not writing
a WPF application, then Window.IsActive might not be useful to you at all,
for all I know. :(

Sorry...maybe someone else who knows more about it can offer some advice.

Pete
 
N

NvrBst

[...]
Basically, how do I get my application window using the
PresentationFramework?  I see
"System.Windows.Window.GetWindow(System.Windows.Window.DependancyObject)",
but what is the DependancyObject that relates to my base applications
window?

I don't know.  I know basically nothing about WPF.  If you're not writing  
a WPF application, then Window.IsActive might not be useful to you at all, 
for all I know.  :(

Sorry...maybe someone else who knows more about it can offer some advice.

Pete

I simply did it the unmanaged way.

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
public bool myAppFocused() { return GetForegroundWindow() ==
this.Handle; }


Cheers NB
 

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