如何使Outlook Compose窗口成为最重要的窗口

本文关键字:窗口 最重要的 Compose 何使 Outlook | 更新日期: 2023-09-27 18:24:32

我正在创建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(目标)

如何使Outlook Compose窗口成为最重要的窗口

首先,调用MailItem.GetInspector来获取Inspector对象(然后可以调用Inspector.Display),其次,将Inspector强制转换为IOleWindow接口并调用IOleWindows::GetWindow来检索Inspector的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;