Example #1
0
 public static void SetAtCenter(Window v, Window w)
 {
     v.UpdateLayout();
     w.UpdateLayout();
     w.Left = v.Left + (v.ActualWidth - w.ActualWidth) / 2;
     w.Top = v.Top + (v.ActualHeight - w.ActualHeight) / 2;
 }
Example #2
0
        public static void CheckWindowPos(Window wnd, ref IntPtr hwnd, bool limit_size)
        {
            try
            {
                if (!Settings.CheckWindowsPos || !wnd.IsVisible)
                    return;

                if (hwnd == IntPtr.Zero)
                    hwnd = new WindowInteropHelper(wnd).Handle;

                if (hwnd == IntPtr.Zero)
                    return;

                //Монитор, на котором окно занимает бОльшую площадь (или ближайший к окну).
                //SystemParameters.WorkArea - только для основного монитора, но уже с dpi.
                Rectangle _WorkingArea = System.Windows.Forms.Screen.FromHandle(hwnd).WorkingArea;

                //Масштабируем под dpi
                double dpi = SysInfo.dpi;
                Rect WorkingArea = (_WorkingArea.Width <= 0 || _WorkingArea.Height <= 0) ? SystemParameters.WorkArea :
                    new Rect(_WorkingArea.X / dpi, _WorkingArea.Y / dpi, _WorkingArea.Width / dpi, _WorkingArea.Height / dpi);

                //Ограничение размеров окна
                if (limit_size)
                {
                    wnd.MaxWidth = WorkingArea.Width;
                    wnd.MaxHeight = WorkingArea.Height;
                    wnd.UpdateLayout();
                }

                //Вписывание в границы
                if (wnd.ActualWidth > 0 && wnd.ActualHeight > 0 && !double.IsNaN(wnd.Left) && !double.IsNaN(wnd.Top))
                {
                    if (wnd.Left < WorkingArea.Left)
                    {
                        //Слева
                        wnd.Left = WorkingArea.Left;
                    }
                    else if (wnd.Left - WorkingArea.Left + wnd.ActualWidth > WorkingArea.Width)
                    {
                        //Справа
                        wnd.Left = WorkingArea.Width - wnd.ActualWidth + WorkingArea.Left;
                    }

                    if (wnd.Top < WorkingArea.Top)
                    {
                        //Сверху
                        wnd.Top = WorkingArea.Top;
                    }
                    else if (wnd.Top - WorkingArea.Top + wnd.ActualHeight > WorkingArea.Height)
                    {
                        //Снизу
                        wnd.Top = WorkingArea.Height - wnd.ActualHeight + WorkingArea.Top;
                    }
                }
            }
            catch (Exception) { }
        }
Example #3
0
		private void CreateLogoWindow ()
			{
			String LogoFileName = Path.Combine (m_CVM.GetProgrammDirectory (), "WPMediaLogo.png");
			if (!File.Exists (LogoFileName))
				return;
			BrushConverter BRConverter = new BrushConverter ();
			m_LogoWindow = new System.Windows.Window ();
			m_LogoWindow.AllowsTransparency = true;
			Brush TransparentBrush = (Brush) BRConverter.ConvertFromString ("Transparent");
			m_LogoWindow.Background = TransparentBrush;
			m_LogoWindow.BorderBrush = TransparentBrush;
			m_LogoWindow.WindowStyle = System.Windows.WindowStyle.None;
			m_LogoWindow.SizeToContent = SizeToContent.WidthAndHeight;
			m_LogoWindow.Topmost = true;
			m_LogoWindow.Top = (double) m_CVM.VideoRectangle.Top + ((double) m_CVM.VideoRectangle.Height) * 0.085;
			m_LogoWindow.Left = (double) m_CVM.VideoRectangle.Left + ((double) m_CVM.VideoRectangle.Width) * 0.88;
			double Sizing = ((double) m_CVM.VideoRectangle.Width) * 0.055;
			Image LogoImage = new Image ();
			LogoImage.Opacity = 0.7;
			BitmapImage LogoBitmap = new BitmapImage ();
			LogoBitmap.BeginInit ();
			LogoBitmap.UriSource = new Uri (LogoFileName);
			LogoBitmap.CacheOption = BitmapCacheOption.OnLoad;
			LogoBitmap.DecodePixelWidth = (int) Sizing;
			LogoBitmap.DecodePixelHeight = (int) Sizing;
			LogoBitmap.EndInit ();
			LogoImage.Source = LogoBitmap;
			m_LogoWindow.Content = LogoImage;
			m_LogoWindow.UpdateLayout ();
			m_LogoWindow.MaxWidth = Sizing;
			m_LogoWindow.MaxHeight = Sizing;
			m_LogoWindow.Cursor = Cursors.None;
			m_LogoWindow.Show ();
			}
Example #4
0
 static void NextWindow()
 {
     if (currentWindow == null)
     {
         if (windowQueue.Count > 0)
         {
             positionWindow = true;
             currentWindow = windowQueue[0];
             currentWindow.Opacity = 0.0;
             if (currentWindow.IsEnabled)
                 currentWindow.Show();
             currentWindow.UpdateLayout();
             windowQueue.RemoveAt(0);
             MainWindow.Instance.Focusable = false;
         }
         else
         {
             MainWindow.Instance.Focusable = true;
         }
     }
 }