Esempio n. 1
0
        /// <summary>
        /// Start Flashing the specified Window (form)
        /// </summary>
        /// <param name="form">The Form (Window) to Flash.</param>
        /// <returns></returns>
        public static bool Start(Window window)
        {
            var handle = (HwndSource)HwndSource.FromVisual(window);
            var fi     = Create_FLASHWINFO(handle.Handle, FLASHW_ALL, uint.MaxValue, 0);

            return(FlashWindowEx(ref fi));
        }
Esempio n. 2
0
        protected override void OnOpened(RoutedEventArgs e)
        {
            base.OnOpened(e);
            var hwnd = (HwndSource)HwndSource.FromVisual(this);

            AcrylicHelper.SetBlur(hwnd.Handle, AccentFlagsType.Popup);
        }
 public NoSnapWindow()
 {
     SourceInitialized += delegate {
         var source = HwndSource.FromVisual(this) as HwndSource;
         source.AddHook(SourceHook);
     };
 }
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or
        /// internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            // Call the base
            base.OnApplyTemplate();

            // Fix for WPF
            IntPtr selection = ((HwndSource)HwndSource.FromVisual(this)).Handle;

            // Lock on OpenGL
            lock (this.OpenGL)
            {
                // Create OpenGL
                this.OpenGL.Create(this.OpenGLVersion, this.RenderContextType, 1, 1, 16, selection);
            }

            // Create our fast event args
            this.eventArgsFast = new OpenGLEventArgs(this.OpenGL);

            // Set the most basic OpenGL styles
            this.OpenGL.ShadeModel(OpenGL.GL_SMOOTH);
            this.OpenGL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            this.OpenGL.ClearDepth(1.0f);
            this.OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
            this.OpenGL.DepthFunc(OpenGL.GL_LEQUAL);
            this.OpenGL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);

            // Fire the OpenGL initialised event
            this.OpenGLInitialized?.Invoke(this, this.eventArgsFast);
        }
Esempio n. 5
0
        public override Reply Run <T>(ControlsStorage <T> controls, IDictionary <string, dynamic> args)
        {
            CheckParamExists(args, "element_id");
            CheckValidControlId <T>(args["element_id"], controls);

            DynamicValueReply reply = new DynamicValueReply(-1);

            dynamic c = controls.GetControl(args["element_id"]);

            if (c is Visual)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    HwndSource source = (HwndSource)HwndSource.FromVisual(c);
                    if (source != null)
                    {
                        IntPtr hWnd = source.Handle;
                        reply       = new DynamicValueReply(hWnd.ToInt64());
                    }
                    else
                    {
                        reply = new DynamicValueReply(null);
                    }
                });
            }
            return(reply);
        }
Esempio n. 6
0
        private void btnShowVideoWin_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;

            VideoInWindow dialog = new VideoInWindow(_channel.CallId);

            dialog.Owner = App.Current.MainWindow;
            dialog.ShowDialog();
            return;

            sua_vid_win_info info = new sua_vid_win_info();

            App.SIPUA.GetVidWindowInfo(_channel.CallId, ref info);

            if (info.show == 1)
            {
                App.SIPUA.ShowVideoWindow(_channel.CallId, false);
            }
            else
            {
                App.SIPUA.ShowVideoWindow(_channel.CallId, true);

                MainWindow main = App.Current.MainWindow as MainWindow;
                if (main != null)
                {
                    int top  = ((int)main.Top) + ((int)main.Height) / 2 - info.height / 2;
                    int left = ((int)main.Left) + ((int)main.Width) / 2 - info.width / 2;

                    HwndSource source = (HwndSource)HwndSource.FromVisual(main);
                    IntPtr     hWnd   = source.Handle;
                    //App.SIPUA.SetVideoWindowPos(_channel.CallId, hWnd, left, top);
                }
            }
        }
