I am writing an application in WPF that attaches to skype, moves with it and is sent to back/front with it. The only thing I am missing is whenever skype is brought to front, I need my WPF application to be sent to front with it.
The way I was thinking of doing is, detecting when Skype goes to the top most (in Z-Order) on my desktop and sending my application to front with it.
This is what I have: For connecting to the process
public List<Process> skypeProcess;
public IntPtr ptr;
public Rect skypeRect;
public SkypeWindowPosition()
{
skypeProcess = Process.GetProcessesByName("skype").ToList();
ptr = skypeProcess[0].MainWindowHandle;
SetForegroundWindow(ptr);
skypeRect = new Rect();
GetWindowRect(ptr, ref skypeRect);
}
I wanted to use GetTopWindow from user32.dll but it doesn't work the way I want it to work.
I tried:
if (lyncWin.ptr == LyncWindowPosition.GetTopWindow(new IntPtr(0)))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
But even when skype is on top, it evaluates to "No".
I also have:
int GetZOrder(IntPtr hWnd)
{
var z = 0;
for (var skypeHandle = hWnd; skypeHandle != IntPtr.Zero; skypeHandle = LyncWindowPosition.GetWindow(skypeHandle, 3)) z++;
return z;
}
Which tells me the Z position of skype, but Z would be different depending on how many windows are active.
Any help on figuring out how to determine if skype is on top, or any better way to do it would be appreciated.