1

我认为开始一个最小化的过程应该很简单,但我对前景没有运气。如何以最小化的方式启动 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();
}
4

4 回答 4

2

您是否尝试过使用ProcessStartInfo.WindowStyle,将其设置为ProcessWindowStyle.Minimized

于 2012-08-01T16:28:04.470 回答
0

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

var hWnd = Process.Start(startInfo);
ShowWindowAsync(hWnd.MainWindowHandle, 2);
于 2012-08-01T18:37:24.543 回答
0

我已经解决了,但如果您认为可以改进解决方案,我想听听您的意见。我还在我的博客上发布了解决方案,并在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
    }
}
于 2012-08-01T21:02:18.090 回答
0

你可以使用this.Application.ActiveExplorer().WindowState = Outlook.OlWindowState.olMinimized;

它最小化您当前的 Outlook 窗口(this = ThisAddIn 类)

于 2017-11-12T11:44:33.517 回答