예제 #1
0
        public static void DisableControlBox(this Window window)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);

            Int64 windowLong = WindowClass.GetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE);

            WindowClass.SetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE, (Int32)(windowLong & ~WindowStyles.WS_SYSMENU));
        }
예제 #2
0
        public static void DisableMinimizeBox(this Window window)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);

            Int64 windowLong = WindowClass.GetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE);

            WindowClass.SetWindowLong(windowInteropHelper.EnsureHandle(), WindowClass.GWL_STYLE, (Int32)(windowLong & ~WindowStyles.WS_MINIMIZEBOX));
        }
예제 #3
0
        public Overlay(bool clickThrough)
        {
            this.m_clickThrough = clickThrough;

            InitializeComponent();
            this.DataContext = OverlayModel.Instance;

            var interop = new WindowInteropHelper(this);

            interop.EnsureHandle();

            var hwnd          = interop.Handle;
            var extendedStyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE);

            if (clickThrough)
            {
                extendedStyle |= NativeMethods.WS_EX_TRANSPARENT;
            }

            extendedStyle |= NativeMethods.WS_EX_NOACTIVATE;

            NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE, extendedStyle);

            this.m_timer       = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Dispatcher);
            this.m_timer.Tick += (ls, le) =>
            {
                try
                {
                    this.Hide();
                }
                catch
                { }
            };
        }
예제 #4
0
        private void SwitchVideoPanel(bool bOn)
        {
            var _linphone = ServiceManager.Instance.LinphoneService;

            if (_linphone != null)
            {
                if (!bOn)
                {
                    _linphone.SetVideoCallWindowHandle(IntPtr.Zero, true);
                }
                else
                {
                    var source = GetWindow(this);
                    if (source != null)
                    {
                        var    wih  = new WindowInteropHelper(source);
                        IntPtr hWnd = wih.EnsureHandle();
                        if (hWnd != IntPtr.Zero)
                        {
                            _linphone.SetVideoCallWindowHandle(hWnd);
                        }
                    }
                }
            }
        }
예제 #5
0
        private void SwitchPreviewPanel(bool bOn)
        {
            var _linphone = ServiceManager.Instance.LinphoneService;

            if (_linphone == null)
            {
                return;
            }
            if (!bOn)
            {
                if (ResetNativePreviewHandle)
                {
                    _linphone.SetVideoPreviewWindowHandle(IntPtr.Zero, true);
                }
            }
            else
            {
                _linphone.SetPreviewVideoSizeByName("cif");
                var source = GetWindow(this);
                if (source != null)
                {
                    var wih = new WindowInteropHelper(source);
                    if (wih.Handle != IntPtr.Zero)
                    {
                        IntPtr hWnd = wih.EnsureHandle();

                        if (hWnd != IntPtr.Zero)
                        {
                            _linphone.SetVideoPreviewWindowHandle(hWnd);
                        }
                    }
                }
                ResetNativePreviewHandle = true;
            }
        }
        void CtrlDef_OnExecute(NameValueMap Context)
        {
            wpfWindow = new PluginWindow(m_inventorApplication, "{880b4435-f9c2-4c5e-b234-d543a20b5c36}");

            // Could be a good idea to set the owner for this window
            // especially if it was modeless as mentioned in this article:
            var helper = new WindowInteropHelper(wpfWindow);

            helper.EnsureHandle();
            //helper.Owner = new IntPtr(m_inventorApplication.MainFrameHWND);
            //wpfWindow.Show();

            var uimanager = m_inventorApplication.UserInterfaceManager;

            //Create window if missing
            if (myDockableWindow == null)
            {
                myDockableWindow = uimanager.DockableWindows.Add("{880b4435-f9c2-4c5e-b234-d543a20b5c36}", "URDF", "URDF converter");
            }

            if (!myDockableWindow.IsCustomized)
            {
                myDockableWindow.DockingState = DockingStateEnum.kFloat;
                myDockableWindow.Move(0, 0, myDockableWindow.Height, myDockableWindow.Width);
            }

            myDockableWindow.AddChild(helper.Handle);

            wpfWindow.Show();
            myDockableWindow.Visible = true;
            //wpfWindow.Show();
        }
