【问题标题】:Activating Console window [duplicate]激活控制台窗口 [重复]
【发布时间】:2011-09-05 14:43:26
【问题描述】:

我正在从控制台应用程序中打开 Word。即使在我显示了 Word 应用程序之后,如何确保控制台仍然是活动窗口?

using System;
using Microsoft.Office.Interop.Word;

namespace WordDocumentObject {
    class Program {
        static void Main(string[] args) {
            _Application app = new Application();
            app.Visible = true;

            //Activate the console window here

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }
    }
}

【问题讨论】:

    标签: c# windows


    【解决方案1】:

    您必须使用对 SetForegroundWindow API 的调用来获取您的要求:

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    

    完整的例子已经在 SO:

    bring a console window to front in c#

    【讨论】:

    • 我不敢相信我错过了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 2023-03-17
    • 2016-03-30
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多