Event raised when Application/Form regains focus...

B

Bodyboarder20

Hello!

So im working on an applicaiton that all pretty much sits on a single
form.

When the application completes a task, I'd like it to use
FlashWindow() to notify the user that it has completed. I have this
part working; however, I cant seem to find the right event to use to
Stop the flashing.

Ive tried the GotFocus and the Enter events on the form, but those
dont seem to do the trick.

Anybody have any ideas?

Thanks!!!
 
N

Nicholas Paldino [.NET/C# MVP]

Do they not work because your form already has focus? If that is the
case, then maybe have a condition where you don't flash the window if the
window already has focus.
 
B

Bodyboarder20

Well for instance if the form is "minimized". Or if there is another
application on top of it. What event is raised when I bring the
entire application back into focus?
 
N

Nicholas Paldino [.NET/C# MVP]

You might want to look into the Activated event as well.
 
B

Bodyboarder20

Activated event seemed to be no goal as well... Is there a way to
monitor an application to see when each event is thrown? That way I
can see what events are thrown and when?
 
B

Bodyboarder20

Activated event seemed to be no goal as well... Is there a way to
monitor an application to see when each event is thrown? That way I
can see what events are thrown and when?

Okay, activated seems to be the one.. however...

Now I seem to be having trouble determining if my application is the
topmost active application that is running.

I dont want the application to flash if it is, cause then i seem to
have to minimize it and restore it before the flashing stops...

ugh...
 
P

Peter Duniho

Bodyboarder20 said:
[...]
Now I seem to be having trouble determining if my application is the
topmost active application that is running.

I dont want the application to flash if it is, cause then i seem to
have to minimize it and restore it before the flashing stops...

ugh...

From what I've gathered based on your posts in this thread, it seems to
me that you are making things way too hard on yourself. There's no
FlashWindow() in .NET, so you appear to be using p/invoke, which isn't
the right way to do what you want.

Just call Form.Activate() on your form instance. It will only flash in
the taskbar if it cannot be activated due to not being the foreground
application.

And for what it's worth, even in non-managed code, FlashWindow() wasn't
the right way to do it either. SetForegroundWindow() would have done
what you want, without all the extra fuss.

Pete
 
B

Bodyboarder20

Bodyboarder20 said:
[...]
Now I seem to be having trouble determining if my application is the
topmost active application that is running.
I dont want the application to flash if it is, cause then i seem to
have to minimize it and restore it before the flashing stops...

From what I've gathered based on your posts in this thread, it seems to
me that you are making things way too hard on yourself. There's no
FlashWindow() in .NET, so you appear to be using p/invoke, which isn't
the right way to do what you want.

Just call Form.Activate() on your form instance. It will only flash in
the taskbar if it cannot be activated due to not being the foreground
application.

And for what it's worth, even in non-managed code, FlashWindow() wasn't
the right way to do it either. SetForegroundWindow() would have done
what you want, without all the extra fuss.

Pete

Well, i managed to get it working using FlashWindow and overriding the
WndProc of the form...

I tried your method and all it did was set the application active and
brought it forward. I dont necessarily want to bring the application
forward. I just wont it to bring in the taskbar. That way a user
will know it's done completing it task. Similar to AIM when you
recieve and instant message...

Thanks to all who have responded!

Problem Solved!
 
P

Peter Duniho

Bodyboarder20 said:
Well, i managed to get it working using FlashWindow and overriding the
WndProc of the form...

What FlashWindow()? There's no FlashWindow() in .NET.
I tried your method and all it did was set the application active and
brought it forward.

Then your application was already a valid candidate for being the
foreground window. Don't you want it brought forward if it can be?

See the docs for non-managed SetForegroundWindow() for a more detailed
explanation of when your application can actually be made the foreground
application and when it can't be (thus causing the taskbar item to flash):
http://msdn2.microsoft.com/en-us/library/ms633539.aspx
I dont necessarily want to bring the application
forward. I just wont it to bring in the taskbar.

If you have some other application that is active and your application
is not a valid candidate for being the foreground window when you call
Activate(), it will flash in the task bar.
That way a user
will know it's done completing it task. Similar to AIM when you
recieve and instant message...

Thanks to all who have responded!

Problem Solved!

Not in a very good way, from the sounds of it. It sounds to me as
though you are abusing the UI guidelines (flashing your taskbar item
when you could simply show the user your window), and at the same time
making your code messier (since you are using non-managed code,
overriding the WndProc, and checking state that has no need of checking).

Pete
 
G

G.Doten

Peter said:
Then your application was already a valid candidate for being the
foreground window. Don't you want it brought forward if it can be?

It sounds like he doesn't; it sounds to me like he just wants the
taskbar to flash regardless of whether the window is a candidate for
being brought forward or not.

Sounds like he found a pretty good workaround to a current Windows Forms
limitation. Nice to know how to do this (I can use it in a couple of apps).
Not in a very good way, from the sounds of it. It sounds to me as
though you are abusing the UI guidelines (flashing your taskbar item
when you could simply show the user your window), and at the same time
making your code messier (since you are using non-managed code,
overriding the WndProc, and checking state that has no need of checking).

FlashWindow[Ex] is a perfectly good Windows function. Just because
Windows Forms hasn't gotten around to implementing this functionality
(assuming that is that case) doesn't mean it breaks any UI guidelines
(apps have been doing this prior to Windows Forms), just that you can't
do it easily with a .NET library call.
 
P

Peter Duniho

G.Doten said:
It sounds like he doesn't; it sounds to me like he just wants the
taskbar to flash regardless of whether the window is a candidate for
being brought forward or not.
I dont want the application to flash if it is, cause then i seem to
have to minimize it and restore it before the flashing stops

That contradicts your assertion that "he just wants the taskbar to flash
regardless". It's pretty clear that there are situations in which he
doesn't want the taskbar to flash.

Using Activate(), Windows will only bring the window to the foreground
if it is the closest thing to the foreground window already. If some
other window is active and involved with the user, the taskbar item will
flash as desired.

This is in fact how the flashing should be done, and is consistent with
the standard Windows UI behavior. Doing it some other way is
inconsistent and violates the user's expectations of what will happen.

Pete
 
G

G.Doten

Peter said:
That contradicts your assertion that "he just wants the taskbar to flash
regardless". It's pretty clear that there are situations in which he
doesn't want the taskbar to flash.

I don't see how in contradicts anything.

ShieldsJared wrote:

<quote>
Okay, activated seems to be the one.. however...

Now I seem to be having trouble determining if my application is the
topmost active application that is running.

I dont want the application to flash if it is, cause then i seem to
have to minimize it and restore it before the flashing stops...
</quote>

I read this to mean that he always wants the taskbar to flash, but when
using Activate to do that *and* his app window is the top-most one, then
he has to min/max his app window to get the flashing to stop. I have
seen app windows that behave that way (I have to click in the window,
even though it is top-most, the get the flashing to stop).

It's interesting to note the native FlashWindow works as ShieldsJared
desires, and it doesn't break any GUI paradigm. You may be right that
most windows require you to click in them to stop the flashing of the
taskbar icon, but when the app window is already topmost I find that
incredibly annoying as appranely ShieldsJared does as well.

I just found the workings of the FlashWindow function interesting,
that's all.
 
G

G.Doten

Peter said:
No...that's not it. Try again.

No, I believe that's it. Otherwise you might be able to discuss the
thread rationally. I give you a concrete reason why you don't understand
the issue, and you turn into a little baby.
 
P

Peter Duniho

G.Doten said:
No, I believe that's it. Otherwise you might be able to discuss the
thread rationally. I give you a concrete reason why you don't understand
the issue, and you turn into a little baby.

Again with the name-calling.

I suppose that without the facts on your side, that's all you have
available to you as a reply. But still...it doesn't exactly help your case.
 
G

G.Doten

Peter said:
Again with the name-calling.

I suppose that without the facts on your side, that's all you have
available to you as a reply. But still...it doesn't exactly help your
case.

Yeah, that's it. You refuse to rationally discuss the problem with the
solution *you* have proposed and have the nerve to say that *I* don't
have a case? You are so precious, little one.

You should learn how to distinguish between name-calling and
characterization, BTW.
 

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