如何使 Outlook Compose 窗口位于最顶部? [英] how to make the Outlook Compose window top most?

查看:27
本文介绍了如何使 Outlook Compose 窗口位于最顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 Outlook 消息.有时 Outlook Compose 窗口会出现在其他窗口的后面.

I am creating an Outlook Message. Sometimes the Outlook Compose window appears behind other windows.

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

How can I make it the top most?

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(目标)

I am using WinForm and .Net 2.0 (target)

推荐答案

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

Firstly, call MailItem.GetInspector to get the Inspector object (you can then call Inspector.Display), secondly, cast Inspector to IOleWindow interface and call IOleWindows::GetWindow to retrieve the inspector's HWND. Once you have that, you can call SetForegroundWindow. One thing to keep in mind is that Windows will nto bring the window to the foreground if the parent process is not in the foreground. You would need to use AttachThreadInput function for that - see below (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;

这篇关于如何使 Outlook Compose 窗口位于最顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