473,441 Members | 1,769 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,441 software developers and data experts.

Set foreground window

Given the handle of a window, is there a way to make it the foreground window
using C# (rather than win32 API)?
Jun 27 '08 #1
3 3758
On Fri, 06 Jun 2008 00:58:03 -0700, AA2e72E
<AA*****@discussions.microsoft.comwrote:
Given the handle of a window, is there a way to make it the foreground
window
using C# (rather than win32 API)?
Given just the handle? No, I don't think so. A handle is an unmanaged
data structure, and you need to use unmanaged code.

If you know something else about the handle (for example, you know for
sure it's from a managed Form instance), then there's the possibility you
can convert it into something that would allow you to use the result from
managed code. But otherwise, no.

Pete

Jun 27 '08 #2

I can do this quite easily using Win32 APIs from unmanaged code; I am trying
to avoid unmanaged code.

As well as the handle, I can get the caption.

Basically I am using an out of process COM server to which I need to send
instructions via SendKeys; for this, I need to make the COM server visible (I
can) and be the foreground window.
Jun 27 '08 #3
On Fri, 06 Jun 2008 09:34:00 -0700, AA2e72E
<AA*****@discussions.microsoft.comwrote:
I can do this quite easily using Win32 APIs from unmanaged code; I am
trying
to avoid unmanaged code.
Based on your description, I don't think that will be possible. But,
using p/invoke for the one function you need (SetForegroundWindow)
shouldn't really be an issue, especially given that you're already
basically messing around with unmanaged stuff anyway.

Note, of course, the limitations on SetForegroundWindow. Assuming your
own application is already in the foreground, you should be fine. But
it's not a panacea.

Pete
Jun 27 '08 #4

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

Similar topics

7
by: one2001boy | last post by:
Hello, I have an executable file lanuched from another application. is there a way to make thie executable file foreground if it is launched from other application? Thanks.
0
by: Tom | last post by:
Here is a very strange problem that I am stumped by. I have a rather large application written in VB.NET (of course) using Framework 1.1. As you know, with an MDI application you can have multiple...
3
by: Carl Fenley | last post by:
I am trying to capture the Windows QueryCancelAutoPlay message that is sent to the "foreground window" when an AutoRun enabled CD is inserted into a drive. Enabling and Disabling AutoRun...
1
by: Terry Olsen | last post by:
In my chat application, I create a new window for each private chat. I use the FlashWindowEx API to flash the window if it's not the Foreground window. I determine the Foreground window using the...
17
by: M O J O | last post by:
Hi, How can I force a form to the foreground no matter what application is in front? Thanks! M O J O
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
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...
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...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.