using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
const int GWL_STYLE = -16;
const uint WS_CAPTION = 0x00C00000;
delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Uso: RemoveTitleBar.exe \"parte do título da janela\"");
return;
}
string partialTitle = args[0].ToLower();
List<IntPtr> windowsToChange = new List<IntPtr>();
EnumWindows((hWnd, lParam) =>
{
if (!IsWindowVisible(hWnd))
return true;
int length = GetWindowTextLength(hWnd);
if (length == 0)
return true;
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hWnd, sb, sb.Capacity);
string title = sb.ToString().ToLower();
if (title.Contains(partialTitle))
{
windowsToChange.Add(hWnd);
}
return true; // continue enumeration
}, IntPtr.Zero);
if (windowsToChange.Count == 0)
{
Console.WriteLine($"Nenhuma janela encontrada contendo '{partialTitle}'.");
return;
}
foreach (var hWnd in windowsToChange)
{
int style = GetWindowLong(hWnd, GWL_STYLE);
style &= ~(int)WS_CAPTION; // remove WS_CAPTION flag
SetWindowLong(hWnd, GWL_STYLE, style);
Console.WriteLine($"Barra de título removida da janela: {GetWindowTitle(hWnd)}");
}
}
static string GetWindowTitle(IntPtr hWnd)
{
int length = GetWindowTextLength(hWnd);
if (length == 0) return "";
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
}