如何最小化启动Outlook

本文关键字:Outlook 启动 最小化 | 更新日期: 2024-09-19 15:31:38

我认为启动一个最小化的过程应该很简单,但我在outlook方面运气不佳。如何启动Outlook最小化?

我的尝试是:

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "OUTLOOK.EXE";
    IntPtr hWnd = Process.Start(startInfo).Handle;
    bool state = false;
    if (!hWnd.Equals(IntPtr.Zero))
        state = ShowWindowAsync(hWnd, 2);
    // window values: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
    Console.WriteLine(state.ToString());
    Console.Read();
}

如何最小化启动Outlook

您尝试过使用ProcessStartInfo.WindowStyle并将其设置为ProcessWindowStyle.Minimized吗?

我发现,如果等到Outlook启动并在下面发送命令,窗口将最小化到任务栏。现在,为了最大限度地减少前景,唯一要做的就是循环,直到它准备好:-)

var hWnd = Process.Start(startInfo);
ShowWindowAsync(hWnd.MainWindowHandle, 2);

我已经解决了它,但如果您认为解决方案可以改进,我愿意听取您的意见。我还在我的博客上发布了解决方案,并在http://jwillmer.de/blog/2012/08/01/how-to-start-outlook-minimized-with-c/

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
// console application entry point
static void Main()
{
    // check if process already runs, otherwise start it
    if(Process.GetProcessesByName("OUTLOOK").Count().Equals(0))
        Process.Start("OUTLOOK");
    // get running process
    var process = Process.GetProcessesByName("OUTLOOK").First();
    // as long as the process is active
    while (!process.HasExited)
    {
        // title equals string.Empty as long as outlook is minimized
        // title starts with "öffnen" (engl: opening) as long as the programm is loading
        string title = Process.GetProcessById(process.Id).MainWindowTitle;
        // "posteingang" is german for inbox
        if (title.ToLower().StartsWith("posteingang"))
        {
            // minimize outlook and end the loop
            ShowWindowAsync(Process.GetProcessById(process.Id).MainWindowHandle, 2);
            break;
        }
        //wait awhile
        Thread.Sleep(100);
        // place for another exit condition for example: loop running > 1min
    }
}

您可以使用这Application.ActiveExplorer().WindowState=Outlook.OlWindowState.ol最小化;

它最小化了您的相应展望窗口(this=ThisAddIn类)