[英]Get outlook Active window handle hwnd in C#
我想在C#中獲取Outlook Active窗口句柄(hwnd)。 我想將其用於將hwnd作為第一個參數的SendMessage()方法。 Outlook已打開且未最小化。 試圖這樣做。。dynamic winHwnd = Globals.ThisAddIn.Application.ActiveWindow(); 不能作為類型不匹配使用。 即使我轉換也不起作用。 有人可以建議我得到這個處理程序嗎。
也許您可以嘗試使用通用方法,方法是使用系統Api FindWindow以其名稱獲取您感興趣的窗口:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = (IntPtr)FindWindow(windowName, null);
從ActiveWindow您可以嘗試:
dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
IntPtr outlookHwnd = new OfficeWin32Window(activeWindow).Handle;
您可能要使用GetActiveWindow api函數。
[DllImport("user32.dll")]
static extern IntPtr GetActiveWindow();
IntPtr handle = GetActiveWindow();
嘗試最小化窗口,以查看是否獲得正確的句柄。
private const int SW_SHOWMINIMIZED = 2;
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow)
ShowWindowAsync(hWnd, SW_SHOWMINIMIZED);
將Inspector對象強制轉換為IOleWindow接口,然后調用IOleWindow :: GetWindow。 Explorer對象也一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.