예제 #7
0
        private HotkeyManager()
        {
            var helper = new WindowInteropHelper(this);

            helper.EnsureHandle();
            Closing += OnClosing;
        }
예제 #8
0
        public static void SetAccentPolicy(Window window, AccentPolicy accentPolicy)
        {
            var windowInteropHelper = new WindowInteropHelper(window);
            var hWnd = windowInteropHelper.EnsureHandle();

            SetAccentPolicy(hWnd, accentPolicy);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowInteropHelper wh = new WindowInteropHelper(this);

            wh.EnsureHandle();
            IntPtr hwnd = wh.Handle;

            KeyboardInput.CreateDevice(hwnd);
            MouseInput.CreateDevice(hwnd);

            WorldEditor.Controls.ObjectWindow w = new Controls.ObjectWindow();
            Window owner = Window.GetWindow(this);

            w.Owner                 = owner;
            w.ShowInTaskbar         = false;
            w.Width                 = 400;
            w.Height                = 500;
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
            w.Left  = owner.Width - 400;
            w.Top   = owner.Top + 60;
            w.Title = "Object window";
            w.Show();

            WorldEditor.Controls.CellView w2 = new Controls.CellView();
            w2.Owner                 = owner;
            w2.ShowInTaskbar         = false;
            w2.Width                 = 450;
            w2.Height                = 300;
            w2.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
            w2.Left  = owner.Width - 500;
            w2.Top   = owner.Top + 700;
            w2.Title = "Cell view";
            w2.Show();
        }
예제 #10
0
        /// <summary>
        /// init and register default hotkeys
        /// </summary>
        /// <param name="_this">Mainwindown object</param>
        public static void initHotkeys(Window _this)
        {
            var helper = new WindowInteropHelper(_this);

            _source = HwndSource.FromHwnd(helper.EnsureHandle());
            _source.AddHook(HwndHook);
        }
예제 #11
0
        /// <inheritdoc />
        protected override void OnAttached()
        {
            var interopHelper = new WindowInteropHelper(AssociatedObject);

            interopHelper.EnsureHandle();
            NativeMethods.SetWindowAppId(interopHelper.Handle, ApplicationID);
        }
예제 #12
0
        public MainWindow(bool hasStartupArgs = false, string[] startupArgs = null)
        {
            _isInitializing              = true;
            _hasStartupArgs              = hasStartupArgs;
            _startupArgs                 = startupArgs;
            _pipeServer                  = new AsyncPipeServer();
            _pipeServer.MessageRecieved += new ServerMessage(MessageRecievedHandler);
            InitializeComponent();
            ClippySettings.Instance.InitializeSettings();
            ClipDataManager.Instance.ItemsChanged += ItemsChangedHandler;

            SetupWindow();
            Action hotkeyPressed = GlobalHotkeyPressed;
            var    interopHelper = new WindowInteropHelper(this);

            interopHelper.EnsureHandle();
            HotKeyHelper.Instance.Initialize(interopHelper.Handle, hotkeyPressed);

            LoadItemsList();
            ApplySettings();
            string pipeName = StaticHelper.GetPipeName();

            _pipeServer.Listen(pipeName);
            _isInitializing = false;
        }
예제 #13
0
        /// <summary>
        /// Passes MainWindow handle to clipboard helper for setting up later.
        /// </summary>
        private void InitializeClipboard()
        {
            var helper = new WindowInteropHelper(this);

            _clipboard.InitializeListener(HwndSource.FromHwnd(helper.EnsureHandle()));
            _clipboard.ClipboardChanged += QueryAppraisalAsync;
        }
예제 #14
0
        public MainWindow(MainWindowViewModel viewModel, CommandRunner commandRunner, ConfigurationManager configurationManager, TranslationService translationService, DynamicHttpClientProvider dynamicHttpClientProvider)
        {
            this.viewModel            = viewModel;
            this.commandRunner        = commandRunner;
            this.configurationManager = configurationManager;
            DataContext = viewModel;
            InitializeComponent();
            var helper = new WindowInteropHelper(this);

            WindowHandleStore.Handle = helper.EnsureHandle();
            appConfig = configurationManager.Load(() => new AppConfig(translationService.DefaultLanguage));
            if (!translationService.Load(appConfig.Language))
            {
                translationService.Load(translationService.DefaultLanguage);
            }
            ViewModel.Model.MainContent = ApplicationContext.Global.Resolve <GeneralPanel>();
            if (appConfig.ServerUrl != null)
            {
                var uri = new Uri($"http://{appConfig.ServerUrl}/api/");
                dynamicHttpClientProvider.SetBaseAddress(uri);
                if (appConfig.AutoConnect)
                {
                    // TODO autoconnect
                }
            }
            if (!appConfig.Minimized)
            {
                Show();
            }
        }
