Answer the question
In order to leave comments, you need to log in
How to bring console app back from notification area?
Good day to all!
Wrote a simple console application. It listens in a background thread to the com port and, receiving messages from there, forwards them to a remote server.
When all that needs to be done, we send the console window to the notification area.
[DllImport( "user32.dll" )]
private static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );
[DllImport( "kernel32.dll", ExactSpelling = true )]
private static extern IntPtr GetConsoleWindow();
...
icon = new NotifyIcon();
icon.Icon = new Icon( "icon.ico" );
icon.Visible = true;
icon.Click += ShowConsole;
icon.DoubleClick += ShowConsole;
ShowWindow( GetConsoleWindow(), 0 );
private static void ShowConsole( object sender, EventArgs e ) {
ShowWindow( GetConsoleWindow(), 1 );
icon.Visible = false;
}
icon.MouseClick += ShowConsole;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question