Here it's what I have: a web browser plug-in written in C++ and a Windows application written in C#. They communicate through a named pipe. The plug-in instructs the C# application to open a file (suppose that the file is a .txt and it opens in Notepad).
Once the C# application is given the command, it opens the file but Notepad doesn't show in the foreground, which isn't acceptable, I must open Notepad in the foreground.
I modified the C# application so that it calls the SetForegroundWindow function. This time Notepad didn't open in the foreground, but the taskbar flashes.
After reading the documentation for SetForegroundWindow and many articles I think that now I understand what the problem is: the C# application can't bring Notepad to the foreground because it wasn't the the foreground process, the browser was (?).
After reading this: "A process that can set the foreground window can enable another process to set the foreground window by calling the AllowSetForegroundWindow function." I decided to modify the plug-in.
This time the plug-in calls the AllowSetForegroundWindow function passing ASFW_ANY as a parameter (I know, ASFW_ANY could be risky, but I wanted to make sure that AllowSetForegroundWindow would do it).
After I did the modification to the plug-in I tested it and it worked! (Opera 12.02). Then I tested it on Internet Explorer and it worked too. But the problem came when I tested it in Firefox and Chrome. The C# application didn't have the ability to bring Notepad to the foreground. I noticed that for those browsers the AllowSetForegroundWindow function was returning false.
So I started investigating and I come to the conclusion that maybe it's because the plugin container that Firefox uses. An idea came to my mind: it worked in Opera 12.02, but they don't have a plugin container, although they did in Opera 12.00. So I downloaded Opera 12.00, I did the test and it failed, which makes me conclude that the plugin container is the culprit.
The question is: how can I give to the C# application the ability to set foreground?
I don't know how to continue, and I think that I tried all the legitimate ways. The AllowSetForegroundWindow & SetForegroundWindow seems to not apply here.