none
ShowWindowAsync 如何显示托盘程序 RRS feed

  • 问题

  • 各位好!

    我在程序中做了两个功能:1、托盘功能--当点击最小化时将程序隐藏到托盘,2、使用windows API 方法保证每次只能运行一个程序,多次运行时使用ShowWindowAsync 这个API将已经运行的程序显示到桌面最前端。

    现在我遇到这样一个问题:我运行程序后将已经运行的程序隐藏到托盘,然后我再次运行这个程序但是却没有任何反应;已经运行的程序依然还是在托盘中并没有显示到桌面的最前端。我尝试使用了ShowWindow这个API没有解决问题,尝试使用FindWindows这个API先找到运行的程序然后再显示出来依然没有解决问题。

    请为各位谁知道我该怎么实现我的这种功能需求呢?

    2012年9月28日 8:54

全部回复

  • 你好,你都尝试了哪些参数?http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx

    Value Meaning
    SW_FORCEMINIMIZE
    11

    Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.

    SW_HIDE
    0

    Hides the window and activates another window.

    SW_MAXIMIZE
    3

    Maximizes the specified window.

    SW_MINIMIZE
    6

    Minimizes the specified window and activates the next top-level window in the Z order.

    SW_RESTORE
    9

    Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

    SW_SHOW
    5

    Activates the window and displays it in its current size and position.

    SW_SHOWDEFAULT
    10

    Sets the show state based on the SW_ value specified in theSTARTUPINFO structure passed to the CreateProcessfunction by the program that started the application.

    SW_SHOWMAXIMIZED
    3

    Activates the window and displays it as a maximized window.

    SW_SHOWMINIMIZED
    2

    Activates the window and displays it as a minimized window.

    SW_SHOWMINNOACTIVE
    7

    Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.

    SW_SHOWNA
    8

    Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.

    SW_SHOWNOACTIVATE
    4

    Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the window is not activated.

    SW_SHOWNORMAL
    1

    Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

    谢谢!

     

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2012年10月1日 6:42
    版主
  • 您好!不好意思哈,放假期间一直没进论坛没能及时回复您。我使用的是ShowWindowAsync这个API来实现显示功能,参数使用过 "Normal" 1、"ShowNoActivate"  4、"Show"  5、"ShowNA"   8、 "Restore"  9、"ShowDefault" 、 10。实现最小化到托盘时使用的方式为:在窗体的Resize事件中添加如下代码
    if (this.WindowState == FormWindowState.Minimized)
                    {
                        this.Visible = false;
                    }
    是我实现托盘的方式不正确引起的还是参数没有使用正确引起的呢?
    2012年10月8日 6:30
  • 您好,麻烦再问下,你是在哪里调用的ShowWindowAsync ?

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2012年10月8日 6:41
    版主
  • 您好,我是在程序的Program类里面调用的。
    2012年10月8日 7:01
  • 论坛内知道的朋友还请您能给出帮助。
    2012年10月11日 1:29