greggorob64
greggorob64

Reputation: 2557

Bring window of another process forward

I have a C Legacy app, this app opens and closes windows as time goes on (its a server app).

On the same machine, I'm running a C# winforms app.

Here is my goal: My C# app sends my C app a win32 message. The C app opens the window up. I want the newly opened C window to bring to front, IN FRONT OF my C# app.

Here is the process currently:

edit I have everything finished except for the part where I get the C window to come to front somehow. I currently message the C app, and it opens the new window (in front of all other windows of the same .exe), but under my C# app.

I've tried using

[DllImport("user32.dll")]
static extern bool AllowSetForegroundWindow(ServerWindowHandle);

But had no luck with it. Do I somehow need to have my C app have "ownership" of my .net app? The C# app is getting launched via a programinvoke.

Upvotes: 1

Views: 1042

Answers (2)

Evan Phillips
Evan Phillips

Reputation: 261

You didn't mention what operating system you were using but through some searching I found that SetForegroundWindow apparently does not always work on Windows 7. A workaround is described here. Perhaps you could take some ideas from there and apply them in either the C or C# app to get a working solution?

Upvotes: 0

user1775315
user1775315

Reputation:

Can you modify the C app? If so, call SetForegroundWindow on the C app window handle. Or you could make this call from the C# app if you can get a reference to the C app window handle.

Upvotes: 1

Related Questions