c# 隐藏 控制台应用程序
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# 隐藏 控制台应用程序的更多相关文章
- 如何创建 C# 控制台应用程序
[转] 如何:创建 C# 控制台应用程序 本主题旨在生成最简单形式的 C# 程序(控制台应用程序)熟悉 Visual Studio 2008 开发环境.由于控制台应用程序是在命令行执行其所有的输入和输 ...
- C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建
取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...
- 双缓冲解决控制台应用程序输出“闪屏”(C/C++,Windows)
使用 C 语言编写游戏的小伙伴们想必起初都要遇到这样的问题,在不断清屏输出数据的过程中,控制台中的输出内容会不断地闪屏.出现这个问题的原因是程序对数据处理花掉的时间影响到了数据显示,或许你可以使用局部 ...
- dotnet core 通过修改文件头的方式隐藏控制台窗口
原文:dotnet core 通过修改文件头的方式隐藏控制台窗口 在带界面的 dotnet core 程序运行的时候就会出现一个控制台窗口,本文告诉大家使用最简单方法去隐藏控制台窗口. 最近在使用 A ...
- 2018-9-30-dotnet-core-通过修改文件头的方式隐藏控制台窗口
title author date CreateTime categories dotnet core 通过修改文件头的方式隐藏控制台窗口 lindexi 2018-09-30 18:36:43 +0 ...
- Windows 隐藏控制台
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"& ...
- dotnet core 隐藏控制台
如果写一个控制台程序,需要隐藏这个控制台程序,可以使用本文的方法 如果是在 Windows 下运行, 可以使用一些系统提供的方法隐藏控制台.如果是 Linux 下,都是控制台,就不用隐藏了 复制下面的 ...
- asp.net mvc引用控制台应用程序exe
起因:有一个控制台应用程序和一个web程序,web程序想使用exe程序的方法,这个时候就需要引用exe程序. 报错:使用web程序,引用exe程序 ,vs调试没有问题,但是部署到iis就报错,如下: ...
- Win32程序和控制台应用程序的项目互转设置
一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...
随机推荐
- xinwajueji
#include<stdio.h> int map[10][10]={0}; int step[30]={0}; int max=99999; int ans[99]={0}; int ...
- [转载]:Delphi xe7并行编程快速入门
现在多数设备.计算机都有多个CPU单元,即使是手机也是多核的.但要在开发中使用多核的优势,却需要一些技巧,花费时间编写额外的代码.好了,现在可以使用Delphi做并行编程了. 在Delphi.C++ ...
- [Android] Intent详解
[转]http://www.cnblogs.com/engine1984/p/4146621.html [正文] Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重 ...
- Android源码剖析之Framework层进阶版(Wms窗口管理)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 上一篇我们主要讲了Ams,篇幅有限,本篇再讲讲Wms,即WindowManagerService,管 ...
- MongoDB的find用法
0.查询符合条件数据的总条数 如:db.list名.find({条件}).count(); 1.返回指定的键值:db.list.find({条件},{name:"任意值",age: ...
- Wordpress固定链接设置
wordpress设置固定链接时,应该尽量注意一下几点: 1.不要让日期出现在固定链接里面. 2.不要让分类的链接出现在固定链接里面. 3.链接不要太深. 4.链接中不要出现中文. 5.文章最后可以加 ...
- jade模板引擎的基本使用
jade和ejs很大的不同是通过缩进的方式解决嵌套和成对标签的问题,比较适合有代码洁癖的同学. jade官方有基础的语法: http://naltatis.github.io/jade-syntax- ...
- java分形树
import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; /** * * @ ...
- ArcGIS API for Silverlight 调用GP服务加载等值线图层
原文:ArcGIS API for Silverlight 调用GP服务加载等值线图层 第二篇.Silverlight客户端调用GP服务 利用ArcGIS API for Silverlight实现G ...
- Layout---poj3169(差分约束+最短路spfa)
题目链接:http://poj.org/problem?id=3169 有n头牛站成一排 在他们之间有一些牛的关系比较好,所以彼此之间的距离不超过一定距离:也有一些关系不好的牛,希望彼此之间的距离大于 ...