當前位置: 首頁>>代碼示例>>C#>>正文


C# Interop.HwndSource類代碼示例

本文整理匯總了C#中System.Windows.Interop.HwndSource的典型用法代碼示例。如果您正苦於以下問題:C# HwndSource類的具體用法?C# HwndSource怎麽用?C# HwndSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HwndSource類屬於System.Windows.Interop命名空間,在下文中一共展示了HwndSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HorizontalMouseScrollHelper

 public HorizontalMouseScrollHelper(ScrollViewer scrollviewer, DependencyObject d)
 {
     scrollViewer = scrollviewer;
     source = (HwndSource)PresentationSource.FromDependencyObject(d);
     if (source != null)
         source.AddHook(WindowProc);
 }
開發者ID:jayhill,項目名稱:FluentFilters,代碼行數:7,代碼來源:HorizontalMouseScrollHelper.cs

示例2: ClipboardListenerBasic

 // Constructor
 public ClipboardListenerBasic(Window wnd,EventHandler handler=null)
 {
     WindowListener=wnd;
     Source=PresentationSource.FromVisual(wnd) as HwndSource;
     ClipboardUpdated=handler;
     Listening=false;
 }
開發者ID:DP458,項目名稱:Clipboard_Watcher,代碼行數:8,代碼來源:BasicRealization.cs

示例3: Initialize3D

		private void Initialize3D()
		{
			HwndSource hwnd = new HwndSource(0, 0, 0, 0, 0, "D3", IntPtr.Zero);

			pp.SwapEffect = SwapEffect.Discard;
			pp.DeviceWindowHandle = hwnd.Handle;
			pp.Windowed = true;
			pp.BackBufferWidth = (int)ActualWidth;
			pp.BackBufferHeight = (int)ActualHeight;
			pp.BackBufferFormat = Format.X8R8G8B8;

			try
			{
				var direct3DEx = new Direct3DEx();
				direct3D = direct3DEx;
				device = new DeviceEx(direct3DEx, 0, DeviceType.Hardware, hwnd.Handle, CreateFlags.HardwareVertexProcessing, pp);
			}
			catch
			{
				direct3D = new Direct3D();
				device = new Device(direct3D, 0, DeviceType.Hardware, hwnd.Handle, CreateFlags.HardwareVertexProcessing, pp);
			}

			System.Windows.Media.CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
		}
開發者ID:XiBeichuan,項目名稱:hydronumerics,代碼行數:25,代碼來源:DirectXHost.cs

示例4: OnSourceInitialized

 protected override void OnSourceInitialized(EventArgs e)
 {
     _hwndSource = (HwndSource) PresentationSource.FromVisual(this);
     _hwndSource?.AddHook(WndProcHook);
     UpdateWindowStyle();
     base.OnSourceInitialized(e);
 }
開發者ID:vebin,項目名稱:ModernApplicationFramework,代碼行數:7,代碼來源:WindowBase.cs

示例5: HotKeyManager

 //private Window window;
 //stack overflow http://stackoverflow.com/questions/2450373/set-global-hotkeys-using-c-sharp
 //private class Window : NativeWindow, IDisposable
 //{
 //    private static int WM_HOTKEY = 0x0312;
 //    private IHotKeyOwner owner;
 //    public Window(IHotKeyOwner owner)
 //    {
 //        this.owner = owner;
 //        // create the handle for the window.
 //        this.CreateHandle(new CreateParams());
 //    }
 //    /// <summary>
 //    /// Overridden to get the notifications.
 //    /// </summary>
 //    /// <param name="m"></param>
 //    protected override void WndProc(ref Message m)
 //    {
 //        base.WndProc(ref m);
 //        // check if we got a hot key pressed.
 //        if (m.Msg == WM_HOTKEY)
 //        {
 //            MessageBox.Show("asdasd");
 //            // get the keys.
 //            Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
 //            ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
 //            owner.HotKeyPressed(0);
 //        }
 //    }
 //    #region IDisposable Members
 //    public void Dispose()
 //    {
 //        this.DestroyHandle();
 //    }
 //    #endregion
 //}
 public HotKeyManager(IHotKeyOwner owner, IntPtr handle)
 {
     this.owner = owner;
     this.hook = new HwndSourceHook(WndProc);
     this.hwndsource = HwndSource.FromHwnd(handle);
     hwndsource.AddHook(hook);
 }
開發者ID:allisharp,項目名稱:as_autoclicker,代碼行數:43,代碼來源:HotKeyManager.cs

