By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Focus issue

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
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
"Tom" wrote:
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

Nov 21 '05 #2

P: n/a
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
Nov 21 '05 #3

P: n/a
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

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
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

Nov 21 '05 #4

P: n/a
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....

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
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

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.