473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application Focus

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
Jan 18 '08 #1
5 7948
On Thu, 17 Jan 2008 22:17:28 -0800, NvrBst <nv****@gmail.comwrote:
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
Jan 18 '08 #2
On Jan 17, 10:30*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 17 Jan 2008 22:17:28 -0800, NvrBst <nvr...@gmail.comwrote:
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
Ah, Window.IsActive is exactly what I want thanks :)

NB
Jan 18 '08 #3
On Jan 18, 10:49*am, NvrBst <nvr...@gmail.comwrote:
On Jan 17, 10:30*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:


On Thu, 17 Jan 2008 22:17:28 -0800, NvrBst <nvr...@gmail.comwrote:
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

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.Wi ndow.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
Jan 20 '08 #4
On Sun, 20 Jan 2008 12:31:31 -0800, NvrBst <nv****@gmail.comwrote:
[...]
Basically, how do I get my application window using the
PresentationFramework? I see
"System.Windows.Window.GetWindow(System.Windows.Wi ndow.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
Jan 20 '08 #5
On Jan 20, 1:11*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Sun, 20 Jan 2008 12:31:31 -0800, NvrBst <nvr...@gmail.comwrote:
[...]
Basically, how do I get my application window using the
PresentationFramework? *I see
"System.Windows.Window.GetWindow(System.Windows.Wi ndow.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.d ll")]
static extern IntPtr GetForegroundWindow();
public bool myAppFocused() { return GetForegroundWindow() ==
this.Handle; }
Cheers NB
Jan 21 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1323
by: titouille | last post by:
Hi everybody ! first, sorry for my poor english, I'm french mothertongue ;) technologies : -------------- Python 2.3 Twisted Matrix 1.2.0 wxPython 2.5.1
6
2808
by: KS | last post by:
I have made a WebForm with log ON/OFF off users. There is a label that shows the total count off users logged on stored in Application("UserCount") It works fine if the users logs out WITH THE...
2
1035
by: Urs Vogel | last post by:
Hi Is there a way to find out which application currently has the focus? I want to display a notification in a screen corner and give the focus back to the application which just had it, or can...
2
6084
by: Gil | last post by:
can you set focus to the current access application through vba? lets say i tell access to open another application and that new application gains the focus and causes access to loose the focus....
0
1122
by: euthymos | last post by:
Dear developers, I'm developing an application which uses MSWord Interop interface. When my application launches MSWord, my application itself loses the focus (even if MSWord is not visible). ...
4
6118
by: Octavius Khan | last post by:
I have an application that runs in the system tray and I use global hotkeys to perform functions. When certain hotkeys are pressed, my system tray application may display a message box and...
1
2990
by: cvairetti | last post by:
Hi, I just write an application in C# that show an interface with five button, each button starts an external application that it comes in front of the main C# application with focus on. When the...
3
10576
by: Kbalz | last post by:
Hello - I've tried to search this, but the word Focus in searching always returns lots of control focusing. I would like my C# Win App to minimize, and focus a program that is already running,...
2
1519
by: petinboy | last post by:
Hi All! I am developing an accessibility keyboard application with Visual Studio 2005 Professional Edition and with C#. The application is a keyboard with buttons that interacts with any...
4
5378
by: =?ISO-8859-15?Q?Albe_V=B0?= | last post by:
In my Application, I need to make a certain graphical refresh, interrogating SqlServer, only if Application has focus (i.e. the title bar is blue). Interrogating .Focused property of various...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.