Esempio n. 7
0
            public static MyTT Create(UIElement content)
            {
                MyTT wnd = new MyTT();

                wnd.Content = content;
                wnd.WindowStartupLocation = WindowStartupLocation.Manual;
                wnd.WindowState           = WindowState.Normal;
                wnd.WindowStyle           = WindowStyle.None;
                wnd.ShowInTaskbar         = false;
                wnd.SizeToContent         = SizeToContent.WidthAndHeight;
                wnd.AllowsTransparency    = true;
                wnd.Background            = System.Windows.Media.Brushes.Transparent;
                wnd.Topmost = true;
                var b = new Binding("DataContext")
                {
                    Source = Application.Current.MainWindow
                };

                BindingOperations.SetBinding(wnd, DataContextProperty, b);
                wnd.MouseEnter += wnd.OnMouseEnter;
                wnd.MouseLeave += (sender, args) => { wnd._gotInside = false;
                                                      wnd.IsOpen     = false; };
                wnd.LostFocus         += (sender, args) => { wnd.IsOpen = false; };
                wnd.IsVisibleChanged  += (sender, args) => wnd.IsOpen = wnd.Visibility == Visibility.Visible;
                wnd.SourceInitialized += (sender, args) =>
                {
                    HwndSource src = (HwndSource)HwndSource.FromVisual(wnd);
                    src.AddHook(wnd.WndProc);
                };
                return(wnd);
            }
        private void LayoutNormalCellsSectionWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Utils.HideWindowInAltTab(this.Handle);
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual((Window)sender);

            hwndSource.AddHook(DragHook);
        }
Esempio n. 9
0
        //--- Windowハンドルを取得できるようになったタイミングで初期化
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            Apply();
            var source = (HwndSource)HwndSource.FromVisual(AssociatedObject);

            source.AddHook(HookProcedure);  //--- メッセージフック
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        public void ShowMultiSearch()
        {
            WindowMultiSearch wms = new WindowMultiSearch(this.Searches);
            // Hack to set owner from a user control?!
            HwndSource source = HwndSource.FromVisual(this) as HwndSource;

            if (source != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(wms);
                helper.Owner = source.Handle;
            }
            if (wms.ShowDialog() == false)
            {
                return;
            }

            // Clear any existing filter ID's as we will only show the multi-string search
            this.FilterIds.Clear();
            this.Searches.Reset();
            foreach (SearchCriteria sc in wms.NewSearches)
            {
                // Add the ID so that any matches show up straight away
                this.FilterIds.Add(sc.Id);
                this.Searches.Add(sc);
            }

            OnMultiSearchInitiated(wms.NewSearches);
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CtxMenuSearchViewTerms_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            WindowSearchTerms wst = new WindowSearchTerms(this.Searches);
            // Hack to set owner from a user control?!
            HwndSource source = HwndSource.FromVisual(this) as HwndSource;

            if (source != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(wst);
                helper.Owner = source.Handle;
            }
            if (wst.ShowDialog() == false)
            {
                return;
            }

            this.Searches = wst.Searches;
            this.FilterIds.Clear();
            foreach (SearchCriteria sc in this.Searches.Items)
            {
                if (sc.Enabled == false)
                {
                    continue;
                }

                this.FilterIds.Add(sc.Id);
            }

            listLines.ItemsSource = null;
            listLines.ItemsSource = this.Lines;
        }
        public async Task <FileDrop.Result> Run(
            IEnumerable <string> filePathes,
            int stepFrameCount      = 0,
            int layer               = 0,
            int timeoutMilliseconds = -1)
        {
            FileDrop.ValidateFilePathes(filePathes, nameof(filePathes));

            // コピーしておく
            var filePathesClone = new List <string>(filePathes);

            return
                (await this.MainWindow.Dispatcher.InvokeAsync(
                     () =>
            {
                // VoiceroidUtilのメインウィンドウハンドル取得
                var mainWinHandle =
                    (HwndSource.FromVisual(this.MainWindow) as HwndSource)?.Handle;
                if (!mainWinHandle.HasValue)
                {
                    return FileDrop.Result.Fail;
                }

                return
                FileDrop.Run(
                    mainWinHandle.Value,
                    filePathesClone,
                    stepFrameCount,
                    layer,
                    timeoutMilliseconds);
            }));
        }
        /// <summary>WindowのSourceInitializedイベントハンドラ。</summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータを格納しているEventArgs。</param>
        private void onSourceInitialized(object sender, EventArgs e)
        {
            var source = (HwndSource)HwndSource.FromVisual(this.AssociatedObject);

            source.AddHook(this.WndProc);
            this.applyProperties();
        }
