How do I determine the position a WPF window control in another process? The following code return source=null, therefore I can’t traverse through all controls to find and determine the control position.
Process[] procs = Process.GetProcesses();
foreach(Process p in procs)
{
if (p.MainWindowHandle != null)
{
StringBuilder sb = new StringBuilder(257);
RealGetWindowClass(p.MainWindowHandle, sb, 256);
if(sb.ToString().StartsWith("HwndWrapper"))
{
System.Windows.Interop.HwndSource source = System.Windows.Interop.HwndSource.FromHwnd(p.MainWindowHandle);
EnumVisual(source.RootVisual);
}
}
}
I’m using Project White for automation. With this project you can find WinForms and WPF windows and access their properties, have a look! This way you don’t need to use the low level Windows API.