C# 如何使Outlook Compose窗口位于最顶端?
我正在创建Outlook邮件。有时Outlook Compose窗口出现在其他窗口的后面 我怎样才能使它成为最好的C# 如何使Outlook Compose窗口位于最顶端?,c#,winforms,outlook,office-interop,C#,Winforms,Outlook,Office Interop,我正在创建Outlook邮件。有时Outlook Compose窗口出现在其他窗口的后面 我怎样才能使它成为最好的 String address = "someone@example.com"; Outlook.Application oApp = new Outlook.Application(); Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
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来检索Inspector的HWND。一旦你有了它,你可以调用setForeGroundIndow。需要记住的一点是,如果父进程不在前台,Windows将无法将窗口带到前台。您需要使用AttachThreadInput函数来实现这一点-请参见下面的(Delphi):
我已经编辑了你的标题。请参见“”,其中共识是“不,他们不应该”。使用[redemption][1]解决此问题[1]:
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;