diff --git a/BorderlessGaming.Logic/Windows/Native.cs b/BorderlessGaming.Logic/Windows/Native.cs index 36a8dd8..90d956d 100644 --- a/BorderlessGaming.Logic/Windows/Native.cs +++ b/BorderlessGaming.Logic/Windows/Native.cs @@ -217,11 +217,17 @@ public static string GetWindowClassName(IntPtr hWnd) public static string GetWindowTitle(IntPtr hWnd) { // Allocate correct string length first - var length = (int) SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero); - var sbWindowTitle = new StringBuilder(length + 1); - SendMessage(hWnd, WM_GETTEXT, (IntPtr) sbWindowTitle.Capacity, sbWindowTitle); - Console.WriteLine(sbWindowTitle.ToString()); - return sbWindowTitle.ToString(); + try + { + var length = (int)SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero); + var sbWindowTitle = new StringBuilder(length + 1); + SendMessage(hWnd, WM_GETTEXT, (IntPtr)sbWindowTitle.Capacity, sbWindowTitle); + return sbWindowTitle.ToString(); + } + catch (Exception) + { + return ""; + } } [DllImport("user32.dll", SetLastError = true)]