我怎样才能将焦点设置到应用程序,它是媒体链接处于运行状态? [英] How can i set the focus to application which is allready in running state?

查看:122
本文介绍了我怎样才能将焦点设置到应用程序,它是媒体链接处于运行状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个C#Windows应用程序和放大器;创建它的exe文件。
我想是,当过我尝试运行应用程序,如果是媒体链接处于运行状态比它激活应用其他新的应用程序中打开

I have developed an C# windows application & created a exe of it. what i want is that when ever i try to run the application, If it is allready in running state than it activate that application else new application is opened

这意味着我不想打开同一个应用程序一次以上。

that means i dont want to open same application more than one time

推荐答案

使用下面的代码将焦点设置到当前的应用程序:

Use the following code to set focus to the current application:

        [DllImport("user32.dll")]
        internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        ... 
        Process currentProcess = Process.GetCurrentProcess();
        IntPtr hWnd = currentProcess.MainWindowHandle;
        if (hWnd != IntPtr.Zero)
        {
            SetForegroundWindow(hWnd);
            ShowWindow(hWnd, User32.SW_MAXIMIZE);
        }

这篇关于我怎样才能将焦点设置到应用程序,它是媒体链接处于运行状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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