gpt4 book ai didi

c# - 使用 API 隐藏程序的标题栏

转载 作者:行者123 更新时间:2023-11-30 12:18:33 27 4
gpt4 key购买 nike

可以使用 C# 和 Windows API 删除窗口控制台标题栏,如果可以,如何?请。

最佳答案

这个简单的应用程序隐藏和显示它所在的控制台的标题栏。它暂时将控制台标题更改为 guid 以找到窗口句柄。之后它使用 ToggleTitleBar 使用找到的句柄显示或隐藏。

public class Program
{
public static void ToggleTitleBar(long hwnd, bool showTitle)
{
long style = GetWindowLong(hwnd, -16L);
if (showTitle)
style |= 0xc00000L;
else
style &= -12582913L;
SetWindowLong(hwnd, -16L, style);
SetWindowPos(hwnd, 0L, 0L, 0L, 0L, 0L, 0x27L);
}

public static void Main()
{
Guid guid = Guid.NewGuid();
string oldTitle = Console.Title;
Console.Title = guid.ToString();
int hwnd = FindWindow("ConsoleWindowClass", guid.ToString());
Console.Title = oldTitle;

Console.WriteLine("Press enter to hide title");
Console.ReadLine();
ToggleTitleBar(hwnd, false);
Console.WriteLine("Press enter to show title");
Console.ReadLine();
ToggleTitleBar(hwnd, true);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}

[DllImport("user32", EntryPoint = "GetWindowLongA")]
public static extern long GetWindowLong(long hwnd, long nIndex);

[DllImport("user32", EntryPoint = "SetWindowLongA")]
public static extern long SetWindowLong(long hwnd, long nIndex, long dwNewLong);

[DllImport("user32")]
public static extern long SetWindowPos(long hwnd, long hWndInsertAfter, long x, long y, long cx, long cy,
long wFlags);

[DllImport("User32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
}

关于c# - 使用 API 隐藏程序的标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2014014/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com