how to activate and bring form to the top

A

Alex K.

Hi all

My application is doing a long job. When it finish, I'd like to bring the
application's form to the top and activate it so user can immediately see the
job is done.
I tried this.Activate() and this.Refresh() in different combination, nothing
seems to work. If I start the process and AFTER that click on another window
that overlaps my application, then after process is finished my form
activates but remains overlapped. I want it to be on the top.

Any ideas?

Thank you
 
A

Ajay Kalra

Peter Duniho said:
If by "click on another window" you mean "click on a window owned by a
different process", then the answer is "you can't".

By design, a process on Windows is not permitted to force an arbitrary
window to the foreground, unless one of a certain narrow list of
conditions are met.

Why cant one write a system wide hook to achieve it? Why is it a system
limitation?
 
A

Ajay Kalra

Peter Duniho said:
There are in fact ways around the limitation. But you have to go to some
significant trouble to do it.

We have SetWindowsHookEx API for that reason. Thats not a limitation but an
explicit API. I am not saying that its a good or bad thing but it can be
done by writing a system wide hook.

I have done it(system wide hook) several times and didnt have to meet any
list of conditions.
 
A

Ajay Kalra

Peter Duniho said:
I have no idea what your point is.

That it can be done contrary to your earlier claim. Please re-read your
reply to OP.
You used a work-around that is outside what a normal application would be
expected to do (hooks are, by definition, a way to hack around the normal
OS API).

I never questioned whether its a good or bad idea. As I mentioned earlier,
this is a Win32 API and despite what you may think, it has appropriate uses.
That's exactly the kind of "significant trouble" I'm talking about.

Using an API isnt trouble in my book.
That's why there's no direct access to that feature in the OS (whatever
else you may believe about correct UI design, using hooks is not
"direct").

Please dont make it a UI design issue; Your claim of " a process on Windows
is not permitted to force an arbitrary
window to the foreground" is patently wrong. I am not saying its a good
thing but it can be done regardless of what I or you may think about its
suitability.
 
A

Ajay

It is _entirely_ a UI design issue.

It wasnt/isnt but seem intent to make it out to be. I never implied
one way or the other whether this is a good technique.
Whatever point you're belaboring now, it can't possibly have anything to  
do with the statement you're saying it does,

You: "By design, a process on Windows is not permitted to force an
arbit..". A process certainly *can* and a process isnt a .Net
construct. I wouldnt suggest OP to use this but I was merely
questioning your statement. Perhaps I took your statement literally
and not in context of .Net.
 

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