带来另外的进程窗前景时,它有ShowInTaskbar = FALSE [英] Bring another processes Window to foreground when it has ShowInTaskbar = false

查看:214
本文介绍了带来另外的进程窗前景时,它有ShowInTaskbar = FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们只需要在任何时间运行我们的应用程序的一个实例。因此在启动时它看起来看到,如果应用程序正在运行,如果是,它要求在主窗口的 SetForegroundWindow

We only want one instance of our app running at any one time. So on start up it looks to see if the app is running and if it is, it calls SetForegroundWindow on the Main Window.

这是所有好,好... 大部分..

This is all good and well ... for the most part..

在我们的应用程序启动时,它会显示启动画面和登录表单。这两种形式有 ShowInTaskBar = FALSE

When our app starts up it will show a Splash screen and a Logon form. Both of these forms have ShowInTaskBar = false.

因此​​,如果您尝试启动时,登录窗体显示应用程序的另一个副本,即登录表单的不带到前面的!

Because of this, if you try to start up another copy of the app when the Logon form is showing, that Logon form is not brought to the front!

特别是作为用户无法看到任务栏上的任何以及所有他们的身影是,应用程序是达夫而无法启动。没有任何迹象表明,还有另一种实例运行。

Especially as the user cant see anything in the taskbar as well, all they figure is that the app is duff and cannot start. There is no indication that there is another instance running.

有没有解决这个问题的办法吗?

Is there any way around this problem?

推荐答案

好吧,code是在这里。即使 ShowInTaskBar ,你应该能够将其带到前面。

Well, code is here. Even if the ShowInTaskBar is false, you should be able to bring it to the front.

    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);

    public static void bringToFront(string title) {
        // Get a handle to the Calculator application.
        IntPtr handle = FindWindow(null, title);

        // Verify that Calculator is a running process.
        if (handle == IntPtr.Zero) {
            return;
        }

        // Make Calculator the foreground application
        SetForegroundWindow(handle);
    }

请注意:你应该使用 FindWindow函数窗体类和叫不上名字的闪屏的形式,有时没有标题,甚至控制盒。使用间谍++进行深入分析。

Note: you should FindWindow using the form's class and not by name as the splash screen forms sometimes do not have titles or even the controlbox. Use Spy++ to dig deeper.

使用 FindWindow函数上飞溅。我觉得这是你想做的事 - 把启动画面前,而主要形式加载

Use FindWindow on splash. I think this is what you want to do - bring the splash screen in front while loading of the main form.

这篇关于带来另外的进程窗前景时,它有ShowInTaskbar = FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