[英]Set Parent for the dialog box when the same dialog box can be opened from both WPF and WinForm application
[英]How to get outlook select name dialog box to focus when opened from wpf application and outlook is running
我正在创建一个wpf应用程序来发送Outlook约会。 在此应用程序中,我将打开Outlook选择名称对话框以选择约会的收件人。 以下是我的代码:
Outlook.SelectNamesDialog selectNameDialog =
outlookApp.Session.GetSelectNamesDialog();
selectNameDialog.SetDefaultDisplayMode(
Outlook.OlDefaultSelectNamesDisplayMode.olDefaultMeeting);
foreach (var recipient in recipientsList)
{
if (string.IsNullOrEmpty(recipient))
continue;
Outlook.Recipient confRoom =
selectNameDialog.Recipients.Add(recipient);
// Explicitly specify Recipient.Type.
confRoom.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
}
selectNameDialog.Recipients.ResolveAll();
selectNameDialog.Display();
我的问题是,当我打开选择名称对话框时,如果Outlook未运行,则可以正常工作。 但是,如果Outlook正在运行,并且在我的应用程序中单击时打开了此对话框,则该对话框将在应用程序的后面以及Outlook窗口的顶部打开。 即使Outlook正在运行,我也需要在应用程序顶部显示它。 非常感谢任何帮助将此对话框置于所有人面前。 提前致谢。
您可以尝试进行Outlook流程,并将他的窗口向前移。 没有.NET挂钩,您需要为此使用本机Win32 DLL。
[Flags()]
private enum SetWindowPosFlags : uint
{
SynchronousWindowPosition = 0x4000,
DeferErase = 0x2000,
DrawFrame = 0x0020,
FrameChanged = 0x0020,
HideWindow = 0x0080,
DoNotActivate = 0x0010,
DoNotCopyBits = 0x0100,
IgnoreMove = 0x0002,
DoNotChangeOwnerZOrder = 0x0200,
DoNotRedraw = 0x0008,
DoNotReposition = 0x0200,
DoNotSendChangingEvent = 0x0400,
IgnoreResize = 0x0001,
IgnoreZOrder = 0x0004,
ShowWindow = 0x0040,
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern bool BringWindowToTop(IntPtr hWnd);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
[DllImport("user32.dll")]
static extern IntPtr SetFocus(IntPtr hWnd);
int bring_window_to_front_mode = 1; // Various option here, try them out
Boolean TopMost = false;
System.Diagnostics.Process[] prcs = System.Diagnostics.Process.GetProcessesByName("XBMCLauncher");
foreach (var proc in prcs)
{
Log.LogLine("Main Window Handle {0}", p.MainWindowHandle.ToInt32());
switch (bring_window_to_front_mode)
{
case 1:
if (TopMost)
{
Log.LogLine("SetWindowPos TopMost {0}", p.MainWindowHandle.ToInt32());
SetWindowPos(p.MainWindowHandle, HWND_TOPMOST, 50, 50, 500, 500, SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize);
}
else
{
Log.LogLine("SetWindowPos {0}", p.MainWindowHandle.ToInt32());
SetWindowPos(p.MainWindowHandle, HWND_TOP, 50, 50, 500, 500, SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize);
}
break;
case 2:
Log.LogLine("BringWindowToTop {0}", p.MainWindowHandle.ToInt32());
BringWindowToTop(p.MainWindowHandle);
break;
case 3:
Log.LogLine("SetForegroundWindow {0}", p.MainWindowHandle.ToInt32());
SetForegroundWindow(p.MainWindowHandle);
break;
case 4:
Log.LogLine("SetFocus {0}", p.MainWindowHandle.ToInt32());
SetFocus(p.MainWindowHandle);
break;
}
}
当然可以尝试/抓住...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.