예제 #1
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        // call this method before allowing access to any TextPattern properties or methods.
        // it ensures that we have an ITextDocument pointer to the richedit control.
        private void EnsureTextDocument()
        {
            // if we don't have a document pointer yet then get one by sending richedit a WM_GETOBJECT message
            // with object id asking for the native OM.
            if (_document == null)
            {
                object obj = null;

                if (UnsafeNativeMethods.AccessibleObjectFromWindow(WindowHandle, NativeMethods.OBJID_NATIVEOM, ref UnsafeNativeMethods.IID_IDispatch, ref obj) != NativeMethods.S_OK)
                {
                    throw new System.NotImplementedException(SR.Get(SRID.NoITextDocumentFromRichEdit));
                }

                // review: - alexsn - This is temp solution which will prevent exception in the case
                //                    when we cannot obtain the ITextDocument from a RichEdit control
                //                    The direct cast does not work for RichEdit20w controls used in MS Office
                //                    Susia will do the real fix
                _document = obj as ITextDocument;
                if (_document == null)
                {
                    // review: proper exception?
                    throw new System.NotImplementedException(SR.Get(SRID.NoITextDocumentFromRichEdit));
                }
            }
        }
예제 #2
0
 public static IAccessible GetAccessibleObject(IntPtr hWnd)
 {
     try {
         Guid      guid         = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
         Object    instance     = null;
         const int OBJID_WINDOW = 0x0;
         int       hResult      = UnsafeNativeMethods.AccessibleObjectFromWindow(hWnd, OBJID_WINDOW, ref guid, ref instance);
         if (hResult != 0 || instance == null)
         {
             return(null);
         }
         return(instance as IAccessible);
     }
     catch {
         return(null);
     }
 }