/// <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 void getWindowHandle()
{
dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
IOleWindow win = activeWindow as IOleWindow;
IntPtr window = IntPtr.Zero;
win.GetWindow(window);
}
2条答案
按热度按时间nqwrtyyt1#
将
Inspector
Outlook对象强制转换到IOleWindow接口(也适用于Explorer
对象),并调用IOleWindow::GetWindow
以获取其HWND
。anauzrmj2#
您可以通过将Outlook窗口示例(如Explorer或Inspector)强制转换到
IOLEWindow
接口并使用IOleWindow::GetWindow方法来检索可用于该函数的窗口句柄,该方法检索参与就地激活的窗口之一(框架,文档,父窗口或就地对象窗口)的句柄。下面是示例代码,显示了如何在Outlook窗口中使用IOLEWindow界面:
字符串