示例6: Start

		private void Start()
		{
			if (hwndSource != null)
				return;


			var window = Application.Current.Windows[0];
			Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
			{

				if (!window.IsInitialized)
					window.SourceInitialized += (sender, args) =>
					{
						hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
						hwndSource.AddHook(WndProc);
					};
				else
				{
					hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
					hwndSource.AddHook(WndProc);
				}
			}));



		}
開發者ID:heinzsack,項目名稱:DEV,代碼行數:26,代碼來源:DeviceChangeDetector.cs

示例7: ClipboardWatcher

 /// <summary>
 /// ClipBoardWatcherクラスを初期化して
 /// クリップボードビューアチェインに登録します。
 /// 使用後は必ずDispose()メソッドを呼び出して下さい。
 /// </summary>
 public ClipboardWatcher(IntPtr handle)
 {
     this.hwndSource = HwndSource.FromHwnd(handle);
     this.hwndSource.AddHook(this.WndProc);
     this.handle = handle;
     this.nextHandle = SetClipboardViewer(this.handle);
 }
開發者ID:yasumo,項目名稱:ClipBoardReplacer,代碼行數:12,代碼來源:ClipboardWatcher.cs

示例8: HwndStylusInputProvider

        internal HwndStylusInputProvider(HwndSource source)
        {
            InputManager inputManager = InputManager.Current;
            StylusLogic stylusLogic = inputManager.StylusLogic;

            IntPtr sourceHandle;

            (new UIPermission(PermissionState.Unrestricted)).Assert();
            try //Blessed Assert this is for RegisterInputManager and RegisterHwndforinput
            {
                // Register ourselves as an input provider with the input manager.
                _site = new SecurityCriticalDataClass<InputProviderSite>(inputManager.RegisterInputProvider(this));

                sourceHandle = source.Handle;
            }
            finally
            {
                UIPermission.RevertAssert();
            }

            stylusLogic.RegisterHwndForInput(inputManager, source);
            _source = new SecurityCriticalDataClass<HwndSource>(source);
            _stylusLogic = new SecurityCriticalDataClass<StylusLogic>(stylusLogic);

            // Enables multi-touch input
            UnsafeNativeMethods.SetProp(new HandleRef(this, sourceHandle), "MicrosoftTabletPenServiceProperty", new HandleRef(null, new IntPtr(MultiTouchEnabledFlag)));
        }
開發者ID:JianwenSun,項目名稱:cc,代碼行數:27,代碼來源:HwndStylusInputProvider.cs

