471,348 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 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 3647
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by one2001boy | last post: by
3 posts views Thread by Carl Fenley | last post: by
1 post views Thread by Terry Olsen | last post: by
17 posts views Thread by M O J O | last post: by

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.