public static bool SetWindowPlacement(IntPtr hWnd, WindowPlacement placement) { placement.Length = Marshal.SizeOf(typeof(WindowPlacement)); return InternalSetWindowPlacement(hWnd, ref placement); }
internal static extern bool GetWindowPlacement(IntPtr hWnd, out WindowPlacement lpwndpl);
public static string GetPlacement(this MetroWindow window) { return(WindowPlacement.GetPlacement(new WindowInteropHelper(window).Handle)); }
/// <summary> /// OMG this method is awful!!! but yagni /// </summary> /// <param name="callbackParam"></param> private void WindowPositionChangedHandler(CallWindowProcedureParam callbackParam) { ApplicationDisplayMetrics appMetrics = null; if (monitorApplications == null || !monitorApplications.ContainsKey(lastMetrics.Key)) { Log.Error("No definitions found for this resolution: {0}", lastMetrics.Key); return; } appMetrics = monitorApplications[lastMetrics.Key] .FirstOrDefault(row => row.Value.HWnd == callbackParam.hwnd) .Value; if (appMetrics == null) { var newAppWindow = SystemWindow.AllToplevelWindows .FirstOrDefault(row => row.Parent.HWnd.ToInt64() == 0 && !string.IsNullOrEmpty(row.Title) && !row.Title.Equals("Program Manager") && row.Visible && row.HWnd == callbackParam.hwnd); if (newAppWindow == null) { Log.Error("Can't find hwnd {0}", callbackParam.hwnd.ToInt64()); return; } ApplicationDisplayMetrics applicationDisplayMetric = null; AddOrUpdateWindow(lastMetrics.Key, newAppWindow, out applicationDisplayMetric); return; } WindowPlacement windowPlacement = appMetrics.WindowPlacement; WindowsPosition newPosition = (WindowsPosition)Marshal.PtrToStructure(callbackParam.lparam, typeof(WindowsPosition)); windowPlacement.NormalPosition.Left = newPosition.Left; windowPlacement.NormalPosition.Top = newPosition.Top; windowPlacement.NormalPosition.Right = newPosition.Left + newPosition.Width; windowPlacement.NormalPosition.Bottom = newPosition.Top + newPosition.Height; var key = appMetrics.Key; if (monitorApplications[lastMetrics.Key].ContainsKey(key)) { monitorApplications[lastMetrics.Key][appMetrics.Key].WindowPlacement = windowPlacement; } else { Log.Error("Hwnd {0} is not in list, we should capture", callbackParam.hwnd.ToInt64()); return; } Log.Info("WPCH - Capturing {0} at [{1}x{2}] size [{3}x{4}]", appMetrics, appMetrics.WindowPlacement.NormalPosition.Left, appMetrics.WindowPlacement.NormalPosition.Top, appMetrics.WindowPlacement.NormalPosition.Width, appMetrics.WindowPlacement.NormalPosition.Height ); }
private static extern bool GetWindowPlacement(IntPtr hWnd, [In, Out] WindowPlacement lpwndpl);
private void SystemEvens_DisplaySettingsChanged(object sender, EventArgs e) { WindowPlacement.SetWindowByResolution(window, false); }
internal static WindowPlacement GetWindowPlacement(IntPtr handle) { var placement = new WindowPlacement(); placement.length = Marshal.SizeOf(placement); GetWindowPlacement(handle, ref placement); return placement; }
public static extern bool SetWindowPlacement(IntPtr wnd, [In] ref WindowPlacement lpwndpl);
public bool GetWindowPlacement(IntPtr hwnd, ref WindowPlacement pointerToWindowPlacement) { return(NativeMethods.GetWindowPlacement(hwnd, ref pointerToWindowPlacement)); }
private void StartInternalWork() { Toolkit.TraceWriteLine("특정 스크린 프로세스 창 이동 방지를 시작합니다."); _isStartWindowWorker = true; Screen preventScreen = Screen.AllScreens[PreventMoveSceenIndex]; while (_isStartWindowWorker) { foreach (Process process in Process.GetProcesses()) { if (ExceptProcessNames.Contains(process.ProcessName)) { continue; } // 프로세스의 모든 윈도우 핸들 찾아서 처리할지 여부 if (_processAllWindowsHandleSetPosProcessNames.Contains(process.ProcessName)) { // TODO: 특정 프로세스의 모든 윈도우 핸들을 찾아서 처리할지 여부도 이벤트핸들러로 정의 필요 foreach (IntPtr windowHandle in WindowManager.GetProcessWindowHandles(process.Id)) { string windowText = WindowManager.GetWindowText(windowHandle); WindowPlacement wp = new WindowPlacement(); if (User32.GetWindowPlacement(windowHandle, ref wp)) { RECT rect = RECT.Empty; User32.GetWindowRect(windowHandle, out rect); // TODO: WindowPlacement ShowCmd.Maximize, ShowCmd.ShowMaximized 크기 20정도 줄이기 if (wp.ShowCmd == ShowWindowCommand.Maximize || wp.ShowCmd == ShowWindowCommand.ShowMaximized) { // outRect 사이즈를 줄여야 함 rect.Deflate(20, 20); } if (IsNearPreventScreenStartPositionOrEndPosition(preventScreen, ref rect)) { } if (ProcessAllWindowsHandleSetPos.Invoke(this, new ProcessAllSetWindowPosEventArgs(process, windowHandle, wp, windowText))) { if (preventScreen.BoundsContains(rect.ToPoints())) { ProcessSetWindowPos(windowHandle, rect); string text = String.Format("ProcessSetWindowPos ProcessName={0}, Handle={1}, ShowWindowCommand={2}, Text={3}", process.ProcessName, windowHandle, wp.ShowCmd.ToString(), windowText); Toolkit.TraceWriteLine(text); } } } } } else { WindowPlacement wp = new WindowPlacement(); if (User32.GetWindowPlacement(process.MainWindowHandle, ref wp)) { RECT rect; User32.GetWindowRect(process.MainWindowHandle, out rect); // TODO: WindowPlacement ShowCmd.Maximize, ShowCmd.ShowMaximized 크기 20정도 줄이기 if (wp.ShowCmd == ShowWindowCommand.Maximize || wp.ShowCmd == ShowWindowCommand.ShowMaximized) { // outRect 사이즈를 줄여야 함 rect.Deflate(20, 20); } if (IsNearPreventScreenStartPositionOrEndPosition(preventScreen, ref rect)) { } if (preventScreen.BoundsContains(rect.ToPoints())) { ProcessSetWindowPos(process.MainWindowHandle, rect); string text = String.Format("ProcessSetWindowPos ProcessName={0}, Handle={1}, ShowWindowCommand={2}, Title={3}", process.ProcessName, process.MainWindowHandle, wp.ShowCmd.ToString(), process.MainWindowTitle); Toolkit.TraceWriteLine(text); } } } } } }
public static extern bool GetWindowPlacement(IntPtr wnd, ref WindowPlacement placement);
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacement windowPlacement);
private void SettingsWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { AppDataHelper.SettingsWindowPlacement = WindowPlacement.GetPlacement(new WindowInteropHelper(this).Handle); FlyoutHandler.Instance.SettingsWindow = null; }
public static extern bool SetWindowPlacement( IntPtr hwnd, ref WindowPlacement windowPlacment);
private static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacement lpwndpl);
private bool HasWindowChanged(string displayKey, SystemWindow window, out ApplicationDisplayMetrics curDisplayMetrics) { var windowPlacement = new WindowPlacement(); User32.GetWindowPlacement(window.HWnd, ref windowPlacement); // Need to get the "real" screen position that takes into account the snapped or maximized state. "NormalPosition" is used when a restore occurs // or when the user drags the window out of the snapped sate to 'restore' it back to what it was before. (It's a feature!) var screenPosition = new RECT(); User32.GetWindowRect(window.HWnd, ref screenPosition); uint processId = 0; uint threadId = User32.GetWindowThreadProcessId(window.HWnd, out processId); curDisplayMetrics = new ApplicationDisplayMetrics { HWnd = window.HWnd, #if DEBUG // these function calls are very cpu-intensive ApplicationName = window.Process.ProcessName, #else ApplicationName = "", #endif ProcessId = processId, WindowPlacement = windowPlacement, RecoverWindowPlacement = true, ScreenPosition = screenPosition }; bool needUpdate = false; if (!monitorApplications[displayKey].ContainsKey(curDisplayMetrics.Key)) { needUpdate = true; } else { ApplicationDisplayMetrics prevDisplayMetrics = monitorApplications[displayKey][curDisplayMetrics.Key]; if (prevDisplayMetrics.ProcessId != curDisplayMetrics.ProcessId) { // key collision between dead window and new window with the same hwnd monitorApplications[displayKey].Remove(curDisplayMetrics.Key); needUpdate = true; } else if (!prevDisplayMetrics.ScreenPosition.Equals(curDisplayMetrics.ScreenPosition)) { needUpdate = true; Log.Trace("Window position changed for: {0} {1} {2}.", window.Process.ProcessName, processId, window.HWnd.ToString("X8")); } else if (!prevDisplayMetrics.EqualPlacement(curDisplayMetrics)) { needUpdate = true; Log.Trace("Window placement changed for: {0} {1} {2}.", window.Process.ProcessName, processId, window.HWnd.ToString("X8")); //string log = string.Format("prev WindowPlacement ({0}, {1}) of size {2} x {3}", // prevDisplayMetrics.WindowPlacement.NormalPosition.Left, // prevDisplayMetrics.WindowPlacement.NormalPosition.Top, // prevDisplayMetrics.WindowPlacement.NormalPosition.Width, // prevDisplayMetrics.WindowPlacement.NormalPosition.Height // ); //string log2 = string.Format("\ncur WindowPlacement ({0}, {1}) of size {2} x {3}", // curDisplayMetrics.WindowPlacement.NormalPosition.Left, // curDisplayMetrics.WindowPlacement.NormalPosition.Top, // curDisplayMetrics.WindowPlacement.NormalPosition.Width, // curDisplayMetrics.WindowPlacement.NormalPosition.Height // ); //Log.Trace("{0}", log + log2); } } return(needUpdate); }
private static extern bool GetWindowPlacement(IntPtr hwnd, WindowPlacement lpwndpl);
public bool GetWindowPlacement(IntPtr hWnd, out WindowPlacement lpwndpl) { return(NativeMethods.GetWindowPlacement(hWnd, out lpwndpl)); }
private static extern bool InternalSetWindowPlacement(IntPtr hWnd, ref WindowPlacement placement);
public bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacement lpwndpl) { return(NativeMethods.SetWindowPlacement(hWnd, ref lpwndpl)); }
//Focus on a process window public static async Task <bool> FocusProcessWindow(string processTitle, int processId, IntPtr processWindowHandle, WindowShowCommand windowShowCommand, bool setWindowState, bool setTempTopMost) { try { //Prepare the process focus async Task <bool> TaskAction() { try { //Close open Windows prompts await CloseOpenWindowsPrompts(); //Get the current focused application ProcessMulti foregroundProcess = GetProcessMultiFromWindowHandle(GetForegroundWindow()); //Close open start menu, cortana or search await CloseOpenWindowsStartMenu(foregroundProcess); //Close open Windows system menu await CloseOpenWindowsSystemMenu(foregroundProcess); //Detect the previous window state if (windowShowCommand == WindowShowCommand.None && setWindowState) { WindowPlacement processWindowState = new WindowPlacement(); GetWindowPlacement(processWindowHandle, ref processWindowState); Debug.WriteLine("Detected the previous window state: " + processWindowState.windowFlags); if (processWindowState.windowFlags == WindowFlags.RestoreToMaximized) { windowShowCommand = WindowShowCommand.ShowMaximized; } else { windowShowCommand = WindowShowCommand.Restore; } } //Change the window state command if (setWindowState) { ShowWindowAsync(processWindowHandle, windowShowCommand); await Task.Delay(10); ShowWindow(processWindowHandle, windowShowCommand); await Task.Delay(10); } //Set the window as top most if (setTempTopMost) { SetWindowPos(processWindowHandle, (IntPtr)WindowPosition.TopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE); await Task.Delay(10); } //Retry to show the window for (int i = 0; i < 2; i++) { try { //Allow changing window AllowSetForegroundWindow(processId); await Task.Delay(10); //Bring window to top BringWindowToTop(processWindowHandle); await Task.Delay(10); //Switch to the window SwitchToThisWindow(processWindowHandle, true); await Task.Delay(10); //Focus on the window UiaFocusWindowHandle(processWindowHandle); await Task.Delay(10); } catch (Exception ex) { Debug.WriteLine("Process focus error: " + ex.Message); } } //Disable the window as top most if (setTempTopMost) { SetWindowPos(processWindowHandle, (IntPtr)WindowPosition.NoTopMost, 0, 0, 0, 0, (int)WindowSWP.NOMOVE | (int)WindowSWP.NOSIZE); await Task.Delay(10); } //Return bool Debug.WriteLine("Focused process window: " + processTitle + " WindowHandle: " + processWindowHandle + " ShowCmd: " + windowShowCommand); return(true); } catch { } Debug.WriteLine("Failed focusing process: " + processTitle); return(false); }; //Focus the process return(await AVActions.TaskStartReturn(TaskAction).Result); } catch { } Debug.WriteLine("Failed focusing process: " + processTitle); return(false); }
public static extern bool GetWindowPlacement( IntPtr Handle, ref WindowPlacement Placement );
private static extern bool GetWindowPlacement(IntPtr intptr_1, ref WindowPlacement windowPlacement_0);
public static extern bool GetWindowPlacement(IntPtr hWnd, out WindowPlacement windowPlacement);
/// <summary> /// Store the WindowPlacement for the editor /// </summary> /// <param name="editorConfiguration">IEditorConfiguration</param> /// <param name="placement">WindowPlacement</param> public static void SetEditorPlacement(this IEditorConfiguration editorConfiguration, WindowPlacement placement) { editorConfiguration.WindowNormalPosition = placement.NormalPosition; editorConfiguration.WindowMaxPosition = placement.MaxPosition; editorConfiguration.WindowMinPosition = placement.MinPosition; editorConfiguration.ShowWindowCommand = placement.ShowCmd; editorConfiguration.WindowPlacementFlags = placement.Flags; }
public static void SaveSettings() { try { var with1 = frmMain.Default; var windowPlacement = new WindowPlacement(frmMain.Default); if (with1.WindowState == FormWindowState.Minimized & windowPlacement.RestoreToMaximized) { with1.Opacity = 0; with1.WindowState = FormWindowState.Maximized; } mRemoteNG.Settings.Default.MainFormLocation = with1.Location; mRemoteNG.Settings.Default.MainFormSize = with1.Size; if (with1.WindowState != FormWindowState.Normal) { mRemoteNG.Settings.Default.MainFormRestoreLocation = with1.RestoreBounds.Location; mRemoteNG.Settings.Default.MainFormRestoreSize = with1.RestoreBounds.Size; } mRemoteNG.Settings.Default.MainFormState = with1.WindowState; if (with1.Fullscreen != null) { mRemoteNG.Settings.Default.MainFormKiosk = with1.Fullscreen.Value; } mRemoteNG.Settings.Default.FirstStart = false; mRemoteNG.Settings.Default.ResetPanels = false; mRemoteNG.Settings.Default.ResetToolbars = false; mRemoteNG.Settings.Default.NoReconnect = false; mRemoteNG.Settings.Default.ExtAppsTBLocation = with1.tsExternalTools.Location; if (with1.tsExternalTools.Parent != null) { mRemoteNG.Settings.Default.ExtAppsTBParentDock = with1.tsExternalTools.Parent.Dock.ToString(); } mRemoteNG.Settings.Default.ExtAppsTBVisible = with1.tsExternalTools.Visible; mRemoteNG.Settings.Default.ExtAppsTBShowText = with1.cMenToolbarShowText.Checked; mRemoteNG.Settings.Default.QuickyTBLocation = with1.tsQuickConnect.Location; if (with1.tsQuickConnect.Parent != null) { mRemoteNG.Settings.Default.QuickyTBParentDock = with1.tsQuickConnect.Parent.Dock.ToString(); } mRemoteNG.Settings.Default.QuickyTBVisible = with1.tsQuickConnect.Visible; var cryptographyProvider = new LegacyRijndaelCryptographyProvider(); mRemoteNG.Settings.Default.ConDefaultPassword = cryptographyProvider.Encrypt(Convert.ToString(mRemoteNG.Settings.Default.ConDefaultPassword), GeneralAppInfo.EncryptionKey); mRemoteNG.Settings.Default.Save(); SavePanelsToXML(); SaveExternalAppsToXML(); } catch (Exception ex) { Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "Saving settings failed" + Environment.NewLine + Environment.NewLine + ex.Message, false); } }
public static void SetPlacement(this MetroWindow window, string placementXml) { WindowPlacement.SetPlacement(new WindowInteropHelper(window).Handle, placementXml); }
public static void SetPlacementJson(this Window window, string placementJson) { WindowPlacement.SetPlacement(new WindowInteropHelper(window).Handle, placementJson); }
public static extern bool GetWindowPlacement(IntPtr window, ref WindowPlacement position);
private static extern bool GetWindowPlacement(IntPtr hwnd, WindowPlacement lpwndpl);
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);
private static extern uint GetWindowPlacement(uint _hwnd, [Out] out WindowPlacement _lpwndpl);
public static WindowPlacement GetWindowPlacement(IntPtr hwnd) { WindowPlacement wndpl = new WindowPlacement(); if (GetWindowPlacement(hwnd, wndpl)) { return wndpl; } throw new Win32Exception(Marshal.GetLastWin32Error()); }
static extern bool GetWindowPlacement(IntPtr handle, ref WindowPlacement wp);
public static extern bool GetWindowPlacement(IntPtr hWnd, out WindowPlacement lpwndpl);
/// <summary> /// Sets the show state and the restored, minimized, and maximized positions of the specified window. /// </summary> /// <param name="windowHandle">A handle to the window.</param> /// <param name="placement"> /// A pointer to the <see cref="WindowPlacement" /> structure that specifies the new show state and /// window positions. /// </param> public static void SetWindowPlacement(IntPtr windowHandle, WindowPlacement placement) { // Check if the handle is valid HandleManipulationHelper.ValidateAsArgument(windowHandle, "windowHandle"); // If the debugger is attached and the state of the window is ShowDefault, there's an issue where the window disappears if (Debugger.IsAttached && placement.ShowCmd == WindowStates.ShowNormal) placement.ShowCmd = WindowStates.Restore; // Set the window placement if (!NativeMethods.SetWindowPlacement(windowHandle, ref placement)) throw new Win32Exception("Couldn't set the window placement."); }
private static extern bool InternalGetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);
/// <summary> /// Set the WindowPlacement /// </summary> /// <param name="interopWindow">InteropWindow</param> /// <param name="placement">WindowPlacement</param> /// <returns>IInteropWindow for fluent calls</returns> public static IInteropWindow SetPlacement(this IInteropWindow interopWindow, WindowPlacement placement) { User32Api.SetWindowPlacement(interopWindow.Handle, ref placement); interopWindow.Placement = placement; return(interopWindow); }
public static extern bool GetWindowPlacement( IntPtr windowHandle, ref WindowPlacement windowPlacement );
public static extern bool GetWindowPlacement(IntPtr window, ref WindowPlacement position);