Skip to content

Commit

Permalink
Manual merge of #95
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeusa committed Jan 9, 2015
1 parent 854346a commit 9f2f1af
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 31 deletions.
74 changes: 72 additions & 2 deletions Common/ProcessDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
//}
Expand All @@ -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
Expand Down Expand Up @@ -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++)
Expand Down
29 changes: 23 additions & 6 deletions Forms/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 23 additions & 11 deletions Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions Forms/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,15 @@
<data name="toggleWindowsTaskbarVisibilityToolStripMenuItem.Text" xml:space="preserve">
<value>Toggle Windows Taskbar Visibility</value>
</data>
<data name="toolStripMenuItem12.Size" type="System.Drawing.Size, System.Drawing">
<value>251, 6</value>
</data>
<data name="fullApplicationRefreshToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>254, 22</value>
</data>
<data name="fullApplicationRefreshToolStripMenuItem.Text" xml:space="preserve">
<value>Full Application Refresh</value>
</data>
<data name="toolsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>48, 27</value>
</data>
Expand Down Expand Up @@ -1070,6 +1079,12 @@
<data name="&gt;&gt;pauseAutomaticProcessingToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;openDataFolderToolStripMenuItem.Name" xml:space="preserve">
<value>openDataFolderToolStripMenuItem</value>
</data>
<data name="&gt;&gt;openDataFolderToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripMenuItem11.Name" xml:space="preserve">
<value>toolStripMenuItem11</value>
</data>
Expand Down Expand Up @@ -1130,12 +1145,18 @@
<data name="&gt;&gt;lblUpdateStatus.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;openDataFolderToolStripMenuItem.Name" xml:space="preserve">
<value>openDataFolderToolStripMenuItem</value>
<data name="&gt;&gt;fullApplicationRefreshToolStripMenuItem.Name" xml:space="preserve">
<value>fullApplicationRefreshToolStripMenuItem</value>
</data>
<data name="&gt;&gt;openDataFolderToolStripMenuItem.Type" xml:space="preserve">
<data name="&gt;&gt;fullApplicationRefreshToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripMenuItem12.Name" xml:space="preserve">
<value>toolStripMenuItem12</value>
</data>
<data name="&gt;&gt;toolStripMenuItem12.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>MainWindow</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions Installer/BorderlessGaming.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
17 changes: 14 additions & 3 deletions WindowsAPI/Manipulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions WindowsApi/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion version.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<borderlessgaming>
<version>7.5</version>
<version>7.6</version>
<url>https://github.com/Codeusa/Borderless-Gaming/releases/latest</url>
</borderlessgaming>

0 comments on commit 9f2f1af

Please sign in to comment.