473,395 Members | 2,253 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,395 software developers and data experts.

Focus another application

Hello - I've tried to search this, but the word Focus in searching
always returns lots of control focusing.

I would like my C# Win App to minimize, and focus a program that is
already running, then send mouse clicks / keyboard interaction.. and
when complete, restore my app, and focus it of course.

My troubles are finding how to focus the other program. Not looking
for code solutions, just maybe the MSDN location of the namespace, or
an article example, thanks!

May 5 '07 #1
3 10569
On Fri, 04 May 2007 17:24:00 -0700, Kbalz <Ku************@gmail.comwrote:
Hello - I've tried to search this, but the word Focus in searching
always returns lots of control focusing.
Yup. You're really asking more about windows and activating, while
controls are all about focusing. :)
I would like my C# Win App to minimize, and focus a program that is
already running, then send mouse clicks / keyboard interaction.. and
when complete, restore my app, and focus it of course.

My troubles are finding how to focus the other program. Not looking
for code solutions, just maybe the MSDN location of the namespace, or
an article example, thanks!
AFAIK, this wasn't available under .NET 3.0, which includes the Windows
class (in the Windows Presentation Foundation). You can use
Windows.Activate(). However, the docs mention that you need (in addition
to .NET 3.0) the UnmanagedCode permission; this may or may not be a
problem for you.

Pre-3.0, I think you may need to use p/invoke and call the native Windows
SetForegroundWindow() function directly.

Keep in mind that you will want to set the other application's window as
the foreground window *before* you minimize yourself. Minimizing may
cause your application to no longer be the foreground application, which
will prevent it from successfully bringing the other application to the
foreground.

Pete
May 5 '07 #2
On May 4, 8:43 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Fri, 04 May 2007 17:24:00 -0700, Kbalz <Kurtas.Balc...@gmail.comwrote:
Hello - I've tried to search this, but the word Focus in searching
always returns lots of control focusing.

Yup. You're really asking more about windows and activating, while
controls are all about focusing. :)
I would like my C# Win App to minimize, and focus a program that is
already running, then send mouse clicks / keyboard interaction.. and
when complete, restore my app, and focus it of course.
My troubles are finding how to focus the other program. Not looking
for code solutions, just maybe the MSDN location of the namespace, or
an article example, thanks!

AFAIK, this wasn't available under .NET 3.0, which includes the Windows
class (in the Windows Presentation Foundation). You can use
Windows.Activate(). However, the docs mention that you need (in addition
to .NET 3.0) the UnmanagedCode permission; this may or may not be a
problem for you.

Pre-3.0, I think you may need to use p/invoke and call the native Windows
SetForegroundWindow() function directly.

Keep in mind that you will want to set the other application's window as
the foreground window *before* you minimize yourself. Minimizing may
cause your application to no longer be the foreground application, which
will prevent it from successfully bringing the other application to the
foreground.

Pete
I probably will be developing this later this year / early next year,
so it should be using 3.0 or 3.5 (whichever is the latest &
greatest).. I was just looking ahead doing some research, currently
I'm using .NET 2.0 with VS 2005 Pro sp1.

Good point about the order of events.

Are you familiar with a program called Automate? This program does
exactly what I'm after, focusing windows or processes, sending mouse/
key clicks to it... I think it uses VB 6 in the version I have at
work.

I'll run more searches using "Activate" instead of "Focus" for
keywords. Also look at what you've suggested for method calls, thanks
a bunch.

May 5 '07 #3
On Fri, 04 May 2007 17:57:48 -0700, Kbalz <Ku************@gmail.comwrote:
I probably will be developing this later this year / early next year,
so it should be using 3.0 or 3.5 (whichever is the latest &
greatest).. I was just looking ahead doing some research, currently
I'm using .NET 2.0 with VS 2005 Pro sp1.
Please note that when I wrote "this wasn't available under .NET 3.0" what
I meant to write was actually "this wasn't available until .NET 3.0".
Looks like you figured that out, but I should clarify anyway. :)

Pete
May 5 '07 #4

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

Similar topics

1
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so...
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
3
by: Joe Delphi | last post by:
Hi, I have more experience working with Windows.Forms than with WebForms and sometimes it trips me up. When my page loads, I want a particular textbox to have the focus. I am attempting to...
2
by: Tom | last post by:
I am developing a VB.NET user control that is composed of a component control (along with some classes, etc). This is probably a stupid question, and should be easy, but I must be having a brain...
4
by: Tom | last post by:
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)?...
5
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some...
7
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click'...
3
by: jan.loucka | last post by:
Hi, I looked around for this specific problem but could not find any answer - there's few things in VB but still nothing exactly like this so I'd appreciate any help. We're writing C# WinForm...
4
by: =?ISO-8859-15?Q?Albe_V=B0?= | last post by:
In my Application, I need to make a certain graphical refresh, interrogating SqlServer, only if Application has focus (i.e. the title bar is blue). Interrogating .Focused property of various...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.