Activating Console window [duplicate]
I am opening Word from within a Console Application. How can I ensure the Console remains the active window, even after I have shown the Word Application?
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);
}
}
}
you will have to use a call to the SetForegroundWindow API to get what you ask:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
full example is already in SO:
bring a console window to front in c#
精彩评论