Exemplo n.º 1
0
        /// <summary>
        /// Try to detect the associated main window from a document has an expanded ribbon ui
        /// </summary>
        /// <param name="document">target document</param>
        /// <param name="throwExceptionIfFailed">throw exception if its failed to detect, otherwise returns false</param>
        /// <returns>true if ribbon is expanded, otherwise false</returns>
        public bool TryGetRibbonIsExpanded(WordApi.Document document, bool throwExceptionIfFailed)
        {
            if (null == document)
                throw new ArgumentNullException("document");
            int handle = TryGetMainWindowHandle(document);
            if (handle <= 0)
            {
                if (throwExceptionIfFailed)
                    throw new NetRuntimeSystem.ComponentModel.Win32Exception();
                else
                    return false;                
            }

            NetOffice.Tools.WndUtils.ChildWindowEnumerator childEnumerator = new NetOffice.Tools.WndUtils.ChildWindowEnumerator(new IntPtr(handle), "Ribbon");
            IntPtr[] handles = childEnumerator.EnumerateWindows(2000);
            if (null != handles && handles.Length > 0)
            {
                NetRuntimeSystem.Drawing.Rectangle rect = NetOffice.Tools.WndUtils.WindowEnumerator.GetWindowRect(handles[0]);
                return rect.Height >= _ribbonHeightExpandedLimit;
            }
            else
            {
                if (throwExceptionIfFailed)
                    throw new NetRuntimeSystem.Runtime.InteropServices.ExternalException();
                else
                    return false;                
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to detect the associated main window from a document has an expanded ribbon ui
        /// </summary>
        /// <param name="document">target document</param>
        /// <param name="throwExceptionIfFailed">throw exception if its failed to detect, otherwise returns false</param>
        /// <returns>true if ribbon is expanded, otherwise false</returns>
        public bool TryGetRibbonIsExpanded(WordApi.Document document, bool throwExceptionIfFailed)
        {
            if (null == document)
            {
                throw new ArgumentNullException("document");
            }
            int handle = TryGetMainWindowHandle(document);

            if (handle <= 0)
            {
                if (throwExceptionIfFailed)
                {
                    throw new NetRuntimeSystem.ComponentModel.Win32Exception();
                }
                else
                {
                    return(false);
                }
            }

            NetOffice.Tools.WndUtils.ChildWindowEnumerator childEnumerator = new NetOffice.Tools.WndUtils.ChildWindowEnumerator(new IntPtr(handle), "Ribbon");
            IntPtr[] handles = childEnumerator.EnumerateWindows(2000);
            if (null != handles && handles.Length > 0)
            {
                NetRuntimeSystem.Drawing.Rectangle rect = NetOffice.Tools.WndUtils.WindowEnumerator.GetWindowRect(handles[0]);
                return(rect.Height >= _ribbonHeightExpandedLimit);
            }
            else
            {
                if (throwExceptionIfFailed)
                {
                    throw new NetRuntimeSystem.Runtime.InteropServices.ExternalException();
                }
                else
                {
                    return(false);
                }
            }
        }