N
N
Nikolay Alekseev2020-11-26 14:13:08
C++ / C#
Nikolay Alekseev, 2020-11-26 14:13:08

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;
  }


But the problem is that clicking on the icon simply does not work (the code in the ShowConsole simply does not enter)

I would be grateful for any hint. I can't figure out what and where I didn't finish watching...

Addition.
On the stackoverflow, I found a solution that you need to subscribe to MouseClick
icon.MouseClick += ShowConsole;
But this also does not work

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question