private void OnVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue != ShowWindow)
            {
                if (_window != null)
                {
                    try
                    {
                        var wih = new System.Windows.Interop.WindowInteropHelper(_window);
                        if (wih.Handle != IntPtr.Zero)
                        {
                            IntPtr hWnd = wih.EnsureHandle();

                            if (hWnd != IntPtr.Zero)
                            {
                                if (ShowWindow)
                                {
                                    _window.Show();
                                }
                                else
                                {
                                    _window.Hide();
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        public Preferences(IntPtr parentWindow) : this()
        {
            var interop = new System.Windows.Interop.WindowInteropHelper(this);

            interop.EnsureHandle();
            interop.Owner = parentWindow;
        }
Example #3
0
        /// <summary>
        /// 获取WPF窗口句柄.
        /// </summary>
        /// <param name="main">The main.</param>
        /// <returns></returns>
        public static IntPtr GetHandle(this Window main)
        {
            var helper = new System.Windows.Interop.WindowInteropHelper(main);

#if !NET35
            if (helper.Handle == IntPtr.Zero)
            {
                return(helper.EnsureHandle());
            }
#endif
            return(helper.Handle);
        }
Example #4
0
        public void Show(IWaitIndicatorAppearance appearance, double left, double top, double width, double height)
        {
            this.Left = left;
            this.Top = top;
            this.Width = width;
            this.Height = height;
            m_ViewModel.Appearance = appearance; // determine "appearance" yet before Show()

            var wih = new System.Windows.Interop.WindowInteropHelper(this);
            wih.EnsureHandle();
            Win32.User32.SetWindowLongPtr(new HandleRef(wih, wih.Handle), Win32.User32.GWL_HWNDPARENT, appearance.OwnerHwnd);

            Show();

            m_ViewModel.WaitWindowVisualState = "Active";
        }
        /// <summary>
        /// Take over control. When this function exits, Chronos is in charge again.
        /// </summary>
        /// <remarks>
        /// We show some dialog window to make clear what we are doing, and that we are in charge.
        /// </remarks>
        public void DoYourJob()
        {
            // Use the process' main window as owner, so that our blocking
            // window can not be hidden behind the main window.
            System.Windows.Window win = null;
            var mainHandle            = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            DoOnGUIThread(new Action(() =>
            {
                win          = new ShowPluginIsInCharge();
                var wih      = new System.Windows.Interop.WindowInteropHelper(win);
                var myHandle = wih.EnsureHandle();
                wih.Owner    = mainHandle;
                win.Show();
            }));
            try
            {
                do
                {
                    System.Threading.Thread.Sleep(5000);
                    var ex = RunSampleList(this,
                                           new AxelSemrau.Chronos.Plugin.RunSampleListEventArgs()
                    {
                        //SampleListFile = @"C:\Users\Patrick\Documents\Chronos\MoveTest.csl"
                        ExtendLastPlanner  = true,
                        StartAndWaitForEnd = false
                    }
                                           );
                    if (ex != null)
                    {
                        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "Plugin Provided Schedule", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                } while (OneMoreScheduleWanted(mainHandle));
            }
            finally
            {
                DoOnGUIThread(new Action(() => win.Close()));
            }
        }
        /// <summary>
        /// Take over control. When this function exits, Chronos is in charge again.
        /// </summary>
        /// <remarks>
        /// We show some dialog window to make clear what we are doing, and that we are in charge.
        /// </remarks>
        public void DoYourJob()
        {
            // Use the process' main window as owner, so that our blocking
            // window can not be hidden behind the main window.
            System.Windows.Window win = null;
            var mainHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            DoOnGUIThread(new Action(() =>
            {
                win = new ShowPluginIsInCharge();
                var wih = new System.Windows.Interop.WindowInteropHelper(win);
                var myHandle = wih.EnsureHandle();
                wih.Owner = mainHandle;
                win.Show();
            }));
            try
            {
                do
                {
                    System.Threading.Thread.Sleep(5000);
                    var ex = RunSampleList(this,
                        new AxelSemrau.Chronos.Plugin.RunSampleListEventArgs()
                        {
                            //SampleListFile = @"C:\Users\Patrick\Documents\Chronos\MoveTest.csl"
                            ExtendLastPlanner = true,
                            StartAndWaitForEnd = false
                        }
                    );
                    if (ex != null)
                    {
                        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "Plugin Provided Schedule",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
                    }
                } while (OneMoreScheduleWanted(mainHandle));
            }
            finally
            {
                DoOnGUIThread(new Action(() => win.Close()));
            }
        }
Example #7
0
        /// <summary>
        /// Retrieves the monitor at the specified WPF window.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public MonitorInfo GetMonitorFromWindow(System.Windows.Window window, MultiMonFlags flags = MultiMonFlags.DefaultToNearest)
        {
            if (Count == 0)
            {
                Refresh();
            }
            var ih = new System.Windows.Interop.WindowInteropHelper(window);
            var h  = MonitorFromWindow(ih.EnsureHandle(), flags);

            ih = null;
            if (h == IntPtr.Zero)
            {
                return(null);
            }
            foreach (var m in this)
            {
                if (m.hMonitor == h)
                {
                    return(m);
                }
            }

            return(this[0]);
        }
        private void OnVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool) e.NewValue != ShowWindow)
            {
                if (_window != null)
                {
                    try
                    {
                        var wih = new System.Windows.Interop.WindowInteropHelper(_window);
                        if (wih.Handle != IntPtr.Zero)
                        {
                            IntPtr hWnd = wih.EnsureHandle();

                            if (hWnd != IntPtr.Zero)
                            {
                                if (ShowWindow)
                                    _window.Show();
                                else
                                {
                                    _window.Hide();
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
Example #9
0
        private void onSourceInitialized(object sender, EventArgs e)
        {
            if (ConfigurableWindowInitialized != null)
                ConfigurableWindowInitialized(this, EventArgs.Empty);

            Window win = sender as Window;
            var wih = new System.Windows.Interop.WindowInteropHelper(win);
            wih.EnsureHandle();
            Win32.User32.SetWindowLongPtr(new HandleRef(wih, wih.Handle), Win32.User32.GWL_HWNDPARENT, m_HwndMainWindow);
        }