private async Task InitAsync() { //process = await AppTest.StartAsync(@"C:\Program Files\7-Zip\7zFM.exe", 1000); const string FileName = @"notepad"; process = await AppTest.StartAsync(FileName, 1000); model.Program = FileName; RECT rect, frame, client; User32.GetClientRect(process.MainWindowHandle, out client); User32.GetWindowRect(process.MainWindowHandle, out rect); User32.DwmGetWindowAttribute(process.MainWindowHandle, (int)User32.DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out rect, Marshal.SizeOf(typeof(RECT))); grid.Width = 1 / dpi * (rect.Right - rect.Left); grid.Height = 1 / dpi * (rect.Bottom - rect.Top); clientRect.Width = 1 / dpi * (client.Right - client.Left); clientRect.Height = 1 / dpi * (client.Bottom - client.Top); POINT p; p.X = rect.Left; p.Y = rect.Top; Point relativePoint = grid.TransformToAncestor(this) .Transform(new Point(0, 0)); POINT p2; p2.X = 0; p2.Y = 0; User32.ClientToScreen(process.MainWindowHandle, ref p2); clientRect.Margin = new Thickness((p2.X - p.X) / dpi, (p2.Y - p.Y) / dpi, 0, 0); this.Left = (1 / dpi * p.X) - relativePoint.X; this.Top = (1 / dpi * p.Y) - relativePoint.Y; //this.Activate(); }