Restoring window from the system tray when allowing only one instance of that program

前端 未结 2 1558
长情又很酷
长情又很酷 2020-12-11 08:47

ok, the title is pretty long and should tell the problem i\'m facing with.

Here is the code when minimizing to icon tray:

void MainFormResize(object          


        
相关标签:
2条回答
  • 2020-12-11 09:07

    After looking through dozens of solutions including the link from Hans, I do not believe that the accepted answer's link will restore an app from the systray. All it seems to be doing is correctly managing a single instance and passing arguments to the single instance.

    A more complete solution which was able to manage single instance, restore a minimised window and restore a systray window can be found on codeplex here. http://www.codeproject.com/KB/cs/SingleInstanceAppMutex.aspx

    It's also extremely simple to incorporate into your own code.

    0 讨论(0)
  • 2020-12-11 09:19

    Calling SetForegroundWindow() on an invisible window isn't going to work. There are many other possible failure mode, FindWindow() is a miserable one when you start passing null.

    Don't invent this yourself, .NET already has great built-in support for single instance apps. You can even get a notification when a 2nd copy starts and pass the command line. Which is what you want here, simply restore the window instead of hacking the API. The code you need is here.

    0 讨论(0)
提交回复
热议问题