private static void SetBeepInternal(RichTextBox rtb, bool beepOn)
    {
        const Int32 WM_USER            = 0x400;
        const Int32 EM_GETOLEINTERFACE = WM_USER + 60;
        const Int32 COMFalse           = 0;
        const Int32 COMTrue            = ~COMFalse; // -1

        ITextServices textServices = null;

        // retrieve the rtb's OLEINTERFACE using the Interop Marshaller to cast it as an ITextServices
        // The control calls the AddRef method for the object before returning, so the calling application must call the Release method when it is done with the object.
        SendMessage(new HandleRef(rtb, rtb.Handle), EM_GETOLEINTERFACE, IntPtr.Zero, ref textServices);
        textServices.OnTxPropertyBitsChange(TXTBIT.ALLOWBEEP, beepOn ? COMTrue : COMFalse);
        Marshal.ReleaseComObject(textServices);
    }
Пример #2
0
        public TextServices32(ITextServices services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            _vtable = new ITextServicesVTable();
            _unk    = Marshal.GetIUnknownForObject(services);
            var vtablePtr = Marshal.ReadIntPtr(_unk);

            Marshal.PtrToStructure(vtablePtr, _vtable);
            _setText                = Marshal.GetDelegateForFunctionPointer <TxSetTextFn>(_vtable.TxSetText);
            _inPlaceActivate        = Marshal.GetDelegateForFunctionPointer <OnTxInPlaceActivateFn>(_vtable.OnTxInPlaceActivate);
            _uIActivate             = Marshal.GetDelegateForFunctionPointer <OnTxUIActivateFn>(_vtable.OnTxUIActivate);
            _onTxPropertyBitsChange = Marshal.GetDelegateForFunctionPointer <OnTxPropertyBitsChangeFn>(_vtable.OnTxPropertyBitsChange);
            _txSendMessage          = Marshal.GetDelegateForFunctionPointer <TxSendMessageFn>(_vtable.TxSendMessage);
            _txDrawD2D              = Marshal.GetDelegateForFunctionPointer <TxDrawD2DFn>(_vtable.TxDrawD2D);
            _txGetNaturalSize2      = Marshal.GetDelegateForFunctionPointer <TxGetNaturalSize2Fn>(_vtable.TxGetNaturalSize2);
        }
 private extern static IntPtr SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, ref ITextServices lParam);
Пример #4
0
 public HealthController(IUserServices userservices, ITextServices textservices)
 {
     this._userservices = userservices;
     this._textservices = textservices;
 }