activating an application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm developing a stand-alone windows application i VB.NET. The app starts
another application via the Process class in background (no window yet) and
then establishes a socket communication between them.
The main-app has a button which shall activate the 2nd app to display it's
main frame. Arguments are sent via the socket and the 2nd app responds and
shows the desired frame.
And now to my problem: everything works fine except that the 2nd app is not
becoming the active application, it is displayed under the main app's window.
How can I force the 2nd app to become the active application?
Two desired solution alternatives could be:
1) the main app forces the 2nd app to be the active application (via the
Process instance)
2) the 2nd app forces himself to be the active application

I hope that someone has hints to this!
 
Hi Lars,

Can you post some code showing how you are creating the new Process,
including all parameters that you are passing to it. And also the code
you are using to display the frame of the second process.

Also by becoming the Active application, i assume you mean that the
process does not have a taskbar window? or do you mean something else?
Do let me know this, i'll surely help you out.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Hi Lars,

I looked through your code, a couple of comments

Control.BringToFront() only brings the control to the front of the
Z-order in it's parent container. It does not bring the main window of
the app to the front.

Form.Activate() : Activating a form brings it to the front if this is
the active application, or it flashes the window caption if this is not
the active application. The form must be visible for this method to have
any effect.

So in order for Activate to bring your form to the front, it has to be
the active application, otherwise proper windows behaviour is to flash
the window. You might have seen this when using MSN messenger or Windows
messenger, if a new message arrives while the application is not active
it only flashes the chat window but does not give it focus. In earler
versions of windows applications could steal the focus from other apps
and make themselves active. (Imagine if you are typing an important
document and a chat message arrives, the chat window gets focus and the
text you type foes into the chat window instead of your document, that
is why Ms has made it difficult for non-active apps to get focus). As
far as i know making an appliation active can only be done done
proactively by the user(either clicking on taskbar icon or by
alt-tabbing to it).

So basically in order to bring the window to the top you will have to
use some hack which override the normal window mechanism.I'll keep
looking to see if there is any possibility of doing this.

If you have any doubts please do get in touch with me.


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Hey Lars,

Sorry for the long gap, i was off to TechEd 2004 held here in Delhi.
Anyways i looked into your problem once more and came across this
intresting link
http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=43806

which pointed me to these two locations

http://vbnet.mvps.org/index.html?code/faq/topmost.htm
http://faq.vb.free.fr/index.php?question=50

so if you haven't tried it before you can try using P/Invoke on the
Win32API SetWindowPos() with HWND_TOPMOST as a param.

Let me know if it helps.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Hi,
as usual I had to solve it by myself ;-)
After 20 hours of work I have come up with a workaround solution on my
problem.
The solution is:
1) the main app calls the AppActivate(<2ndapp>) function just after the
message is sent to the 2nd app
2) the 2nd app (after message received) alters the Form.TopMost by first
setting it to True and then to False combined with the Form.Activate(). The
Form.TopMost replace the need for the API function SetWindowPos().

This solution seems to work 100%.

Thanks anyway to Sijin Joseph for your efforts.

No thanks to MS because they didn't answer... ;-(
The 2-day commitment from MS is worthless!
 
Back
Top