Focus issue

T

Tom

Another question relating to focus: Is it possible to set the focus to
another program's window and send it keystrokes, YET still keep my VB
program in the foreground (i.e. showing on the screen)? For instance, I want
to monitor another program's window and send keytstrokes to it, yet I want
my VB.NET program to remain in the foreground, where I will show progress
indicators.

Is this even possible in .NET? I believe it was in VB6 (cause I have a
program that did that) yet I can't get it to work in .NET

Tom
 
G

Guest

Yes, it it possible.

Is the window you want to set focus to part of your application or external?

Does the window title change?

Obviously, to keep your window on top you can use:

Me.TopMost = True

However, there are a few ways to set the focus to the other application:

FindWindow API (Window text or class name)
GetProcessByName & Activate it are just a few ways
 
T

Tom

Crouchie: Yes, this is an external application that I am calling. I want to
set focus to it (the external application) and send it keystrokes; however,
I would like to keep this external application in the background - i.e. keep
my application in the front.

So exactly which APIs must I call to do this? Thanks.

Tom
 
G

Guest

Set your application to topmost:

Me.TopMost = True ' You application is now the TopMost windows.

Is the 'window caption' a constant value in your external application? If
so, you can use FindWindow to get its Handle etc.

Awaiting your reply to the Window Caption question
 
T

Tom

Crouchie: OK, I've set my TopMost to True (and set it to False when the form
is closing).

And yes, I believe that my window caption is a constant value. Actually, I
am using FindWindow, and FindWindowLike to get the handle of the
application; that I am not having a problem with. I just need to set the
focus to that external application (so I can send it keystrokes) yet keep
the other window in the front to display statistics (via a timer).

I've played around with SetFocusAPI, BringProcessToFront, SetToForeground,
etc; however, I am unsure as to exactly which one (if only one) I need to
use to accomplish this task.

One more thing: I find that if I have used one of these APIs to set focus to
the external application, it seems to have a hard time setting focus BACK to
my main VB.NET application once it gets done. I tried a simple Me.Focus but
the external application still stays up. Any ideas on that?

Tom
 
T

Tom

Crouchie: Yep, TopMost worked great... now I can use the API calls to set
focus but the main VB.NET window stays in the forefront.

Now if I can just figure out why I can't reset focus back to the .NET form
when my sendkeys are done....
 

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