Esempio n. 14
0
        private void SetTopmost(bool value)
        {
            if (this.Topmost == value || this.Child == null || !this.Child.IsVisible)
            {
                return;
            }

            var rect   = default(RECT);
            var source = (HwndSource)HwndSource.FromVisual(this.Child);
            var handle = source.Handle;

            if (!GetWindowRect(handle, out rect))
            {
                return;
            }

            if (value)
            {
                SetWindowPos(handle, HWND_TOPMOST, rect.Left, rect.Top, (int)this.Width, (int)this.Height, TOPMOST_FLAGS);
            }
            else
            {
                SetWindowPos(handle, HWND_BOTTOM, rect.Left, rect.Top, (int)this.Width, (int)this.Height, TOPMOST_FLAGS);
                SetWindowPos(handle, HWND_TOP, rect.Left, rect.Top, (int)this.Width, (int)this.Height, TOPMOST_FLAGS);
                SetWindowPos(handle, HWND_NOTOPMOST, rect.Left, rect.Top, (int)this.Width, (int)this.Height, TOPMOST_FLAGS);
            }

            this.Topmost = value;
        }
Esempio n. 15
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            HwndSource source = (HwndSource)HwndSource.FromVisual(this);

            ExMessageBoxBase.FlashWind(source.Handle);

            _vm.MsgText  = text;
            _vm.MSGTitle = title;

            if (mType == ExMessageBoxBase.MessageType.Asterisk)
            {
                System.Media.SystemSounds.Asterisk.Play();
            }
            if (mType == ExMessageBoxBase.MessageType.Beep)
            {
                System.Media.SystemSounds.Beep.Play();
            }
            if (mType == ExMessageBoxBase.MessageType.Exclamation)
            {
                System.Media.SystemSounds.Exclamation.Play();
            }
            if (mType == ExMessageBoxBase.MessageType.Hand)
            {
                System.Media.SystemSounds.Hand.Play();
            }
            if (mType == ExMessageBoxBase.MessageType.Question)
            {
                System.Media.SystemSounds.Question.Play();
            }
        }
        /// <summary>
        /// Updates the host, setting the size, parent window and visibility if needed.
        /// </summary>
        private void UpdateHost()
        {
            //  On the preview host thread, set the parent and bounds.
            OnPreviewHostThread(
                () =>
            {
                //  Set the parent of the host.
                if (previewHostHandle != IntPtr.Zero)
                {
                    User32.SetParent(previewHandlerHost.Handle, previewHostHandle);
                }

                //  Set the bounds of the host.
                previewHandlerHost.Bounds = new Rectangle(previewArea.left, previewArea.top, previewArea.Width(), previewArea.Height());

                //  If we have a preview control, make sure its parent is set and it's visible.
                if (previewHandlerControl != null)
                {
                    HwndSource panelHwnd = HwndSource.FromVisual(previewHandlerControl) as HwndSource;


                    User32.SetParent(panelHwnd.Handle, previewHandlerHost.Handle);
                    //previewHandlerControl.Bounds = new Rectangle(previewArea.left, previewArea.top, previewArea.Width(), previewArea.Height());
                    previewHandlerHost.Visible       = true;
                    previewHandlerControl.Visibility = System.Windows.Visibility.Visible;
                }
            });
        }
Esempio n. 17
0
        private void WindowSourceInitialized(object sender, EventArgs e)
        {
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual((Window)sender);

            hwndSource.AddHook(DragHook);
            hwndSource.AddHook(MaximizeHook);
        }
