From 9f2f1afc14a0d19cd77db391bff5bea469ff2b1a Mon Sep 17 00:00:00 2001 From: Codeusa Date: Fri, 9 Jan 2015 12:49:57 -0500 Subject: [PATCH] Manual merge of #95 --- Common/ProcessDetails.cs | 74 +++++++++++++++++++++++++++++++++- Forms/MainWindow.Designer.cs | 29 ++++++++++--- Forms/MainWindow.cs | 34 +++++++++++----- Forms/MainWindow.resx | 27 +++++++++++-- Installer/BorderlessGaming.iss | 6 +-- Properties/AssemblyInfo.cs | 4 +- WindowsAPI/Manipulation.cs | 17 ++++++-- WindowsApi/Native.cs | 4 ++ version.xml | 2 +- 9 files changed, 166 insertions(+), 31 deletions(-) diff --git a/Common/ProcessDetails.cs b/Common/ProcessDetails.cs index dababc8..047e6e0 100644 --- a/Common/ProcessDetails.cs +++ b/Common/ProcessDetails.cs @@ -18,9 +18,10 @@ public class ProcessDetails public string DescriptionOverride = ""; public string WindowTitle = ""; //public string WindowClass = ""; // note: this isn't used, currently - public IntPtr WindowHandle = IntPtr.Zero; + public IntPtr _WindowHandle = IntPtr.Zero; public bool Manageable = false; public bool MadeBorderless = false; + public int MadeBorderlessAttempts = 0; public WindowsAPI.WindowStyleFlags OriginalStyleFlags_Standard = 0; public WindowsAPI.WindowStyleFlags OriginalStyleFlags_Extended = 0; public Rectangle OriginalLocation = new Rectangle(); @@ -30,7 +31,7 @@ public class ProcessDetails //{ // this.Proc = p; - // this.WindowHandle = this.Proc.MainWindowHandle; + // this._WindowHandle = this.Proc.MainWindowHandle; // this.WindowTitle = WindowsAPI.Native.GetWindowTitle(this.WindowHandle); // //this.WindowClass = WindowsAPI.Native.GetWindowClassName(this.WindowHandle); // note: this isn't used, currently //} @@ -44,6 +45,47 @@ public ProcessDetails(Process p, IntPtr hWnd) //this.WindowClass = WindowsAPI.Native.GetWindowClassName(this.WindowHandle); // note: this isn't used, currently } + // Automatically detects changes to the window handle + public IntPtr WindowHandle + { + get + { + try + { + if (this.ProcessHasExited) + return IntPtr.Zero; + + if (!WindowsAPI.Native.IsWindow(this._WindowHandle)) + { + this.Proc.Refresh(); + this._WindowHandle = this.Proc.MainWindowHandle; + } + } + catch { } + + return this._WindowHandle; + } + set + { + this._WindowHandle = value; + } + } + + public bool ProcessHasExited + { + get + { + try + { + if (this.Proc != null) + return this.Proc.HasExited; + } + catch { } + + return true; + } + } + public string BinaryName { get @@ -108,6 +150,34 @@ private string BinaryName_ForComparison } } + // Detect whether or not the window needs border changes + public bool WindowHasTargetableStyles + { + get + { + WindowsAPI.WindowStyleFlags styleCurrentWindow_standard = WindowsAPI.Native.GetWindowLong(this.WindowHandle, WindowsAPI.WindowLongIndex.Style); + WindowsAPI.WindowStyleFlags styleCurrentWindow_extended = WindowsAPI.Native.GetWindowLong(this.WindowHandle, WindowsAPI.WindowLongIndex.ExtendedStyle); + + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.Border) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.DialogFrame) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ThickFrame) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.SystemMenu) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.MaximizeBox) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.MinimizeBox) > 0) return true; + + if ((styleCurrentWindow_extended | WindowsAPI.WindowStyleFlags.ExtendedDlgModalFrame) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedComposited) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedWindowEdge) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedClientEdge) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedLayered) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedStaticEdge) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedToolWindow) > 0) return true; + if ((styleCurrentWindow_standard | WindowsAPI.WindowStyleFlags.ExtendedAppWindow) > 0) return true; + + return false; + } + } + public static implicit operator ProcessDetails(Process process) { for (int i = 0; i < ProcessDetails.List.Count; i++) diff --git a/Forms/MainWindow.Designer.cs b/Forms/MainWindow.Designer.cs index 5a9ef6d..311e7a8 100644 --- a/Forms/MainWindow.Designer.cs +++ b/Forms/MainWindow.Designer.cs @@ -83,6 +83,7 @@ private void InitializeComponent() this.resToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pauseAutomaticProcessingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openDataFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem11 = new System.Windows.Forms.ToolStripSeparator(); this.toggleMouseCursorVisibilityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toggleWindowsTaskbarVisibilityToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -97,7 +98,8 @@ private void InitializeComponent() this.btnRestoreWindow = new System.Windows.Forms.Button(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.lblUpdateStatus = new System.Windows.Forms.ToolStripStatusLabel(); - this.openDataFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.fullApplicationRefreshToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem12 = new System.Windows.Forms.ToolStripSeparator(); this.processContext.SuspendLayout(); this.mnuFavoritesContext.SuspendLayout(); this.trayIconContextMenu.SuspendLayout(); @@ -477,7 +479,9 @@ private void InitializeComponent() this.openDataFolderToolStripMenuItem, this.toolStripMenuItem11, this.toggleMouseCursorVisibilityToolStripMenuItem, - this.toggleWindowsTaskbarVisibilityToolStripMenuItem}); + this.toggleWindowsTaskbarVisibilityToolStripMenuItem, + this.toolStripMenuItem12, + this.fullApplicationRefreshToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; resources.ApplyResources(this.toolsToolStripMenuItem, "toolsToolStripMenuItem"); // @@ -488,6 +492,12 @@ private void InitializeComponent() resources.ApplyResources(this.pauseAutomaticProcessingToolStripMenuItem, "pauseAutomaticProcessingToolStripMenuItem"); this.pauseAutomaticProcessingToolStripMenuItem.Click += new System.EventHandler(this.pauseAutomaticProcessingToolStripMenuItem_Click); // + // openDataFolderToolStripMenuItem + // + this.openDataFolderToolStripMenuItem.Name = "openDataFolderToolStripMenuItem"; + resources.ApplyResources(this.openDataFolderToolStripMenuItem, "openDataFolderToolStripMenuItem"); + this.openDataFolderToolStripMenuItem.Click += new System.EventHandler(this.openDataFolderToolStripMenuItem_Click); + // // toolStripMenuItem11 // this.toolStripMenuItem11.Name = "toolStripMenuItem11"; @@ -582,11 +592,16 @@ private void InitializeComponent() this.lblUpdateStatus.Name = "lblUpdateStatus"; resources.ApplyResources(this.lblUpdateStatus, "lblUpdateStatus"); // - // openDataFolderToolStripMenuItem + // fullApplicationRefreshToolStripMenuItem // - this.openDataFolderToolStripMenuItem.Name = "openDataFolderToolStripMenuItem"; - resources.ApplyResources(this.openDataFolderToolStripMenuItem, "openDataFolderToolStripMenuItem"); - this.openDataFolderToolStripMenuItem.Click += new System.EventHandler(this.openDataFolderToolStripMenuItem_Click); + this.fullApplicationRefreshToolStripMenuItem.Name = "fullApplicationRefreshToolStripMenuItem"; + resources.ApplyResources(this.fullApplicationRefreshToolStripMenuItem, "fullApplicationRefreshToolStripMenuItem"); + this.fullApplicationRefreshToolStripMenuItem.Click += new System.EventHandler(this.fullApplicationRefreshToolStripMenuItem_Click); + // + // toolStripMenuItem12 + // + this.toolStripMenuItem12.Name = "toolStripMenuItem12"; + resources.ApplyResources(this.toolStripMenuItem12, "toolStripMenuItem12"); // // MainWindow // @@ -688,5 +703,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripSeparator toolStripMenuItem11; private System.Windows.Forms.ToolStripMenuItem noSizeChangeToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem openDataFolderToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem12; + private System.Windows.Forms.ToolStripMenuItem fullApplicationRefreshToolStripMenuItem; } } \ No newline at end of file diff --git a/Forms/MainWindow.cs b/Forms/MainWindow.cs index 84d9836..2c3c914 100644 --- a/Forms/MainWindow.cs +++ b/Forms/MainWindow.cs @@ -117,9 +117,8 @@ private void UpdateProcessList(bool bReset = false) for (int i = this.lstProcesses.Items.Count - 1; i >= 0; i--) { ProcessDetails pd = (ProcessDetails)this.lstProcesses.Items[i]; - string window_title = Native.GetWindowTitle(pd.WindowHandle); - if ((!pd.Manageable) || (!processes.Any(p => p.Id == pd.Proc.Id)) || HiddenProcesses.IsHidden(pd) || (pd.WindowTitle != window_title)) + if ((pd.ProcessHasExited) || (!pd.Manageable) || (!processes.Any(p => p.Id == pd.Proc.Id)) || HiddenProcesses.IsHidden(pd) || (pd.WindowTitle != Native.GetWindowTitle(pd.WindowHandle))) { this.HandlePrunedProcess(pd); @@ -200,15 +199,12 @@ private void wrkBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { foreach (ProcessDetails pd in ProcessDetails.List) { - if (!pd.MadeBorderless) + foreach (Favorites.Favorite fav_process in Favorites.List) { - foreach (Favorites.Favorite fav_process in Favorites.List) + if (((fav_process.Kind == Favorites.Favorite.FavoriteKinds.ByBinaryName) && (pd.BinaryName == fav_process.SearchText)) || + ((fav_process.Kind == Favorites.Favorite.FavoriteKinds.ByTitleText) && (pd.WindowTitle == fav_process.SearchText))) { - if (((fav_process.Kind == Favorites.Favorite.FavoriteKinds.ByBinaryName) && (pd.BinaryName == fav_process.SearchText)) || - ((fav_process.Kind == Favorites.Favorite.FavoriteKinds.ByTitleText) && (pd.WindowTitle == fav_process.SearchText))) - { - this.RemoveBorder(pd, fav_process); - } + this.RemoveBorder(pd, fav_process); } } } @@ -320,6 +316,11 @@ private void toolStripAbout_Click(object sender, EventArgs e) { new AboutForm().ShowDialog(); } + + private void fullApplicationRefreshToolStripMenuItem_Click(object sender, EventArgs e) + { + this.UpdateProcessList(true); + } #endregion @@ -426,8 +427,19 @@ private void byTheProcessBinaryNameToolStripMenuItem_Click(object sender, EventA private void addSelectedItem_Click(object sender, EventArgs e) { - // assume that the button press to add to favorites will do so by window title - this.byTheWindowTitleTextToolStripMenuItem_Click(sender, e); + // assume that the button press to add to favorites will do so by window title (unless it's blank, then go by process name) + + if (this.lstProcesses.SelectedItem == null) return; + + ProcessDetails pd = ((ProcessDetails)this.lstProcesses.SelectedItem); + + if (!pd.Manageable) + return; + + if (!string.IsNullOrEmpty(pd.WindowTitle)) + this.byTheWindowTitleTextToolStripMenuItem_Click(sender, e); + else + this.byTheProcessBinaryNameToolStripMenuItem_Click(sender, e); } private void RefreshFavoritesList(Favorites.Favorite fav = null) diff --git a/Forms/MainWindow.resx b/Forms/MainWindow.resx index 00483b9..dd598d8 100644 --- a/Forms/MainWindow.resx +++ b/Forms/MainWindow.resx @@ -598,6 +598,15 @@ Toggle Windows Taskbar Visibility + + 251, 6 + + + 254, 22 + + + Full Application Refresh + 48, 27 @@ -1070,6 +1079,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + openDataFolderToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripMenuItem11 @@ -1130,12 +1145,18 @@ System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - openDataFolderToolStripMenuItem + + fullApplicationRefreshToolStripMenuItem - + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + toolStripMenuItem12 + + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainWindow diff --git a/Installer/BorderlessGaming.iss b/Installer/BorderlessGaming.iss index b918255..b420fc0 100644 --- a/Installer/BorderlessGaming.iss +++ b/Installer/BorderlessGaming.iss @@ -18,11 +18,11 @@ DisableProgramGroupPage=yes DirExistsWarning=no ; Shown as installed version (Programs & Features) as well as product version ('Details' tab when right-clicking setup program and choosing 'Properties') -AppVersion=7.4 +AppVersion=7.6 ; Stored in the version info for the setup program itself ('Details' tab when right-clicking setup program and choosing 'Properties') -VersionInfoVersion=7.4.315.3 +VersionInfoVersion=7.6.915.629 ; Other version info -OutputBaseFilename=BorderlessGaming_7.4__setup +OutputBaseFilename=BorderlessGaming_7.6__setup ; Shown in the setup program during install only diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 4471738..06e6111 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -36,6 +36,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("7.5.315.567")] -[assembly: AssemblyFileVersion("7.5.315.567")] +[assembly: AssemblyVersion("7.6.915.629")] +[assembly: AssemblyFileVersion("7.6.915.629")] [assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/WindowsAPI/Manipulation.cs b/WindowsAPI/Manipulation.cs index d59845c..c74519e 100644 --- a/WindowsAPI/Manipulation.cs +++ b/WindowsAPI/Manipulation.cs @@ -38,13 +38,19 @@ public static void MakeWindowBorderless(Forms.MainWindow frmMain, IntPtr targetW // Note: if one is not available, the default settings will be used as a new Favorite() object. favDetails = favDetails ?? targetWindow; + // Automatically match this window to a process + ProcessDetails processDetails = targetWindow; + + // Failsafe to prevent rapid switching, but also allow a few changes to the window handle (to be persistent) + if (processDetails != null) + if (processDetails.MadeBorderless) + if ((processDetails.MadeBorderlessAttempts > 3) || (!processDetails.WindowHasTargetableStyles)) + return; + // If no target frame was specified, assume the entire space on the primary screen if ((targetFrame.Width == 0) || (targetFrame.Height == 0)) targetFrame = Screen.FromHandle(targetWindow).Bounds; - // Automatically match this window to a process - ProcessDetails processDetails = targetWindow; - // Get window styles WindowStyleFlags styleCurrentWindow_standard = Native.GetWindowLong(targetWindow, WindowLongIndex.Style); WindowStyleFlags styleCurrentWindow_extended = Native.GetWindowLong(targetWindow, WindowLongIndex.ExtendedStyle); @@ -176,8 +182,12 @@ public static void MakeWindowBorderless(Forms.MainWindow frmMain, IntPtr targetW ); } + // Make a note that we attempted to make the window borderless if (processDetails != null) + { processDetails.MadeBorderless = true; + processDetails.MadeBorderlessAttempts++; + } return; } @@ -191,6 +201,7 @@ public static void RestoreWindow(ProcessDetails pd) WindowsAPI.Native.SetWindowPos(pd.WindowHandle, IntPtr.Zero, pd.OriginalLocation.X, pd.OriginalLocation.Y, pd.OriginalLocation.Width, pd.OriginalLocation.Height, WindowsAPI.SetWindowPosFlags.ShowWindow | WindowsAPI.SetWindowPosFlags.NoZOrder); WindowsAPI.Native.SetWindowPos(pd.WindowHandle, WindowsAPI.Native.HWND_NOTTOPMOST, 0, 0, 0, 0, WindowsAPI.SetWindowPosFlags.NoActivate | WindowsAPI.SetWindowPosFlags.NoMove | WindowsAPI.SetWindowPosFlags.NoSize); pd.MadeBorderless = false; + pd.MadeBorderlessAttempts = 0; } public static void ToggleWindowsTaskbarVisibility(Tools.Boolstate forced = Tools.Boolstate.Indeterminate) diff --git a/WindowsApi/Native.cs b/WindowsApi/Native.cs index 454104b..d53a92a 100644 --- a/WindowsApi/Native.cs +++ b/WindowsApi/Native.cs @@ -225,5 +225,9 @@ public static IntPtr SetWindowLong(IntPtr hWnd, WindowLongIndex nIndex, WindowSt return new IntPtr(Native.SetWindowLong32(hWnd, nIndex, dwNewLong)); } + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsWindow(IntPtr hWnd); } } \ No newline at end of file diff --git a/version.xml b/version.xml index 11d4357..0de3a95 100644 --- a/version.xml +++ b/version.xml @@ -1,5 +1,5 @@ - 7.5 + 7.6 https://github.com/Codeusa/Borderless-Gaming/releases/latest \ No newline at end of file