See runnable example below :
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace MyNamespace
{
class Program
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[STAThread]
static void Main(string[] args)
{
// My example context is when app run with no parameters
// application launch an UI to waiting command from it.
if (arrArgs.Count == 0)
{
// Display manage UI and hide console
HideConsole();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainForm());
}
else
{
// Handle parameters ...
}
}
static void HideConsole()
{
IntPtr hWnd = FindWindow(null, Console.Title);
if(hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, 0); // 0 = SW_HIDE
}
}
static void ShowConsole()
{
IntPtr hWnd = FindWindow(null, Console.Title);
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
}
}
}
}
Hope this useful for you.
Happy harvest exp.
Moongy.
1 nhận xét:
Thank, i'll try this
Post a Comment