public void Position() { if (Handle != IntPtr.Zero) { User32.SetWindowPos(Handle, 0, (int)Location.Left, (int)Location.Top, (int)Location.Width, (int)Location.Height, User32.SWP_NOZORDER); DwmApi.CloakWindow(Handle, false); } }
void PositionFS2020Window() { var gameHwnd = User32.FindWindow("AceApp", "Microsoft Flight Simulator - 1.12.13.0"); if (gameHwnd == IntPtr.Zero) { _window.Dispatcher.InvokeAsync(() => { _window.Left = 50; _window.Height = 31; _window.Width = m_primaryScreen.WorkingArea.Width - 300; _window.Cloak(false); }); return; } var gameLeft = -8; var gameWidth = 2560 + 16; var gameHeight = 1440 - 32; switch (m_gameWindowSize) { case 2: gameWidth += 2560 / 2; gameLeft -= 2560 / 4; break; case 3: gameWidth += 2560; gameLeft -= 2560 / 2; break; case 4: gameWidth += 2560; gameWidth += 2560; gameLeft -= 2560; break; } User32.SetWindowPos(gameHwnd, 0, gameLeft, 0, gameWidth, gameHeight, User32.SWP_NOZORDER); var blackout = User32.FindWindow_ByCaption(IntPtr.Zero, "TaskbarBlackout"); User32.SetWindowPos(blackout, 0, gameLeft, gameHeight - 6, gameWidth, 40, User32.SWP_NOZORDER); DwmApi.CloakWindow(blackout, false); _window.Dispatcher.InvokeAsync(() => { _window.Height = 31; _window.Left = gameLeft; _window.Width = gameWidth - 50; _window.Cloak(false); }); }
void Setup_A5_FS2020() { PositionFS2020Window(); var windows = new List <NetworkCaptureWindow>(); var defaultClip = new WindowClip(); var pfdClip = new WindowClip(); var mfdClip = new WindowClip(); var panel_height = 478; var panel_width = 600; var mfd_ext_width = 190; var pfd_ext_width = 65; var pfd_ext_height = panel_height; if (_appVm.CurrentAircraftAvionics == AvionicsKind.G3000) { panel_height = 404; mfdClip.LClip += (int)(panel_height * 0.01); pfdClip.BottomClip += 5; mfd_ext_width = 84; pfd_ext_height = 68; pfd_ext_width = panel_width; } else if (_appVm.CurrentAircraftAvionics == AvionicsKind.G3X) { panel_height = pfd_ext_height = 468; panel_width = 700; mfd_ext_width = 84; pfd_ext_height = 68; pfd_ext_width = panel_width; } else if (_appVm.CurrentAircraftAvionics == AvionicsKind.G1000) { panel_height = pfd_ext_height = 478; pfdClip.BottomClip += (int)(panel_height * 0.04); mfdClip.BottomClip += (int)(panel_height * 0.04); } else if (_appVm.CurrentAircraftAvionics == AvionicsKind.F22) { panel_height = pfd_ext_height = 478; panel_width = 540; // updated below pfdClip.TopClip += (int)(panel_height * 0.022); // pfdClip.BottomClip += (int)(panel_height * 0.07); pfdClip.BottomClip += (int)(panel_height * 0.12); mfdClip.BottomClip += (int)(panel_height * 0.12); mfdClip.TopClip += (int)(panel_height * 0.12); } var ptrs = new List <IntPtr>(); var ptrs2 = new List <IntPtr>(); var hwnd = User32.FindWindow("AceApp", ""); ptrs.Add(hwnd); var hwnd2 = User32.FindWindowEx(IntPtr.Zero, hwnd, "AceApp", ""); ptrs.Add(hwnd2); var hwnd3 = User32.FindWindowEx(IntPtr.Zero, hwnd2, "AceApp", ""); ptrs.Add(hwnd3); var hwnd4 = User32.FindWindowEx(IntPtr.Zero, hwnd3, "AceApp", ""); ptrs.Add(hwnd4); ptrs.Sort((one, two) => one.ToInt64().CompareTo(two.ToInt64())); var topfullPtrs = ptrs.Where(p => m_windowFlags.ContainsKey(p) && m_windowFlags[p] == WindowFlags.TopFull); var fullPtrs = ptrs.Where(p => m_windowFlags.ContainsKey(p) && m_windowFlags[p] == WindowFlags.Full); var cduptrs = ptrs.Where(p => m_windowFlags.ContainsKey(p) && m_windowFlags[p] == WindowFlags.CDU); ptrs2.AddRange(topfullPtrs); ptrs2.AddRange(fullPtrs); if (m_isCduFlip) { ptrs2.AddRange(cduptrs.Reverse()); } else { ptrs2.AddRange(cduptrs); } if (ptrs2.Count == 0 || ptrs2.Count < 4) { Trace.Write("RESET PTRS"); ptrs2.Clear(); var ptrs3 = ptrs.GroupBy(x => x).Select(y => y.First()); ptrs2.AddRange(ptrs3.Where(ptr => ptr != IntPtr.Zero)); if (ptrs2.Count == 2 && m_windowFlags.ContainsKey(ptrs2[1]) && m_windowFlags[ptrs2[1]] == WindowFlags.TopFull) { var tmp = ptrs2[0]; ptrs2[0] = ptrs2[1]; ptrs2[1] = tmp; } } if (ptrs2.Count < 1) { return; } var PFD = new CaptureableWindow(ptrs2[0], new Rect(m_screen.WorkingArea.Left, m_screen.WorkingArea.Top, panel_width, panel_height), pfdClip); windows.Add(new NetworkCaptureWindow(PFD, "192.168.0.105", 11001)); // SP4 hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "PFD_EXT"); var PFD_EXT = new CaptureableWindow(hwnd, new Rect(m_screen.WorkingArea.Left + panel_width, m_screen.WorkingArea.Top, pfd_ext_width, pfd_ext_height), defaultClip); var PFD_EXTw = new NetworkCaptureWindow(PFD_EXT, "192.168.0.105", 11004); PFD_EXTw.IsOverlay = true; windows.Add(PFD_EXTw); // SP4 hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "PFDTop"); var PFDTop = new CaptureableWindow(hwnd, new Rect(m_screen.WorkingArea.Left + defaultClip.LClip, m_screen.WorkingArea.Top + pfdClip.TopClip, panel_width - defaultClip.RClip - defaultClip.LClip, panel_height - pfdClip.TopClip - pfdClip.BottomClip), defaultClip); windows.Add(new NetworkCaptureWindow(PFDTop, "localhost", 0, false)); var cdu_width = 290; CaptureableWindow CDU = PFD; hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "MFD_EXT"); var MFD_EXT = new CaptureableWindow(hwnd, new Rect(m_screen.WorkingArea.Left + panel_width, m_screen.WorkingArea.Top + panel_height, mfd_ext_width, panel_height), defaultClip); var MFD_EXTw = new NetworkCaptureWindow(MFD_EXT, "192.168.0.117", 11003); MFD_EXTw.IsOverlay = true; windows.Add(MFD_EXTw); // Nike if (ptrs2.Count > 1) { if (_appVm.CurrentAircraftAvionics == AvionicsKind.F22) { panel_width = 456; } var ND = new CaptureableWindow(ptrs2[1], new Rect(m_screen.WorkingArea.Left, m_screen.WorkingArea.Top + panel_height, panel_width, panel_height), mfdClip); windows.Add(new NetworkCaptureWindow(ND, "192.168.0.117", 11002)); // Nike CDU = ND; hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "MFDTop"); var MFDTop = new CaptureableWindow(hwnd, new Rect(m_screen.WorkingArea.Left + defaultClip.LClip, m_screen.WorkingArea.Top + panel_height + mfdClip.TopClip, panel_width - defaultClip.RClip - defaultClip.LClip, panel_height - mfdClip.BottomClip - mfdClip.TopClip), defaultClip); windows.Add(new NetworkCaptureWindow(MFDTop, "localhost", 0, false)); if (ptrs2.Count > 2) { CDU = new CaptureableWindow(ptrs2[2], new Rect(m_screen.WorkingArea.Left + panel_width + mfd_ext_width + 100, m_screen.WorkingArea.Top + panel_height, cdu_width, panel_height), defaultClip); var CDUw = new NetworkCaptureWindow(CDU, "192.168.0.107", 11005); CDUw.IsCDU = true; windows.Add(CDUw); // NUVision if (ptrs2.Count > 3) { var CDU2 = new CaptureableWindow(ptrs2[3], new Rect(m_screen.WorkingArea.Left + panel_width + mfd_ext_width + 100 + cdu_width, m_screen.WorkingArea.Top + panel_height, cdu_width, panel_height), defaultClip); var CDU2w = new NetworkCaptureWindow(CDU2, "192.168.0.107", 11009); CDU2w.IsCDU = true; windows.Add(CDU2w); // NUVision hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "CDUTop1"); var CDUTop1 = new CaptureableWindow(hwnd, CDU.Location, defaultClip); windows.Add(new NetworkCaptureWindow(CDUTop1, "localhost", 0, false)); hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "CDUTop2"); var CDUTop2 = new CaptureableWindow(hwnd, CDU2.Location, defaultClip); windows.Add(new NetworkCaptureWindow(CDUTop2, "localhost", 0, false)); } } else { hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "CDUTop1"); DwmApi.CloakWindow(hwnd); hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "CDUTop2"); DwmApi.CloakWindow(hwnd); } } hwnd = User32.FindWindow_ByCaption(IntPtr.Zero, "CDUExt"); var CDUExt = new CaptureableWindow(hwnd, new Rect(CDU.Location.Left, CDU.Location.Bottom, cdu_width, 110), defaultClip); var CDUExtw = new NetworkCaptureWindow(CDUExt, "192.168.0.107", 11006); CDUExtw.IgnoreFromRelayout = true; windows.Add(CDUExtw); m_windows = windows; }
public static void Cloak(this Window window, bool hide = true) { DwmApi.CloakWindow(new WindowInteropHelper(window).Handle, hide); }