示例9: Recorder

        public Recorder(string fileName, 
            FourCC codec, int quality, 
            int audioSourceIndex, SupportedWaveFormat audioWaveFormat, bool encodeAudio, int audioBitRate)
        {
            System.Windows.Media.Matrix toDevice;
            using (var source = new HwndSource(new HwndSourceParameters()))
            {
                toDevice = source.CompositionTarget.TransformToDevice;
            }

            screenWidth = (int)Math.Round(SystemParameters.PrimaryScreenWidth * toDevice.M11);
            screenHeight = (int)Math.Round(SystemParameters.PrimaryScreenHeight * toDevice.M22);

            // Create AVI writer and specify FPS
            writer = new AviWriter(fileName)
            {
                FramesPerSecond = 10,
                EmitIndex1 = true,
            };

            // Create video stream
            videoStream = CreateVideoStream(codec, quality);
            // Set only name. Other properties were when creating stream,
            // either explicitly by arguments or implicitly by the encoder used
            videoStream.Name = "Screencast";

            if (audioSourceIndex >= 0)
            {
                var waveFormat = ToWaveFormat(audioWaveFormat);

                audioStream = CreateAudioStream(waveFormat, encodeAudio, audioBitRate);
                // Set only name. Other properties were when creating stream,
                // either explicitly by arguments or implicitly by the encoder used
                audioStream.Name = "Voice";

                audioSource = new WaveInEvent
                {
                    DeviceNumber = audioSourceIndex,
                    WaveFormat = waveFormat,
                    // Buffer size to store duration of 1 frame
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;
            }

            screenThread = new Thread(RecordScreen)
            {
                Name = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }
            screenThread.Start();
        }
開發者ID:bobahml,項目名稱:SharpAvi,代碼行數:60,代碼來源:Recorder.cs

示例10: Show

        public void Show(Int32Rect rpRect)
        {
            var rMainWindowHandle = new WindowInteropHelper(App.Current.MainWindow).Handle;

            if (r_HwndSource == null)
            {
                var rParam = new HwndSourceParameters(nameof(ScreenshotToolOverlayWindow))
                {
                    Width = 0,
                    Height = 0,
                    PositionX = 0,
                    PositionY = 0,
                    WindowStyle = 0,
                    UsesPerPixelOpacity = true,
                    HwndSourceHook = WndProc,
                    ParentWindow = rMainWindowHandle,
                };

                r_HwndSource = new HwndSource(rParam) { SizeToContent = SizeToContent.Manual, RootVisual = this };
            }

            var rBrowserWindowHandle = ServiceManager.GetService<IBrowserService>().Handle;

            NativeStructs.RECT rBrowserWindowRect;
            NativeMethods.User32.GetWindowRect(rBrowserWindowHandle, out rBrowserWindowRect);

            var rHorizontalRatio = rBrowserWindowRect.Width / GameConstants.GameWidth;
            var rVerticalRatio = rBrowserWindowRect.Height / GameConstants.GameHeight;
            rpRect.X = (int)(rpRect.X * rHorizontalRatio);
            rpRect.Y = (int)(rpRect.Y * rVerticalRatio);
            rpRect.Width = (int)(rpRect.Width * rHorizontalRatio);
            rpRect.Height = (int)(rpRect.Height * rVerticalRatio);

            NativeMethods.User32.SetWindowPos(r_HwndSource.Handle, IntPtr.Zero, rBrowserWindowRect.Left + rpRect.X, rBrowserWindowRect.Top + rpRect.Y, rpRect.Width, rpRect.Height, NativeEnums.SetWindowPosition.SWP_NOZORDER | NativeEnums.SetWindowPosition.SWP_NOACTIVATE | NativeEnums.SetWindowPosition.SWP_SHOWWINDOW);
        }
開發者ID:amatukaze,項目名稱:IntelligentNavalGun,代碼行數:35,代碼來源:ScreenshotToolOverlayWindow.cs

示例11: OnLoaded

 protected void OnLoaded(object sender, EventArgs e)
 {
     WindowInteropHelper helper = new WindowInteropHelper(this);
     _hwndSource = HwndSource.FromHwnd(helper.Handle);
     _wndProcHandler = new HwndSourceHook(HookHandler);
     _hwndSource.AddHook(_wndProcHandler);
 }
開發者ID:vebin,項目名稱:PhotoBrushProject,代碼行數:7,代碼來源:FloatingWindow.xaml.cs

示例12: HotKeyManager

        /// <summary>
        /// Initializes a new instance of the <see cref="HotKeyManager"/> class.
        /// </summary>
        public HotKeyManager()
        {
            _windowHandleSource = new HwndSource(new HwndSourceParameters());
            _windowHandleSource.AddHook(messagesHandler);

            _registered = new Dictionary<HotKey, int>();
        }
開發者ID:kirmir,項目名稱:GlobalHotKey,代碼行數:10,代碼來源:HotKeyManager.cs

示例13: StartListeningToClipboard

 private void StartListeningToClipboard()
 {
     var lWindowInteropHelper = new WindowInteropHelper(this);
     _HWndSource = HwndSource.FromHwnd(lWindowInteropHelper.Handle);
     _HWndSource.AddHook(WinProc);
     _HWndNextViewer = SetClipboardViewer(_HWndSource.Handle); // set this window as a viewer
 } //
開發者ID:huoxudong125,項目名稱:HQF.Tutorial.WPF,代碼行數:7,代碼來源:MainWindow.xaml.cs

示例14: HotkeyManager

 public HotkeyManager(Window window)
 {
     source = (HwndSource)PresentationSource.FromVisual(window);
     hook = new HwndSourceHook(WndProc);
     source.AddHook(hook);
     ids = new List<int>();
 }
開發者ID:alexhorn,項目名稱:BrightnessControl,代碼行數:7,代碼來源:HotkeyManager.cs

示例15: ShadowedWindow_OnLoaded

    private void ShadowedWindow_OnLoaded(object sender, RoutedEventArgs e)
    {
      hwndSource = PresentationSource.FromVisual((Visual) sender) as HwndSource;

      if (hwndSource != null)
        hwndSource.AddHook(WndProc);
    }
開發者ID:maxschmeling,項目名稱:flamecage,代碼行數:7,代碼來源:ShadowedWindow.cs


注:本文中的System.Windows.Interop.HwndSource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。