我认为开始一个最小化的过程应该很简单,但我对前景没有好运。如何启动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();
}
答案 0 :(得分:2)
您是否尝试过使用ProcessStartInfo.WindowStyle
,将其设为ProcessWindowStyle.Minimized
?
答案 1 :(得分:0)
我发现如果你等到Outlook启动并且你在窗口下方发送命令将最小化到托盘。现在,为了最小化前景,唯一要做的就是循环直到准备就绪:-)
var hWnd = Process.Start(startInfo);
ShowWindowAsync(hWnd.MainWindowHandle, 2);
答案 2 :(得分: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
}
}
答案 3 :(得分:0)
你可以用它 this.Application.ActiveExplorer()。WindowState = Outlook.OlWindowState.olMinimized;
最小化您的正确展望窗口 (this = ThisAddIn class)