部署 Outlook VSTO 插件后 Win 窗体无法打开?
Win form not opening after deploying Outlook VSTO Addin?
我已经使用 Visual Studio 安装程序项目(跟随 this link)和 C# 部署了 Outlook 加载项。
安装程序已正确安装 (.msi),我可以在“选项”->“加载项”中看到它,还可以通过控件看到功能区。(这是一个 winform)
不幸的是,当我按下按钮(在功能区内)时,没有任何反应。
Ribbon.cs中的代码:
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Form1 formObj = new Form1();
formObj.FormBorderStyle = FormBorderStyle.FixedDialog;
formObj.MaximizeBox = false;
formObj.MinimizeBox = false;
formObj.StartPosition = FormStartPosition.CenterScreen;
//formObj.ShowDialog();
formObj.Show();
}
代码在调试解决方案时运行良好。
我搜索过,但没有找到任何相关内容。这可能是什么问题,或者我遗漏了什么?
此致,
安克
很可能您的表单显示在 Outlook window 后面。要使其在 Outlook windows 之上可见,您必须指定父 window 句柄。您可以通过将 Outlook window 实例(如 Explorer 或 Inspector)投射到 IOLEWindow 接口并使用 IOleWindow::GetWindow 方法来检索它,该方法检索参与就地激活的 windows 之一的句柄(框架、文档、父对象或就地对象 window)。
Show or ShowDialog
method accepts an instance of the IWin32Window 接口代表您的父 window 句柄。
/// <summary>
/// Implemented and used by containers and objects to obtain window handles
/// and manage context-sensitive help.
/// </summary>
/// <remarks>
/// The IOleWindow interface provides methods that allow an application to obtain
/// the handle to the various windows that participate in in-place activation,
/// and also to enter and exit context-sensitive help mode.
/// </remarks>
[ComImport]
[Guid("00000114-0000-0000-C000-000000000046")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleWindow
{
/// <summary>
/// Returns the window handle to one of the windows participating in in-place activation
/// (frame, document, parent, or in-place object window).
/// </summary>
/// <param name="phwnd">Pointer to where to return the window handle.</param>
void GetWindow (out IntPtr phwnd) ;
/// <summary>
/// Determines whether context-sensitive help mode should be entered during an
/// in-place activation session.
/// </summary>
/// <param name="fEnterMode"><c>true</c> if help mode should be entered;
/// <c>false</c> if it should be exited.</param>
void ContextSensitiveHelp ([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode) ;
}
public IWin32Window getWindowHandle()
{
dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
IOleWindow win = activeWindow as IOleWindow;
window = win.GetWindow();
IWin32Window wind = Control.FromHandle(window);
return wind;
}
// and pass it to the Show method
form.Show(getWindowHandle());
我遇到了这个问题。
实际上我有一个 win form 的依赖项(Materialskin.dll),它被排除在检测到的依赖项之外(在安装项目中),如教程中所述。
我仅将 Materialskin.dll 的排除 属性 值更改为 false 并重建解决方案。
成功安装创建的 msi 包后,插件运行正常。
我已经使用 Visual Studio 安装程序项目(跟随 this link)和 C# 部署了 Outlook 加载项。
安装程序已正确安装 (.msi),我可以在“选项”->“加载项”中看到它,还可以通过控件看到功能区。(这是一个 winform)
不幸的是,当我按下按钮(在功能区内)时,没有任何反应。
Ribbon.cs中的代码:
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Form1 formObj = new Form1();
formObj.FormBorderStyle = FormBorderStyle.FixedDialog;
formObj.MaximizeBox = false;
formObj.MinimizeBox = false;
formObj.StartPosition = FormStartPosition.CenterScreen;
//formObj.ShowDialog();
formObj.Show();
}
代码在调试解决方案时运行良好。
我搜索过,但没有找到任何相关内容。这可能是什么问题,或者我遗漏了什么?
此致, 安克
很可能您的表单显示在 Outlook window 后面。要使其在 Outlook windows 之上可见,您必须指定父 window 句柄。您可以通过将 Outlook window 实例(如 Explorer 或 Inspector)投射到 IOLEWindow 接口并使用 IOleWindow::GetWindow 方法来检索它,该方法检索参与就地激活的 windows 之一的句柄(框架、文档、父对象或就地对象 window)。
Show or ShowDialog
method accepts an instance of the IWin32Window 接口代表您的父 window 句柄。
/// <summary>
/// Implemented and used by containers and objects to obtain window handles
/// and manage context-sensitive help.
/// </summary>
/// <remarks>
/// The IOleWindow interface provides methods that allow an application to obtain
/// the handle to the various windows that participate in in-place activation,
/// and also to enter and exit context-sensitive help mode.
/// </remarks>
[ComImport]
[Guid("00000114-0000-0000-C000-000000000046")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleWindow
{
/// <summary>
/// Returns the window handle to one of the windows participating in in-place activation
/// (frame, document, parent, or in-place object window).
/// </summary>
/// <param name="phwnd">Pointer to where to return the window handle.</param>
void GetWindow (out IntPtr phwnd) ;
/// <summary>
/// Determines whether context-sensitive help mode should be entered during an
/// in-place activation session.
/// </summary>
/// <param name="fEnterMode"><c>true</c> if help mode should be entered;
/// <c>false</c> if it should be exited.</param>
void ContextSensitiveHelp ([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode) ;
}
public IWin32Window getWindowHandle()
{
dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
IOleWindow win = activeWindow as IOleWindow;
window = win.GetWindow();
IWin32Window wind = Control.FromHandle(window);
return wind;
}
// and pass it to the Show method
form.Show(getWindowHandle());
我遇到了这个问题。
实际上我有一个 win form 的依赖项(Materialskin.dll),它被排除在检测到的依赖项之外(在安装项目中),如教程中所述。
我仅将 Materialskin.dll 的排除 属性 值更改为 false 并重建解决方案。
成功安装创建的 msi 包后,插件运行正常。