473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to set focus to other process ?

I need to allow single instance of my process.
I did found the other System.Diagnostics.Process as follow:
System.Diagnostics.Process currentProcess =
System.Diagnostics.Process.GetCurrentProcess();
// Get all instances of GciViewer running on the local machin.
System.Diagnostics.Process[] localByName =
System.Diagnostics.Process.GetProcessesByName("Gci Viewer");
foreach( System.Diagnostics.Process process in localByName )
{
if( currentProcess.Id != process.Id )
{
// TO DO: How to set the focus to the process !!
}
}

How can I set focus to other process?
--
Thanks
Sharon
Mar 8 '06 #1
3 11525
Hello Sharon,

First, use Mutex with "Global\" pattern for single app instance
And SetForegroundWindow + MainWindowHandle API function (apply pinvoke) to
bring process on front

S> I need to allow single instance of my process.
S> I did found the other System.Diagnostics.Process as follow:
S> System.Diagnostics.Process currentProcess =
S> System.Diagnostics.Process.GetCurrentProcess();
S> // Get all instances of GciViewer running on the local machin.
S> System.Diagnostics.Process[] localByName =
S> System.Diagnostics.Process.GetProcessesByName("Gci Viewer");
S> foreach( System.Diagnostics.Process process in localByName )
S> {
S> if( currentProcess.Id != process.Id )
S> {
S> // TO DO: How to set the focus to the process !!
S> }
S> }
S> How can I set focus to other process?
S>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 8 '06 #2
I was hoping for C# API/code.

But if I must use the Win32 API; can I use the send SendMessage() with
WM_SETFOCUS ?

Can you post some sample code on how to set the focus to the other process?
--
Thanks
Sharon
Mar 8 '06 #3
Sharon,

Is this another instance of your own application that you are trying to
bring to focus (for a single-instance application)? If so, check out this
previous thread. It deals with this issue and should give you guidance on
how to enable this functionality in your app:

http://groups.google.com/group/micro...2d86fcc6e071fe

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:1B**********************************@microsof t.com...
I was hoping for C# API/code.

But if I must use the Win32 API; can I use the send SendMessage() with
WM_SETFOCUS ?

Can you post some sample code on how to set the focus to the other
process?
--
Thanks
Sharon

Mar 8 '06 #4

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

Similar topics

1
by: Jagadeesh | last post by:
hi , Am trying to read from and write to a same xml file.i have no prob when reading the xml file.but when i write to the same file i get the following error even after closing the reader...
0
by: walker | last post by:
hi, I want to get other process pid in my program. the other process name is known, I want get its pid, how can I do? for example : in my program I call a process named "mpg321" to play a mp3...
4
by: Marcus Peters | last post by:
Hi folks, I need to copy the selected text in any other application to the clipborad. I played around with several ways which did not work: Win API: Send a Message with WM_COPY --> Worked...
1
by: walter | last post by:
Hi there, this might be a easy one for you -- I want to check if the file is opened by other process before I start to write something in it. This question is so traditional that make me feel a...
1
by: windy | last post by:
Hi all, I wanna know the function to make an process active. i.e. I have my own process runing. And I want to pass the focus(active window) to another existing program on the process list what...
9
by: Carl | last post by:
Hi Is it possible to find out if another process is using a paticular file (xml)? There does not seem to be anything useful in the File och Filestream class for this purpose. regards Carl
2
by: =?Utf-8?B?S2lk?= | last post by:
Hi How can I control other process UI and input some data value like input edit box or click button controls ? Is there some good sample code and tool to help me ? Thank you .
2
by: =?Utf-8?B?S2lk?= | last post by:
Hi Can I get other process UI data like edit box string or combo box index ? And is it possible to get other app client screen pixels data ? Thank you .
3
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'd like to know how to access another process' main window (if it exists) and get information like screen location and size, and whether it's visible at the moment. Is something like that possible?...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.