473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Set Focus to another programs window?

Tom
I am using VB.NET to control another program. I have the program's window
hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes. I thought I could just use the
SetFocus API, but I read somewhere that it will only work for programs
running under that programs thread. Is this true? If so, how can I set focus
to another program's window via VB.NET? Thanks.

Tom
Nov 21 '05 #1
8 51635
Hi

First of all 'hwnd' is now 'Handle' in VB.NET

The easiest way would be to use 'AppActivate' if you know the window title:

AppActivate("Untitled - Notepad")

---

Another simple way is:

Dim intNotePad As Integer = Shell("C:\WINNT\Notepad.exe",
AppWinStyle.MinimizedNoFocus)

AppActivate(intNotePad)

---

I cannot see any point using FinWindow API if you already have the Handle of
that window.

"Tom" wrote:
I am using VB.NET to control another program. I have the program's window
hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes. I thought I could just use the
SetFocus API, but I read somewhere that it will only work for programs
running under that programs thread. Is this true? If so, how can I set focus
to another program's window via VB.NET? Thanks.

Tom

Nov 21 '05 #2
Tom
Crouchie: Thanks, forgot about AppActivate.

One question, though: Is the process handle the same and the 'Handle' (i.e.
old hwnd)?

Tom

"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi

First of all 'hwnd' is now 'Handle' in VB.NET

The easiest way would be to use 'AppActivate' if you know the window title:
AppActivate("Untitled - Notepad")

---

Another simple way is:

Dim intNotePad As Integer = Shell("C:\WINNT\Notepad.exe",
AppWinStyle.MinimizedNoFocus)

AppActivate(intNotePad)

---

I cannot see any point using FinWindow API if you already have the Handle of that window.

"Tom" wrote:
I am using VB.NET to control another program. I have the program's window hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes. I thought I could just use the
SetFocus API, but I read somewhere that it will only work for programs
running under that programs thread. Is this true? If so, how can I set focus to another program's window via VB.NET? Thanks.

Tom

Nov 21 '05 #3
"Tom" <to*@nospam.com> schrieb:
I am using VB.NET to control another program. I have the program's window
hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes.


See:

<URL:http://www.google.de/groups?selm=uKqv47yaEHA.3820%40tk2msftngp13.phx.gb l>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"Tom" <to*@nospam.com> schrieb:
One question, though: Is the process handle the same and the 'Handle'
(i.e.
old hwnd)?


No. Process handles are different from window handles.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
Tom
Herfried: Does this just bring the window to the front? Or does it also set
focus to the window?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uz**************@tk2msftngp13.phx.gbl...
"Tom" <to*@nospam.com> schrieb:
I am using VB.NET to control another program. I have the program's window
hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes.
See:

<URL:http://www.google.de/groups?selm=uKq...ftngp13.phx.gb
l>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"Tom" <to*@nospam.com> schrieb:
Does this just bring the window to the front? Or does it also set
focus to the window?


MSDN on 'SetForegroundWindow':

"
The 'SetForegroundWindow' function puts the thread that created the
specified window into the foreground and activates the window. Keyboard
input is directed to the window, and various visual cues are changed for the
user.
"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Tom
Herfried: One more question related to this: Is it possible to set the focus
to another program's window and send it keystroks, YET still keep my VB
program in the foreground (i.e. showing on the screen)?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uz**************@tk2msftngp13.phx.gbl...
"Tom" <to*@nospam.com> schrieb:
I am using VB.NET to control another program. I have the program's window
hwnd; however, I need to be able to set the focus to that other programs
window so I can send it some keystrokes.
See:

<URL:http://www.google.de/groups?selm=uKq...ftngp13.phx.gb
l>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Tom
Herfried: One more question related to this: Is it possible to set the focus
to another program's window and send it keystroks, YET still keep my VB
program in the foreground (i.e. showing on the screen)?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
"Tom" <to*@nospam.com> schrieb:
Does this just bring the window to the front? Or does it also set
focus to the window?
MSDN on 'SetForegroundWindow':

"
The 'SetForegroundWindow' function puts the thread that created the
specified window into the foreground and activates the window. Keyboard
input is directed to the window, and various visual cues are changed for

the user.
"

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: omission9 | last post by:
An application I have written is, suddenly it seems, throwing the following error after being left in use for several hours. This does not seem to occur with lighter usage. I am not 100% sure what...
4
by: Jamie Jackson | last post by:
The crux of the problem is I only know if the popup *has been* opened, but not if it *is* open. Therefore, the script doesn't know whether to simply refocus, or whether to popup a fresh window. ...
2
by: Mike May | last post by:
Hi IE6 Win2k The javascript FAQ describes how you can retain a reference to a window that you have opened and manipulate the window - focus on it or close it, viz: 4.10 How do I check to...
31
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page...
1
by: ranabhavin2 | last post by:
I have done chatting application in asp.net by using Atlas. I have made database chat application . So, problem is that , If there are many windows minimized at my taskbar and if there is new ...
1
by: yuenli | last post by:
Hi! I am facing a problem here. I wish to open a sub window from another sub window which means when i click on the main parent window a small window will appear then when i click on the button on...
2
by: Dean Slindee | last post by:
I am not looking for a "hybrid" WPF/WinForm or WinForm/WPF solution, but rather a pure WPF/WPFsolution. I want to host a WPF window inside another WPF window. I want to host a WPF window as a...
4
by: gaurav kashyap | last post by:
Dear all, I am using Microsoft Windows XP.Using putty.exe,I connected to LINUX server and a terminal window gets opened.Here i logeed in as root. What i want to do is open another terminal...
5
by: datactrl | last post by:
On firefox multi-tab, I open a window with ref=window.open(). It works. A new window is opened in a new tab. On parent window, there is button doing ref.focus(). But it won't put focus on that new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.