コード例 #1
0
 private void Application_WindowActivate(
     Microsoft.Office.Interop.Excel.Workbook Wb,
     Microsoft.Office.Interop.Excel.Window Wn)
 {
     Logger.Info("Application_WindowActivate");
     AttachToCurrentWindow();
 }
コード例 #2
0
        private static ExcelApplication InnerFromHandle(Int32 handle)
        {
            xlWin win = null;
            Int32 hr  = AccessibleObjectFromWindow(handle, DW_OBJECTID, rrid.ToByteArray(), ref win);

            return(new ExcelApplication(win.Application));
        }
コード例 #3
0
ファイル: exEnumClass.cs プロジェクト: Kgrah/Saver
        private static xlApp InnerFromHandle(Int32 handle)
        {
            //assign the handle to be that excel window
            //then grab application object
            xlWin win = null;
            Int32 hr  = AccessibleObjectFromWindow(handle, DW_OBJECTID, rrid.ToByteArray(), ref win);

            return(win.Application);
        }
コード例 #4
0
        /// <summary>
        /// Find all open Excel workbooks in all Excel processes.
        /// </summary>
        /// <returns>List of open Excel Workbooks</returns>
        /// <remarks>
        /// This method might not be that friendly because it keeps references open. Excel might not close until finalizers are forced.
        /// </remarks>
        internal static IList <ExcelWorkbook> GetAllOpenWorkbooks()
        {
            HashSet <IntPtr>     windows   = new HashSet <IntPtr>();
            List <ExcelWorkbook> workbooks = new List <ExcelWorkbook>();
            Guid           windowGuid      = typeof(ExcelWindow).GUID;
            HashSet <uint> processes       = new HashSet <uint>();

            ISet <IntPtr> mainWindows;

            mainWindows = FindAllWindowsForClass(IntPtr.Zero, MainWindowClass);

            // find all main excel windows
            foreach (IntPtr mainWindow in mainWindows)
            {
                // filter out multiple windows in the same process.
                uint processId;
                GetWindowThreadProcessId(mainWindow, out processId);
                if (processes.Contains(processId))
                {
                    continue;
                }
                processes.Add(processId);

                // find first desktop window
                IntPtr desktopWindow = FindWindowEx(mainWindow, IntPtr.Zero, DesktopWindowClass, null);
                if (desktopWindow != IntPtr.Zero)
                {
                    // find first workbook window
                    IntPtr workbookWindow = FindWindowEx(desktopWindow, IntPtr.Zero, WorkbookWindowClass, null);
                    if (workbookWindow != IntPtr.Zero)
                    {
                        ExcelWindow excelWindow = null;

                        if (AccessibleObjectFromWindow(workbookWindow, OBJID_NATIVEOM, ref windowGuid, out excelWindow) >= 0)
                        {
                            ExcelApplication excelApplication;
                            excelApplication = excelWindow.Application;

                            foreach (ExcelWorkbook workbook in excelApplication.Workbooks)
                            {
                                workbooks.Add(workbook);
                            }
                        }
                    }
                }
            }
            return(workbooks);
        }
コード例 #5
0
    public static void GetReferences(ref Microsoft.Office.Interop.Excel.Application _Application, ref Microsoft.Office.Interop.Excel.Workbook _Workbook)
    {
        EnumChildCallback cb;
        // First, get Excel's main window handle.
        int hwnd = (int)Process.GetCurrentProcess().MainWindowHandle;

        // We need to enumerate the child windows to find one that
        // supports accessibility. To do this, instantiate the
        // delegate and wrap the callback method in it, then call
        // EnumChildWindows, passing the delegate as the 2nd arg.
        if (hwnd != 0)
        {
            int hwndChild = 0;
            cb = new EnumChildCallback(EnumChildProc);
            EnumChildWindows(hwnd, cb, ref hwndChild);
            // If we found an accessible child window, call
            // AccessibleObjectFromWindow, passing the constant
            // OBJID_NATIVEOM (defined in winuser.h) and
            // IID_IDispatch - we want an IDispatch pointer
            // into the native object model.
            if (hwndChild != 0)
            {
                const uint OBJID_NATIVEOM = 0xFFFFFFF0;
                Guid       IID_IDispatch  = new Guid(
                    "{00020400-0000-0000-C000-000000000046}");
                Microsoft.Office.Interop.Excel.Window ptr = null;
                int hr = AccessibleObjectFromWindow(
                    hwndChild, OBJID_NATIVEOM, IID_IDispatch.ToByteArray(), ref ptr);
                if (hr >= 0)
                {
                    // If we successfully got a native OM
                    // IDispatch pointer, we can QI this for
                    // an Excel Application (using the implicit
                    // cast operator supplied in the PIA).
                    _Application = ptr.Application;
                    _Workbook    = _Application.ActiveWorkbook;
                }
            }
        }
    }
コード例 #6
0
    private Microsoft.Office.Interop.Excel.Application SearchExcelInterop(Process p)
    {
        Microsoft.Office.Interop.Excel.Window ptr = null;
        int hwnd       = 0;
        int hWndParent = (int)p.MainWindowHandle;

        if (hWndParent == 0)
        {
            throw new ExcelMainWindowNotFoundException();
        }
        EnumChildWindows(hWndParent, EnumChildFunc, ref hwnd);
        if (hwnd == 0)
        {
            throw new ExcelChildWindowNotFoundException();
        }
        int hr = AccessibleObjectFromWindow(hwnd, DW_OBJECTID, rrid.ToByteArray(), ref ptr);

        if (hr < 0)
        {
            throw new AccessibleObjectNotFoundException();
        }
        return(ptr.Application);
    }
コード例 #7
0
 public static extern int AccessibleObjectFromWindow(
       int hwnd, uint dwObjectID, byte[] riid,
       ref Microsoft.Office.Interop.Excel.Window ptr);
コード例 #8
0
ファイル: ExcelAppEvents.cs プロジェクト: chrhodes/Office
 void _ExcelApplication_WindowActivate(Microsoft.Office.Interop.Excel.Workbook Wb, Microsoft.Office.Interop.Excel.Window Wn)
 {
     DisplayInWatchWindow(WindowActivate++, System.Reflection.MethodInfo.GetCurrentMethod().Name);
 }
コード例 #9
0
 private static extern Int32 AccessibleObjectFromWindow(
     Int32 hwnd, UInt32 dwObjectID, Byte[] riid, ref xlWin ptr);
コード例 #10
0
 public AddinWindow(ThisAddIn thisAddIn)
 {
     window = thisAddIn.Application.ActiveWindow;
 }
コード例 #11
0
 private static extern int AccessibleObjectFromWindow(
     IntPtr handle,
     uint id,
     ref Guid iid,
     out ExcelWindow excelWindow);
コード例 #12
0
 private static extern int AccessibleObjectFromWindow(int hwnd, uint dwObjectID, byte[] riid, out xlWin ppvObject);