예제 #15
0
            public static bool SetBlurState(Window window, bool enabled)
            {
                try
                {
                    WindowInteropHelper interopHelper = new WindowInteropHelper(window);
                    IntPtr hWnd = interopHelper.EnsureHandle();

                    using (HwndSource hWndSource = HwndSource.FromHwnd(hWnd))
                    {
                        hWndSource.CompositionTarget.BackgroundColor = Colors.Transparent;

                        DWM_BLURBEHIND blurBehindParameters = new DWM_BLURBEHIND
                        {
                            dwFlags  = DwmBlurBehindFlags.DWM_BB_ENABLE,
                            fEnable  = true,
                            hRgnBlur = IntPtr.Zero
                        };

                        return(DwmEnableBlurBehindWindow(hWnd, ref blurBehindParameters).ToInt32() != 0);
                    }
                }
                catch (DllNotFoundException)
                {
                    return(false);
                }
            }
예제 #16
0
        // Helper

        private static IntPtr GetWindowHwnd(Window window)
        {
            var tmp = new WindowInteropHelper(window);

            tmp.EnsureHandle();
            return(new WindowInteropHelper(window).Handle);
        }
예제 #17
0
        public IPWindow()
        {
            this.InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            this.Title = "DataTools Interop Library Test Project";

            this.Loaded += IPWindow_Loaded;

            this.Closing += IPWindow_Closing;

            Quit.Click += Quit_Click;

            ShowPrg.Click     += ShowPrg_Click;
            ShowHw.Click      += ShowHw_Click;
            ShowFS.Click      += ShowFS_Click;
            ShowHID.Click     += ShowHID_Click;
            ShowSysInfo.Click += ShowSysInfo_Click;
            ShowColor.Click   += ShowColor_Click;
            ShowIcon.Click    += ShowIcon_Click;

            AdapterList.SelectionChanged += AdapterList_SelectionChanged;


            var helper = new WindowInteropHelper(this);

            helper.EnsureHandle();

            listener = new HardwareListener(helper.Handle);
            listener.HardwareChange += Listener_HardwareChange;
        }
예제 #18
0
        internal static void EnableBlur(MainWindow window)
        {
            var windowHelper = new WindowInteropHelper(window);

            windowHelper.EnsureHandle();

            var accent           = new AccentPolicy();
            var accentStructSize = Marshal.SizeOf(accent);

            accent.AccentState   = AccentState.ACCENT_ENABLE_BLURBEHIND;
            accent.AccentFlags   = (int)(AccentEdges.Left | AccentEdges.Top);
            accent.GradientColor = 0x3f00FF00;

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new WindowCompositionAttributeData
            {
                Attribute  = WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr
            };

            SetWindowCompositionAttribute(windowHelper.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
예제 #19
0
        public BasicSettingsData(System.Windows.Controls.TextBox processTextfield)
        {
            var helper = new WindowInteropHelper(Application.Current.MainWindow);

            helper.EnsureHandle();  //get a handle witthout the need to show the window
            hotkeyListener = new Hotkey.HotkeyListener(helper.Handle);
            hotkeyListener?.RegisterHotKey(HotkeyMod1._Value | HotkeyMod2._Value, HotkeyKey._Value);

            this.bot = new Bot.Bot(new Input.Keyboard.User32_SendInput_VirtualKeycode());
            hotkeyListener.OnHotKeyPressed += () => {
                if (this.IsBotRunning)
                {
                    bot.Stop();
                }
                else
                {
                    bot.Start("\r" + this.HotkeyAction + "\r");
                }

                this.IsBotRunning = !this.IsBotRunning;
            };

            Application.Current.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
            procChecker = new Timer(checkProcess, null, -1, -1); // init timer, but don`t start
            processTextfield.IsVisibleChanged += DependentUIElement_IsVisibleChanged;
            processTextfield.KeyUp            += (a, b) => { procChecker.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)); };
        }