Esempio n. 18
0
        /// <summary>
        /// Adjust the number of alerts by the height of the window
        /// </summary>
        void adjustAlertNum()
        {
            var source = HwndSource.FromVisual(_owner) as HwndSource;

            if (source != null && _manager.GetAllAlerts().Any())
            {
                if (Win32.GetClientRect(source.Handle, out Win32.RECT cr))
                {
                    var alertHeight = _manager.GetAllAlerts().Sum(x => x.Height);
                    var clientRect  = new Rect(cr.Left, cr.Top, cr.Right - cr.Left, cr.Bottom - cr.Top);
                    while ((clientRect.Height < alertHeight) && _manager.GetAllAlerts().Any())
                    {
                        var alert = _manager.GetAllAlerts().FirstOrDefault();
                        _manager.CloseAlert(alert, false);

                        var oldHeight = alertHeight;
                        alertHeight = _manager.GetAllAlerts().Sum(x => x.Height);
                        if (Math.Abs(oldHeight - alertHeight) < 0.001)
                        {
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 19
0
 private WindowAspectRatio(ViewWindow window)
 {
     _calculatedMagic = false;
     _window          = window;
     _ratio           = window.GetRatio();
     ((HwndSource)HwndSource.FromVisual(window)).AddHook(DragHook);
 }
Esempio n. 20
0
 public void InitialiseHWND()
 {
     //Window window = Window.GetWindow(_owner);
     //var wih = new WindowInteropHelper(window);
     //IntPtr hWnd = wih.Handle;
     Init((HwndSource)HwndSource.FromVisual(_owner));
 }
Esempio n. 21
0
        public void SetForeground(Window Window)
        {
            HwndSource source       = (HwndSource)HwndSource.FromVisual(Window);
            IntPtr     WindowHandle = source.Handle;

            SetForegroundWindow(WindowHandle);
        }
Esempio n. 22
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string           path = @"D:\Spil\Diablo II\Diablo II - 1.14D bnet1\Game.exe";
            ProcessStartInfo psi  = new ProcessStartInfo(path);

            psi.Arguments = "-w";
            //psi.WindowStyle = ProcessWindowStyle.Minimized;
            p = Process.Start(psi);
            p.WaitForInputIdle();

            while (p.MainWindowHandle == IntPtr.Zero)
            {
                Thread.Yield();
            }

            HwndSource source = (HwndSource)HwndSource.FromVisual(MainD2Grid);

            IntPtr pt = p.MainWindowHandle;

            SafeNativeMethods.SetParent(pt, source.Handle);                     // Process.GetCurrentProcess().MainWindowHandle);
            int style = SafeNativeMethods.GetWindowLong(pt, GWL_STYLE);         // get the original window style

            SafeNativeMethods.SetWindowLong(pt, GWL_STYLE, (style & ~MYSTUFF)); // change window style (remove border)
            //SafeNativeMethods.ShowWindow(pt, SW_SHOWMAXIMIZED); // maximize the window
        }
Esempio n. 23
0
        public HotKeyHost(Window window)
        {
            _window = window;
            var hwnd = (HwndSource)HwndSource.FromVisual(window);

            Init(hwnd);
        }
Esempio n. 24
0
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            this.Apply();
            var source = (HwndSource)HwndSource.FromVisual(this.AssociatedObject);

            source.AddHook(this.HookProcedure);
        }
Esempio n. 25
0
        public static bool FindSteam()
        {
            // find steam
            string path = "";

            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Valve\\Steam");
            if (key != null)
            {
                path = key.GetValue("SteamPath") as string;
            }

            // no steam key, let's try the default
            if (path.Equals("") || !Directory.Exists(path))
            {
                path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                path = Path.Combine(path, "Steam");
            }
            path = Path.Combine(path, "steamapps");
            path = Path.Combine(path, "common");
            path = Path.Combine(path, "terraria");
            path = Path.Combine(path, "Content");
            if (Directory.Exists(path))
            {
                HwndSource hwnd = HwndSource.FromVisual(App.Current.MainWindow) as HwndSource;
                cm = new ContentManager(new SimpleProvider(hwnd.Handle), path);
                return((cm == null) ? false : true);
            }

            return(false);
        }
Esempio n. 26
0
        /// <summary>
        /// フックプロシージャ
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode == NativeMethods.HCBT_ACTIVATE)
            {
                var rcForm   = new NativeMethods.RECT(0, 0, 0, 0);
                var rcMsgBox = new NativeMethods.RECT(0, 0, 0, 0);

                var hwndSource = (HwndSource)HwndSource.FromVisual(_owner);
                NativeMethods.GetWindowRect(hwndSource.Handle, out rcForm);
                NativeMethods.GetWindowRect(wParam, out rcMsgBox);

                // センター位置を計算する。
                var x = (rcForm.Left + (rcForm.Right - rcForm.Left) / 2) - ((rcMsgBox.Right - rcMsgBox.Left) / 2);
                var y = (rcForm.Top + (rcForm.Bottom - rcForm.Top) / 2) - ((rcMsgBox.Bottom - rcMsgBox.Top) / 2);

                NativeMethods.SetWindowPos(wParam, 0, x, y, 0, 0, NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOZORDER | NativeMethods.SWP_NOACTIVATE);

                var result = NativeMethods.CallNextHookEx(_hookHandle, nCode, wParam, lParam);

                // フックを解除する。
                NativeMethods.UnhookWindowsHookEx(_hookHandle);
                _hookHandle = IntPtr.Zero;

                return(result);
            }
            else
            {
                return(NativeMethods.CallNextHookEx(_hookHandle, nCode, wParam, lParam));
            }
        }
Esempio n. 27
0
        private void InitializeThumbnail()
        {
            if (IntPtr.Zero != _thumb)
            {
                // release the old thumbnail
                ReleaseThumbnail();
            }

            if (IntPtr.Zero == Handle)
            {
                return;
            }

            // find our parent hwnd
            _target = (HwndSource)HwndSource.FromVisual(this);

            // if we have one, we can attempt to register the thumbnail
            if (_target == null || 0 != DwmUtils.DwmRegisterThumbnail(_target.Handle, Handle, out this._thumb))
            {
                return;
            }

            DwmThumbnailProperties props = new DwmThumbnailProperties();

            props.Visible = false;
            props.SourceClientAreaOnly = false;
            props.Opacity = (byte)(255 * this.Opacity);
            props.Flags   = ThumbnailFlags.Visible |
                            ThumbnailFlags.SourceClientAreaOnly |
                            ThumbnailFlags.Opacity;

            DwmUtils.DwmUpdateThumbnailProperties(_thumb, ref props);
        }
Esempio n. 28
0
        private void InitialiseThumbnail(IntPtr source)
        {
            if (IntPtr.Zero != thumb)
            {
                // release the old thumbnail
                ReleaseThumbnail();
            }

            if (IntPtr.Zero != source)
            {
                // find our parent hwnd
                target = (HwndSource)HwndSource.FromVisual(this);

                // if we have one, we can attempt to register the thumbnail
                if (target != null && 0 == Interop.DwmRegisterThumbnail(target.Handle, source, out this.thumb))
                {
                    Interop.ThumbnailProperties props = new Interop.ThumbnailProperties();
                    props.Visible = false;
                    props.SourceClientAreaOnly = this.ClientAreaOnly;
                    props.Opacity = (byte)(255 * this.Opacity);
                    props.Flags   = Interop.ThumbnailFlags.Visible | Interop.ThumbnailFlags.SourceClientAreaOnly
                                    | Interop.ThumbnailFlags.Opacity;
                    Interop.DwmUpdateThumbnailProperties(thumb, ref props);
                }
            }
        }
Esempio n. 29
0
        void OnSizeLocationChanged()
        {
            try
            {
                if (this.Visibility == System.Windows.Visibility.Visible)
                {
                    Point             offset     = _placementTarget.TranslatePoint(new Point(), Owner);
                    Point             size       = new Point(_placementTarget.ActualWidth, _placementTarget.ActualHeight);
                    HwndSource        hwndSource = (HwndSource)HwndSource.FromVisual(Owner);
                    CompositionTarget ct         = hwndSource.CompositionTarget;
                    offset = ct.TransformToDevice.Transform(offset);
                    size   = ct.TransformToDevice.Transform(size);

                    Win32.POINT screenLocation = new Win32.POINT(offset);
                    Win32.ClientToScreen(hwndSource.Handle, ref screenLocation);
                    Win32.POINT screenSize = new Win32.POINT(size);
                    try
                    {
                        Win32.MoveWindow(((HwndSource)HwndSource.FromVisual(this)).Handle, screenLocation.X, screenLocation.Y, screenSize.X, screenSize.Y, true);
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Flash the specified Window (form) for the specified number of times
        /// </summary>
        /// <param name="form">The Form (Window) to Flash.</param>
        /// <param name="count">The number of times to Flash.</param>
        /// <returns></returns>
        public static bool Flash(Window window, uint count)
        {
            var handle = (HwndSource)HwndSource.FromVisual(window);
            var fi     = Create_FLASHWINFO(handle.Handle, FLASHW_ALL, count, 0);

            return(FlashWindowEx(ref fi));
        }