Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sampson committed Mar 11, 2019
1 parent 3b54d6a commit 04bdc5d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions BorderlessGaming.Logic/Windows/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<error>";
}
}

[DllImport("user32.dll", SetLastError = true)]
Expand Down

0 comments on commit 04bdc5d

Please sign in to comment.