예제 #20
0
        private void SetWindowAccent(Window w, AccentState state)
        {
            var windowHelper = new WindowInteropHelper(w);

            windowHelper.EnsureHandle();

            var accent = new AccentPolicy {
                AccentState = state
            };
            var accentStructSize = Marshal.SizeOf(accent);

            var accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            var data = new WindowCompositionAttributeData
            {
                Attribute  = WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr
            };

            SetWindowCompositionAttribute(windowHelper.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
예제 #21
0
        private PipelineElements CreatePipeline()
        {
            PipelineElements pipe = new PipelineElements();

            pendingPipeline = pipe;

            pipe.pipeline  = new Pipeline();
            pipe.RTSP      = (Bin)ElementFactory.Make("rtspsrc");
            pipe.Depay     = ElementFactory.Make("rtpvrawdepay");
            pipe.VideoSink = ElementFactory.Make("d3dvideosink");

            Window window           = GetWindow(this);
            WindowInteropHelper wih = new WindowInteropHelper(this);

            wih.EnsureHandle(); // Generate Window Handle if current HWND is NULL (always occurs because background window)
            pipe.overlay = new VideoOverlayAdapter(pipe.VideoSink.Handle);
            pipe.overlay.WindowHandle = wih.Handle;

            pipe.pipeline["message-forward"] = true;
            pipe.RTSP["location"]            = "rtsp://" + StreamName;
            pipe.RTSP["latency"]             = BufferSizeMs;

            pipe.pipeline.Add(pipe.RTSP, pipe.Depay, pipe.VideoSink);
            pipe.RTSP.PadAdded += RTSPPadAdded;
            pipe.RTSP.Link(pipe.Depay);
            pipe.Depay.Link(pipe.VideoSink);

            pipe.pipeline.SetState(State.Null);

            return(pipe);
        }
        bool ILifeSpanHandler.OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            //Set newBrowser to null unless your attempting to host the popup in a new instance of ChromiumWebBrowser
            newBrowser = null;

            var chromiumWebBrowser = (ChromiumWebBrowser)browserControl;

            ChromiumWebBrowser chromiumBrowser = null;

            var windowX      = (windowInfo.X == int.MinValue) ? double.NaN : windowInfo.X;
            var windowY      = (windowInfo.Y == int.MinValue) ? double.NaN : windowInfo.Y;
            var windowWidth  = (windowInfo.Width == int.MinValue) ? double.NaN : windowInfo.Width;
            var windowHeight = (windowInfo.Height == int.MinValue) ? double.NaN : windowInfo.Height;

            chromiumWebBrowser.Dispatcher.Invoke(() =>
            {
                var owner       = Window.GetWindow(chromiumWebBrowser);
                chromiumBrowser = new ChromiumWebBrowser
                {
                    Address = targetUrl,
                };

                chromiumBrowser.SetAsPopup();
                chromiumBrowser.LifeSpanHandler = this;

                var popup = new Window
                {
                    Left    = windowX,
                    Top     = windowY,
                    Width   = windowWidth,
                    Height  = windowHeight,
                    Content = chromiumBrowser,
                    Owner   = owner,
                    Title   = targetFrameName
                };

                var windowInteropHelper = new WindowInteropHelper(popup);
                //Create the handle Window handle (In WPF there's only one handle per window, not per control)
                var handle = windowInteropHelper.EnsureHandle();

                //The parentHandle value will be used to identify monitor info and to act as the parent window for dialogs,
                //context menus, etc. If parentHandle is not provided then the main screen monitor will be used and some
                //functionality that requires a parent window may not function correctly.
                windowInfo.SetAsWindowless(handle);

                popup.Closed += (o, e) =>
                {
                    var w = o as Window;
                    if (w != null && w.Content is IWebBrowser)
                    {
                        (w.Content as IWebBrowser).Dispose();
                        w.Content = null;
                    }
                };
            });

            newBrowser = chromiumBrowser;

            return(false);
        }
예제 #23
0
파일: App.xaml.cs 프로젝트: garcia/unicodex
        private IntPtr getMainWindowHwnd()
        {
            var windowInteropHelper = new WindowInteropHelper(MainWindow);

            windowInteropHelper.EnsureHandle();
            return((IntPtr)windowInteropHelper.Handle.ToInt32());
        }
예제 #24
0
        public static void AttachToDesktop(Window window)
        {
            var interop      = new WindowInteropHelper(window);
            var windowHandle = interop.EnsureHandle();

            if (windowHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Window handle is zero.");
            }
            var handle1 = FindWindow("Progman", null);
            var handle2 = FindWindowEx(handle1, IntPtr.Zero, "SHELLDLL_DefVIew", null);
            var handle3 = FindWindowEx(handle2 == IntPtr.Zero ? handle1 : handle2, IntPtr.Zero, "SysListView32", null);

            var desktopHandle = handle3 == IntPtr.Zero ?
                                (handle2 == IntPtr.Zero ? handle1 : handle2) :
                                handle3;

            LogWin32Error($"FindWindow error code");

            if (desktopHandle == IntPtr.Zero)
            {
                throw new InvalidOperationException("Desktop handle is zero.");
            }

            SetParent(windowHandle, desktopHandle);

            LogWin32Error($"SetParent error code");
        }
예제 #25
0
        public MainWindow()
        {
            InitializeComponent();

            helper = new WindowInteropHelper(this);

            ViewModel = new MainWindowViewModel();
            ViewModel.ShowNotification = (title, message, icon) => notifyIcon.ShowBalloonTip(3000, title, message, icon);

            Closing += OnClosing;

            Loaded += (sender, args) =>
            {
                helper.EnsureHandle();
                Win32Api.BringToFront(helper.Handle);
            };

            Activated += (sender, args) =>
            {
                helper.EnsureHandle();
                Win32Api.BringToFront(helper.Handle);
            };

            notifyIcon = new NotifyIcon();

            StreamResourceInfo resourceStream = Application.GetResourceStream(new Uri("pack://application:,,,/App.ico"));

            if (resourceStream != null)
            {
                using (Stream iconStream = resourceStream.Stream)
                {
                    notifyIcon.Icon = new System.Drawing.Icon(iconStream);
                }
            }
            notifyIcon.Visible     = false;
            notifyIcon.MouseClick += OnNotifyIconClick;
            notifyIcon.Text        = ViewModel.Update.ProductAndVersion;

            //notifyIcon.Click += OnNotifyIconClick;

            contextMenu = new ContextMenu();
            var exitMenuItem = new MenuItem("E&xit", (sender, args) => Application.Current.Shutdown());

            contextMenu.MenuItems.Add(exitMenuItem);

            notifyIcon.ContextMenu = contextMenu;
        }
예제 #26
0
        public void Attach(WebView webView)
        {
            webView.Closed += webView_Closed;
            WindowInteropHelper helper = new WindowInteropHelper(this);

            helper.EnsureHandle();
            webView.ShowDevTools(helper.Handle);
        }
예제 #27
0
        public MainWindow(CommandRunner commandRunner, InputDeviceManager inputDeviceManager)
        {
            this.commandRunner = commandRunner;
            InitializeComponent();
            var helper = new WindowInteropHelper(this);

            WindowHandleStore.Handle = helper.EnsureHandle();
        }
예제 #28
0
        public MainWindow()
        {
            InitializeComponent();

            var interopHelper = new WindowInteropHelper(this);

            Handle = interopHelper.EnsureHandle();
        }
        protected internal void BindRawInputKeyboard(System.Windows.Window winformControl)
        {
            var interopHelper = new WindowInteropHelper(winformControl);

            interopHelper.EnsureHandle();
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None, interopHelper.Handle);
            SharpDX.RawInput.Device.KeyboardInput += DeviceOnKeyboardInput;
        }
예제 #30
0
        void OnSourceInitialized(object sender, EventArgs e)
        {
            // Hook the window proc so that we can get the disc-change notifications.
            var interopHelper = new WindowInteropHelper(this);

            this.interopSource = HwndSource.FromHwnd(interopHelper.EnsureHandle());
            this.interopSource.AddHook(MessageHook);
        }