如何使Outlook Compose窗口最顶级?

我正在创建一个Outlook消息。 有时Outlook Compose窗口出现在其他窗口后面。

我怎样才能成为最顶级的?

String address = "someone@example.com"; Outlook.Application oApp = new Outlook.Application(); Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMailItem.To = address; oMailItem.Subject = "Help"; oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain; oMailItem.Attachments.Add("H:\\file.txt"); oMailItem.Body = "Call me"; // body, bcc etc... oMailItem.Display(true); 

我正在使用WinForm和.Net 2.0(目标)

首先,调用MailItem.GetInspector获取Inspector对象(然后可以调用Inspector.Display),其次,将Inspector强制转换为IOleWindow接口并调用IOleWindows :: GetWindow以检索检查器的HWND。 一旦你有了,你可以调用SetForegroundWindow。 要记住的一件事是,如果父进程不在前台,Windows将不会将窗口置于前台。 你需要使用AttachThreadInput函数 – 见下文(Delphi):

 function ForceForegroundWindow(hWnd: THandle): BOOL; var hCurWnd: THandle; begin hCurWnd := GetForegroundWindow; AttachThreadInput( GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, True); Result := SetForegroundWindow(hWnd); AttachThreadInput( GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, False); end;