Show/Hide the console window of a C# console application(显示/隐藏 C# 控制台应用程序的控制台窗口)
问题描述
我搜索了有关如何隐藏自己的控制台窗口的信息.令人惊讶的是,我能找到的唯一解决方案是使用 FindWindow() 来按标题 找到控制台窗口的 hacky 解决方案.我对 Windows API 进行了更深入的研究,发现有一种更好更简单的方法,所以我想在这里发布它以供其他人查找.
I googled around for information on how to hide one’s own console window. Amazingly, the only solutions I could find were hacky solutions that involved FindWindow() to find the console window by its title. I dug a bit deeper into the Windows API and found that there is a much better and easier way, so I wanted to post it here for others to find.
如何隐藏(和显示)与我自己的 C# 控制台应用程序关联的控制台窗口?
推荐答案
方法如下:
using System.Runtime.InteropServices;
<小时>
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
<小时>
var handle = GetConsoleWindow();
// Hide
ShowWindow(handle, SW_HIDE);
// Show
ShowWindow(handle, SW_SHOW);
这篇关于显示/隐藏 C# 控制台应用程序的控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显示/隐藏 C# 控制台应用程序的控制台窗口
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
