using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices; namespace HideConsole
{
class Program
{
static void Main(string[] args)
{
Console.Title = "HideConsole";
IntPtr hwnd = FindWindow(null, Console.Title);
if (hwnd != IntPtr.Zero)
ShowWindow(hwnd, CmdShow.SW_HIDE);
//Process p = new Process();
/////cmd 名称
//p.StartInfo.FileName = Process.GetCurrentProcess().MainModule.ModuleName;
//p.StartInfo.CreateNoWindow = true;
//p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Console.WriteLine("控制台应用程序隐藏DOS界面"); Console.ReadKey();
} #region WinAPI
/// <summary>
/// Sets the specified window's show state.
/// </summary>
/// <param name="hWnd">A handle to the window.</param>
/// <param name="nCmdShow">Controls how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls</param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "ShowWindow")]
private static extern bool ShowWindow(IntPtr hWnd, CmdShow nCmdShow);
/// <summary>
/// Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
/// </summary>
/// <param name="lpClassName">The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
/// If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.
/// If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.</param>
/// <param name="lpWindowName">The window name (the window's title). If this parameter is NULL, all window names match.</param>
/// <returns>If the function succeeds, the return value is a handle to the window that has the specified class name and window name.
///If the function fails, the return value is NULL.</returns>
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
#endregion
} /// <summary>
/// http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx
/// </summary>
public enum CmdShow : int
{
/// <summary>
/// Hides the window and activates another window.
/// </summary>
SW_HIDE = ,
/// <summary>
/// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
/// </summary>
SW_SHOWNORMAL = ,
/// <summary>
/// Activates the window and displays it as a minimized window.
/// </summary>
SW_SHOWMINIMIZED = ,
/// <summary>
/// Activates the window and displays it as a maximized window.
/// </summary>
SW_SHOWMAXIMIZED = ,
/// <summary>
/// Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the window is not activated.
/// </summary>
SW_SHOWNOACTIVATE = ,
/// <summary>
/// Activates the window and displays it in its current size and position.
/// </summary>
SW_SHOW = ,
/// <summary>
/// Minimizes the specified window and activates the next top-level window in the Z order.
/// </summary>
SW_MINIMIZE = ,
/// <summary>
/// Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
/// </summary>
SW_SHOWMINNOACTIVE = ,
/// <summary>
/// Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.
/// </summary>
SW_SHOWNA = ,
/// <summary>
/// Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
/// </summary>
SW_RESTORE = ,
/// <summary>
/// Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
/// </summary>
SW_SHOWDEFAULT = ,
/// <summary>
/// Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
/// </summary>
SW_FORCEMINIMIZE =
}
}

c# 隐藏 控制台应用程序的更多相关文章

  1. 如何创建 C# 控制台应用程序

    [转] 如何:创建 C# 控制台应用程序 本主题旨在生成最简单形式的 C# 程序(控制台应用程序)熟悉 Visual Studio 2008 开发环境.由于控制台应用程序是在命令行执行其所有的输入和输 ...

  2. C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建

    取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...

  3. 双缓冲解决控制台应用程序输出“闪屏”(C/C++,Windows)

    使用 C 语言编写游戏的小伙伴们想必起初都要遇到这样的问题,在不断清屏输出数据的过程中,控制台中的输出内容会不断地闪屏.出现这个问题的原因是程序对数据处理花掉的时间影响到了数据显示,或许你可以使用局部 ...

  4. dotnet core 通过修改文件头的方式隐藏控制台窗口

    原文:dotnet core 通过修改文件头的方式隐藏控制台窗口 在带界面的 dotnet core 程序运行的时候就会出现一个控制台窗口,本文告诉大家使用最简单方法去隐藏控制台窗口. 最近在使用 A ...

  5. 2018-9-30-dotnet-core-通过修改文件头的方式隐藏控制台窗口

    title author date CreateTime categories dotnet core 通过修改文件头的方式隐藏控制台窗口 lindexi 2018-09-30 18:36:43 +0 ...

  6. Windows 隐藏控制台

    #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"& ...

  7. dotnet core 隐藏控制台

    如果写一个控制台程序,需要隐藏这个控制台程序,可以使用本文的方法 如果是在 Windows 下运行, 可以使用一些系统提供的方法隐藏控制台.如果是 Linux 下,都是控制台,就不用隐藏了 复制下面的 ...

  8. asp.net mvc引用控制台应用程序exe

    起因:有一个控制台应用程序和一个web程序,web程序想使用exe程序的方法,这个时候就需要引用exe程序. 报错:使用web程序,引用exe程序 ,vs调试没有问题,但是部署到iis就报错,如下: ...

  9. Win32程序和控制台应用程序的项目互转设置

    一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...

随机推荐

  1. Lazarus中TScreen类使用介绍

    描述:虚拟屏幕(桌面)可以包含多个物理显示器.Screen对象是鼠标指针.字体.窗体. 对于Delphi兼容的(不可见)DataModules也被列出了. 同时也追踪当前活动窗体窗体.控件和指针. S ...

  2. 十 mybatis逆向工程

    1       逆向工程 1.1     什么是逆向工程 mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper. ...

  3. 【翻译】How To Tango With Django 1.5.4 第一章

    1.概览 这本书的目的就是为了给你提供Django实战开发的指导,这本书主要是为学生设计的,它提供了开发并运行第一个web应用程序的详细的指导步骤,并且指导你怎么将它发布到web服务器上. 本书就是为 ...

  4. hiveserver2以及beeline客户端的使用

    一:开启服务 1.启动前端的hiveserver2 按住ctrl+c就可以结束这个服务. 2.怎么知道已经开启的服务 如果进程在后台,可以查出来,kill这些进程. 3.后端开启服务 二:beelin ...

  5. ADO.NET连接到数据库(oracle)

    本文摘抄于http://www.cnblogs.com/luluping/archive/2009/10/13/1582737.html,如有侵权,请联系博主. OracleConnection 对象 ...

  6. css“变形”效果

    <html <head> <title></title> <style> .test { margin-left:300px; margin-to ...

  7. ArcGIS API for JavaScript开发环境搭建及第一个实例demo

    原文:ArcGIS API for JavaScript开发环境搭建及第一个实例demo ESRI公司截止到目前已经发布了最新的ArcGIS Server for JavaScript API v3. ...

  8. The "Real" Project Plan

    "I need a project plan by tomorrow morning." As project managers, that's what we hear. But ...

  9. C++ version the delaunay triangulation

    https://github.com/Bl4ckb0ne/delaunay-triangulation

  10. Unofficial Windows Binaries for Python Extension Packages

    http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy