我正在创建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(目标)
答案 0 :(得分:-1)
首先,调用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;