This thread is old, but still thought some one might want the solution with out changing their project types. And this solution is specific to C#, so I think there might be similar approach for VC++. Doesn't have a hands on with VC++
You can achieve this using few simple steps. This piece of code minimizes the Console Window, hides from Task Bar. You can hide, restore the app from the Notification Tray.
class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern IntPtr GetShellWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
static NotifyIcon notifyIcon;
static IntPtr processHandle;
static IntPtr WinShell;
static IntPtr WinDesktop;
static MenuItem HideMenu;
static MenuItem RestoreMenu;
static void Main(string[] args)
{
notifyIcon = new NotifyIcon();
notifyIcon.Icon = new Icon("TestICON.ico");
notifyIcon.Text = "Monitor";
notifyIcon.Visible = true;
ContextMenu menu = new ContextMenu();
HideMenu = new MenuItem("Hide", new EventHandler(Minimize_Click));
RestoreMenu = new MenuItem("Restore", new EventHandler(Maximize_Click));
menu.MenuItems.Add(RestoreMenu);
menu.MenuItems.Add(HideMenu);
menu.MenuItems.Add(new MenuItem("Exit", new EventHandler(CleanExit)));
notifyIcon.ContextMenu = menu;
Task.Factory.StartNew(Run);
processHandle = Process.GetCurrentProcess().MainWindowHandle;
WinShell = GetShellWindow();
WinDesktop = GetDesktopWindow();
ResizeWindow(false);
Application.Run();
}
static void Run()
{
Console.WriteLine("Listening to messages");
while (true)
{
System.Threading.Thread.Sleep(1000);
}
}
private static void CleanExit(object sender, EventArgs e)
{
notifyIcon.Visible = false;
Application.Exit();
Environment.Exit(1);
}
static void Minimize_Click(object sender, EventArgs e)
{
ResizeWindow(false);
}
static void Maximize_Click(object sender, EventArgs e)
{
ResizeWindow();
}
static void ResizeWindow(bool Restore = true)
{
if (Restore)
{
RestoreMenu.Enabled = false;
HideMenu.Enabled = true;
SetParent(processHandle, WinDesktop);
}
else
{
RestoreMenu.Enabled = true;
HideMenu.Enabled = false;
SetParent(processHandle, WinShell);
}
}
}