Beispiel #1
0
 Rect rcnormal;                  //定义一个全局rect记录还原状态下窗口的位置和大小。
 public MainWindow()
 {
     InitializeComponent();
     icon();
     //保证窗体显示在上方。 
     wsl = WindowState;
 }
        public void Restore(XmlReader reader)
        {
            int count = reader.AttributeCount;
            for (int i = 0; i < count; ++i)
            {
                reader.MoveToAttribute(i);
                switch (reader.Name)
                {
                    case "top":
                        Top = reader.ReadContentAsDouble();
                        break;

                    case "left":
                        Left = reader.ReadContentAsDouble();
                        break;

                    case "width":
                        Width = reader.ReadContentAsDouble();
                        break;

                    case "height":
                        Height = reader.ReadContentAsDouble();
                        break;

                    case "state":
                        State = (WindowState) Enum.Parse(typeof (WindowState), reader.Value);
                        break;
                }
            }
        }
	static void OpenGeovoxIntegrationWindow(){
		Resolution res = Screen.currentResolution;
		
		UpdateCurrentSourceDirectory();
		
		if ( window == null ){
			window = ScriptableObject.CreateInstance<AGF_IntegrationWindow>();
			window.ShowUtility();
			
			window.position = new Rect( res.width * 0.25f, res.height * 0.25f, 500.0f, 200 );
			window.title = "Geovox Scene Loader";
			window.maxSize = new Vector2( window.position.width, window.position.height );
			window.minSize = new Vector2( window.position.width, window.position.height );
			window.integrationType = IntegrationType.Geovox;
			
			m_CurrentWindowState = WindowState.ModeSelect;
			
		} else {
			window.Focus();
		}

		lightShadows = (LightShadows)PlayerPrefs.GetInt (Main.gameName + "ShadowType", 2);
		terrainShadows = PlayerPrefs.GetInt (Main.gameName + "TerrainShadowType", 1) == 1;
		grassShadows = PlayerPrefs.GetInt (Main.gameName + "GrassShadowType", 1) == 1;
		prefabShadows = PlayerPrefs.GetInt (Main.gameName + "PrefabShadowType", 1) == 1;
		terrainSpecular = PlayerPrefs.GetInt (Main.gameName + "TerrainSpecular", 1) == 1;
		
		prevRunInBackground = Application.runInBackground;
		Application.runInBackground = true;
	}
Beispiel #4
0
        public Sdl2NativeWindow(int x, int y, int width, int height,
            string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (sync)
            {
                var bounds = device.Bounds;
                var flags = TranslateFlags(options);
                flags |= WindowFlags.OPENGL;
                flags |= WindowFlags.RESIZABLE;
                flags |= WindowFlags.HIDDEN;
                flags |= WindowFlags.ALLOW_HIGHDPI;

                if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 ||
                    (flags & WindowFlags.FULLSCREEN) != 0)
                    window_state = WindowState.Fullscreen;

                IntPtr handle;
                lock (SDL.Sync)
                {
                    EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
                    handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
                    SDL.AddEventWatch(EventFilterDelegate, handle);
                    SDL.PumpEvents();
                }
                window = new Sdl2WindowInfo(handle, null);
                window_id = SDL.GetWindowID(handle);
                windows.Add(window_id, this);
                window_title = title;

                exists = true;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Called when an attached view's Loaded event fires.
        /// </summary>
        /// <param name="view"/>
        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);

            _window = Window.GetWindow((DependencyObject)view);

            if (_window == null)
            {
                return;
            }

            _window.StateChanged += OnWindowStateChanged;
            _previousWindowState = _window.WindowState;

            Stream iconStream = IoC.Get<IResourceManager>()
                .GetStream("Resources/GoHome.ico", Assembly.GetExecutingAssembly().GetAssemblyName());

            _taskbarIcon = new TaskbarIcon { Icon = new Icon(iconStream), ToolTipText = "Show main window" };

            _taskbarIcon.TrayMouseDoubleClick += OnTaskbarIconTrayMouseClick;
            _taskbarIcon.TrayLeftMouseDown += OnTaskbarIconTrayMouseClick;
            _taskbarIcon.TrayRightMouseDown += OnTaskbarIconTrayMouseClick;

            if (Settings.Default.StartHiddenToTray)
            {
                _window.WindowState = WindowState.Minimized;
            }
        }
 public static void Initialize()
 {
     _window = CoreWindow.GetForCurrentThread();
     _windowsBounds = _window.Bounds;
     _windowState = WindowState.Full;
     _window.SizeChanged += _window_SizeChanged;
 }
Beispiel #7
0
        public static void GoFullScreen(this Window window)
        {
            if (IsFullScreen(window))
            {
                return;
            }

            windowState = window.WindowState;
            windowStyle = window.WindowStyle;
            windowTopmost = window.Topmost;
            windowResizeMode = window.ResizeMode;
            windowRect.X = window.Left;
            windowRect.Y = window.Top;
            windowRect.Width = window.Width;
            windowRect.Height = window.Height;

            window.WindowState = WindowState.Maximized;
            window.WindowStyle = WindowStyle.None;
            windowTopmost = false;
            windowResizeMode = ResizeMode.NoResize;
            IntPtr handle = new WindowInteropHelper(window).Handle;
            Screen screen = Screen.FromHandle(handle);
            window.Width = screen.Bounds.Width;
            window.Height = screen.Bounds.Height;

            fullWindow = window;
        }
        public static void ToFullscreen(this Window window)
        {
            if (window.IsFullscreen())
            { 
                return; 
            }
   
            _windowState = window.WindowState;
            _windowStyle = window.WindowStyle;
            _windowTopMost = window.Topmost;
            _windowResizeMode = window.ResizeMode;
            _windowRect.X = window.Left;
            _windowRect.Y = window.Top;
            _windowRect.Width = window.Width;
            _windowRect.Height = window.Height;

            window.WindowState = WindowState.Normal; 
            window.WindowStyle = WindowStyle.None;
            window.ResizeMode = ResizeMode.NoResize;
            window.Topmost = true; 

          
            var handle = new WindowInteropHelper(window).Handle; 
            Screen screen = Screen.FromHandle(handle); 
            window.MaxWidth = screen.Bounds.Width;
            window.MaxHeight = screen.Bounds.Height;
            window.WindowState = WindowState.Maximized;
             
            window.Activated += new EventHandler(window_Activated);
            window.Deactivated += new EventHandler(window_Deactivated); 
            _fullWindow = window;
        }
Beispiel #9
0
        public MainWindowAdapter(
            Project project, IFieldPathFactory pathFactory, 
            PresetView preset, StandardView standard, AdvancedView advanced, 
            RetrieveFieldsView fields)
            : base(project)
        {
            _appWidth = Properties.Settings.Default.AppWidth;
            _appHeight = Properties.Settings.Default.AppHeight;
            _appWindowState = Properties.Settings.Default.AppWindowState;
            _viewColumnSize = new GridLength(Properties.Settings.Default.ViewColumnSize);

            Preset = preset;
            Standard = standard;
            Advanced = advanced;
            RetrieveFields = fields;
            _views.Add("Preset", preset.Adapter);
            _views.Add("Standard", standard.Adapter);
            _views.Add("Advanced", advanced.Adapter);

            Preset.Adapter.Search += Adapter_Search;
            Standard.Adapter.Search += Adapter_Search;
            Advanced.Adapter.Search += Adapter_Search;

            ProjectAdapter = new ProjectAdapter(project);
            ProjectAdapter.Project.CurrentConnectionChanged += delegate
            {
                RefreshPaths();
                OnPropertyChanged("ApplicationTitle");
            };
            PathFactory = pathFactory;

            CurrentView = Preset.Adapter;
            SelectedSubjectChanged += delegate { RefreshPaths(); };
            RefreshPaths();
        }
Beispiel #10
0
 public SavedWindowState Read(ISettingsSection section)
 {
     Bounds = section.Attribute<Rect?>("Bounds") ?? Rect.Empty;
     IsFullScreen = section.Attribute<bool?>("IsFullScreen") ?? false;
     WindowState = section.Attribute<WindowState?>("WindowState") ?? WindowState.Normal;
     return this;
 }
Beispiel #11
0
 private void Window_StateChanged(object sender, EventArgs e)
 {
     if (this.WindowState != System.Windows.WindowState.Minimized)
     {
         FLastRestoreWindowState = this.WindowState;
     }
     
 }
Beispiel #12
0
        protected override void OnStateChanged(EventArgs e)
        {
            base.OnStateChanged(e);

            if(this.WindowState != WindowState.Minimized) {
                this.RestoreWindowState = this.WindowState;
            }
        }
 private static Action<object> SetWindowStateHandler(WindowState newState)
 {
     return o =>
     {
         Window win = ExtractWindowFromParameter(o);
         win.WindowState = newState;
     };
 }
Beispiel #14
0
 public void UpdateFrom(MainWindow window)
 {
     Left = window.Left;
     Top = window.Top;
     Width = window.Width;
     Height = window.Height;
     State = window.WindowState;
 }
    public static void OnSceneLoaded()
    {
        m_CurrentWindowState = WindowState.ModeSelect;

        if ( window != null ){
            window.Repaint();
        }
    }
        public FloatingItemSnapShot(object content, Rect location, int zIndex, WindowState state)
        {
            if (content == null) throw new ArgumentNullException("content");

            _content = content;
            _location = location;
            _zIndex = zIndex;
            _state = state;
        }
Beispiel #17
0
 private void MainWindowLoaded(object sender, RoutedEventArgs e)
 {
     dgNotifications.Items.SortDescriptions.Add(new SortDescription("StartTime", ListSortDirection.Descending));
     _showStateForNotifyIcon = WindowState;
     UpdateConnectionSring();
     if (miHideAtStart.IsChecked)
     {
         WindowState = WindowState.Minimized;
     }
 }
Beispiel #18
0
        public WindowSysMin(Window wind)
        {
            window = wind;
            window.Closing += window_Closing;
            window.StateChanged += window_StateChanged;
            //保证窗体显示在上方。
            wsl = window.WindowState;

            Init();
        }
Beispiel #19
0
        public static void Initialize()
        {
            _window = CoreWindow.GetForCurrentThread();
            _windowsBounds = _window.Bounds;
            _windowState = WindowState.Full;
            _window.SizeChanged += _window_SizeChanged;

            CoreApplication.Suspending += CoreApplication_Suspending;
            CoreApplication.Resuming += CoreApplication_Resuming;
        }
		// Constructor
		public MainWindowViewModel()
		{
			// Default values
			windowState = WindowState.Normal;
			restoreOrMaximiseImageButtonSource = ImageUtil.LoadBitmapImageFromResources(@"../Resources/maximise_normal.png");

			// Title bar commands
			this.minimiseCommand = new RelayCommand(x => windowState = WindowState.Minimized);
			this.restoreOrMaximiseCommand = new RelayCommand(x => windowState = WindowState.Maximized);
			this.closeCommand = new RelayCommand(x => Application.Current.Shutdown());
		}
Beispiel #21
0
 public MenuWindow(SpriteFont spriteFont, string menuTitle, Texture2D backgroundImage)
 {
     itemList = new List<MenuItem>();
     changeSpan = TimeSpan.FromMilliseconds(800.0);
     selectedItem = 0;
     changeProgress = 0;
     windowState = WindowState.Inactive;
     this.spriteFont = spriteFont;
     this.menuTitle = menuTitle;
     this.backgroundImage = backgroundImage;
 }
 void OnStateChanged(object sender, EventArgs args)
 {
     if (WindowState == WindowState.Minimized)
     {
         Hide();
         if (appIcon != null)
             appIcon.ShowBalloonTip(2000);
     }
     else
         windowState = WindowState;
 }
Beispiel #23
0
		public SavedWindowState(MetroWindow window) {
			this.Bounds = window.RestoreBounds;
			var source = PresentationSource.FromVisual(window);
			Debug.Assert(source != null);
			if (source != null) {
				var t = this.Bounds;
				t = Rect.Transform(Bounds, source.CompositionTarget.TransformToDevice);
				this.Bounds = new Rect(t.TopLeft, this.Bounds.Size);
			}
			this.IsFullScreen = window.IsFullScreen;
			this.WindowState = window.WindowState;
		}
Beispiel #24
0
		public AGSGameSettings(string title, AGS.API.Size virtualResolution, WindowState windowState = WindowState.Maximized,
               AGS.API.Size? windowSize = null, VsyncMode vsync = VsyncMode.Adaptive, bool preserveAspectRatio = true,
                               WindowBorder windowBorder = WindowBorder.Resizable)
		{
            Title = title;
            VirtualResolution = virtualResolution;
            WindowState = windowState;
            WindowSize = windowSize.HasValue ? windowSize.Value : virtualResolution;
            Vsync = vsync;
            PreserveAspectRatio = preserveAspectRatio;
            WindowBorder = windowBorder;
		}
Beispiel #25
0
        public MainWindow()
        {
            InitializeComponent();

            _youTubeUrlIdentifier = new IsYouTubeVideoSpecification();

            _storedWindowState = WindowState.Normal;

            _notifier = new System.Windows.Forms.NotifyIcon();

            InitializeTrayIcon();
        }
Beispiel #26
0
 /**
  * ウインドウ GUI
  */
 public void OnWindowGUI()
 {
     if (windowState == WindowState.Minimize) {
         if (GUI.Button(minimizeRect, ">")) {
             windowState = WindowState.Visible;
         }
     } else {
         windowRect = GUI.Window(
             windowId, windowRect, OnWindowContentGUI, windowTitle
         );
     }
 }
        protected override void OnStateChanged(EventArgs e)
        {
            base.OnStateChanged(e);

            if (!this.IsLoaded)
                return;

            if (this.WindowState == System.Windows.WindowState.Minimized)
                _icon_DoubleClick(this, e);//Hide
            else
                _lastState = this.WindowState;
        }
Beispiel #28
0
    // Update is called once per frame
    void Update()
    {
        int val = GameMaster.Instance.Coin;

        switch(ws){
        case WindowState.Appear:
            progress += 15f*Time.deltaTime;
            if(progress >= 1f){
                ws = WindowState.Wait;
                progress = 1f;
                waitCount = waitTime;
                timeSpan = 0f;
            }
            break;
        case WindowState.Wait:
            if (timeSpan > 0f){
                timeSpan-= Time.deltaTime;
            }else if (timeSpan <= 0f && viewNumber != val){
                viewNumber++;
                timeSpan = 0.05f;
            }else{
                waitCount -= 2f*Time.deltaTime;
                if (waitCount<=0f){
                    ws = WindowState.Close;
                }
            }
            break;
        case WindowState.Close:
            progress -= Time.deltaTime;
            if(progress <= 0f){
                ws = WindowState.Off;
                progress = 0f;
            }
            break;
        case WindowState.Off:
            break;
        }

        Vector3 bufv = transform.localPosition;
        bufv.y = originalY - (110f * progress);
        transform.localPosition = bufv;

        if (viewNumber != val &&(ws == WindowState.Off || ws == WindowState.Close)) {
            ws =  WindowState.Appear;
        }

        int buf = viewNumber;
        for (int i=maxDigit-1; i>=0; i--) {
            digitText[i].text = (buf % 10).ToString();
            buf /= 10;
        }
    }
Beispiel #29
0
        public NotifyIconWrapper(Window window, WindowState showState)
        {
            InitializeComponent();
            _window = window;
            notifyIcon.Text = _window.Title;
            _showState = showState;

            toolStripMenuItemShow.Text = Res.Show;
            toolStripMenuItemShow.Click += ToolStripMenuItemShowClick;

            toolStripMenuItemClose.Text = Res.Close;
            toolStripMenuItemClose.Click += ToolStripMenuItemCloseClick;
        }
Beispiel #30
0
        public MainWindow()
        {
            InitializeComponent();
            ShowIcon();

            //保证窗体显示在上方。
            wsl = WindowState;

            //设置定时器
            Timer timeClock = new Timer();
            timeClock.Enabled = true;
            timeClock.Interval = 1000;
            timeClock.Elapsed += new ElapsedEventHandler(clock);
        }
Beispiel #31
0
 public WindowManager(WindowState windowState, Vector2 resolution)
 {
     this.windowState = windowState;
     this.resolution  = resolution;
     current          = this;
 }
Beispiel #32
0
 public AddPopUp(WindowState ws)
 {
     InitializeComponent();
     this.CurrentWindowState = ws;
     UserControllSelecter();
 }
Beispiel #33
0
        private void UpdateWindowState()
        {
            // we should wait until window's not fullscreen to resize
            if (updateClientBounds)
            {
                var prevState = window.WindowState;

                if (CurrentPlatform.OS == OS.Linux)
                {
                    window.WindowBorder = WindowBorder.Resizable;
                }

                updateClientBounds = false;

                // if the window-state is set from the outside (maximized button pressed) we have to update it here.
                // if it was set from the inside (.IsFullScreen changed), we have to change the window.
                // this code might not cover all corner cases
                // window was maximized
                if ((windowState == WindowState.Normal && window.WindowState == WindowState.Maximized) ||
                    (windowState == WindowState.Maximized && window.WindowState == WindowState.Normal))
                {
                    windowState = window.WindowState; // maximize->normal and normal->maximize are usually set from the outside
                }
                else
                {
                    window.WindowState = windowState; // usually fullscreen-stuff is set from the code
                }
                if (!Configuration.RunningOnSdl2 && prevState != WindowState.Fullscreen)
                {
                    int centerOffsetX = -(targetBounds.Width - window.ClientRectangle.Width) / 2;
                    int centerOffsetY = -(targetBounds.Height - window.ClientRectangle.Height) / 2;
                    window.X = Math.Max(0, centerOffsetX + window.X);
                    window.Y = Math.Max(0, centerOffsetY + window.Y);
                }

                window.ClientRectangle = new System.Drawing.Rectangle(targetBounds.X,
                                                                      targetBounds.Y, targetBounds.Width, targetBounds.Height);

                // we need to create a small delay between resizing the window
                // and changing the border to avoid OpenTK Linux bug
                if (CurrentPlatform.OS == OS.Linux)
                {
                    updateborder = 2;
                }
                else
                {
                    UpdateBorder();
                }

                var context = GraphicsContext.CurrentContext;
                if (context != null)
                {
                    context.Update(window.WindowInfo);
                }

                if (!Window.Visible)
                {
                    Window.Visible = true;

                    // Bug in OpenTK, it doesn't always set state if window is not visible
                    window.WindowState = windowState;
                }
            }
        }
Beispiel #34
0
 public abstract void SetWindowState(WindowState value);
Beispiel #35
0
        public override async Task OnCommandRecieved(Command cmd)
        {
            string commandName = cmd.LocalCommand;
            string userInput   = cmd.UserInput;


            if (string.IsNullOrEmpty(ApiKey))
            {
                if (!cmd.IsLocalCommand)
                {
                    cmd.Respond("Invalid API Key.");
                }

                return;
            }

            if (commandName == "Play ID")
            {
                string id = RegisteredCommands[commandName].Match(userInput).Groups["id"].Value.ToString();

                if (Current != null)
                {
                    if (Current.IsLoaded)
                    {
                        Current.Close();
                    }
                }

                Application.Current.Dispatcher.Invoke(() => {
                    Current = new YoutubeVideo(id);
                    Current.Show();
                });
            }

            if (commandName == "Search")
            {
                Match m = RegisteredCommands[commandName].Match(userInput);

                string name = m.Groups["name"].Value.ToString();
                if (!string.IsNullOrWhiteSpace(name))
                {
                    if (cmd.IsLocalCommand)
                    {
                        Application.Current.Dispatcher.Invoke(() => {
                            new YoutubeSearch(name).Show();
                        });
                    }
                    else
                    {
                        YouTubeService ys = new YouTubeService(new BaseClientService.Initializer()
                        {
                            ApiKey          = YoutubeHook.ApiKey,
                            ApplicationName = "Butler-YoutubeViewer"
                        });

                        SearchResource.ListRequest req = new SearchResource.ListRequest(ys, "snippet")
                        {
                            Q          = name,
                            MaxResults = 30
                        };

                        LastSearchResponse = req.Execute();

                        string output = "Search Results:-\n";

                        for (int i = 0; i < LastSearchResponse.Items.Count; i++)
                        {
                            output += $"{i+1}.] {LastSearchResponse.Items[i].Snippet.Title}\n";
                        }

                        cmd.Respond(output);
                    }
                }
            }

            if (commandName == "Lucky Search")
            {
                Match m = RegisteredCommands[commandName].Match(userInput);

                YouTubeService ys = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = YoutubeHook.ApiKey,
                    ApplicationName = "Butler-YoutubeViewer"
                });

                SearchResource.ListRequest req = new SearchResource.ListRequest(ys, "snippet")
                {
                    Q          = m.Groups["name"].Value.ToString(),
                    MaxResults = 1
                };

                SearchListResponse resp = req.Execute();

                if (Current != null)
                {
                    if (Current.IsLoaded)
                    {
                        Current.Close();
                    }
                }

                Application.Current.Dispatcher.Invoke(() => {
                    Current = new YoutubeVideo(resp.Items[0].Id.VideoId);
                    Current.Show();
                });
            }

            if (commandName == "Choose Option")
            {
                string choiceString = RegisteredCommands[cmd.LocalCommand].Match(cmd.UserInput).Groups["choice"].Value;
                int    choiceInt;

                if (LastSearchResponse == null)
                {
                    cmd.Respond("You didn't search for anything."); return;
                }
                if (!int.TryParse(choiceString, out choiceInt))
                {
                    cmd.Respond("That is not a number."); return;
                }

                choiceInt -= 1;
                if (choiceInt < 0 || choiceInt > LastSearchResponse.Items.Count - 1)
                {
                    cmd.Respond("Dude.. Enter a acceptable value."); return;
                }

                if (Current != null)
                {
                    if (Current.IsLoaded)
                    {
                        Current.Close();
                    }
                }

                Application.Current.Dispatcher.Invoke(() => {
                    Current = new YoutubeVideo(LastSearchResponse.Items[choiceInt].Id.VideoId);
                    Current.Show();
                });


                // Should I clear the search options after an option has been selected?
                //LastSearchResponse = null;
            }

            if (commandName == "Close")
            {
                if (Current != null)
                {
                    if (Current.IsLoaded)
                    {
                        Current.Close();
                    }
                }
            }

            if (commandName == "State")
            {
                string state = RegisteredCommands[commandName].Match(userInput).Groups["state"].Value.ToLower();

                switch (state)
                {
                case "min":
                case "minimize": State = WindowState.Minimized;
                    break;

                case "max":
                case "maximize": State = WindowState.Maximized;
                    break;
                }

                if (Current != null)
                {
                    if (Current.IsLoaded)
                    {
                        if (State == WindowState.Maximized)
                        {
                            Current.Maximize();
                        }
                        else
                        {
                            Current.Minimize();
                        }
                    }
                }
            }
        }
        private void Select_Window(int i, WindowState wd, WindowStartupLocation wd_st)
        {
            switch (i)
            {
            case 1:
            {
                View.View_Thukho.Mathang view = new View.View_Thukho.Mathang();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 2:
            {
                View.View_Thukho.Loaimathang view = new View.View_Thukho.Loaimathang();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 3:
            {
                View.View_Thukho.Donvi view = new View.View_Thukho.Donvi();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 4:
            {
                View.View_Thukho.Xuathang view = new View.View_Thukho.Xuathang();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 5:
            {
                View.View_Thukho.Nhaphang view = new View.View_Thukho.Nhaphang();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 6:
            {
                View.View_Thukho.Thongke view = new View.View_Thukho.Thongke();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            case 7:
            {
                View.View_Thukho.Thungrac view = new View.View_Thukho.Thungrac();
                view.WindowState           = wd;
                view.WindowStartupLocation = wd_st;
                view.Show();
            }
            break;

            default:
                break;
            }
        }
Beispiel #37
0
        protected virtual Tuple <WindowStyles, WindowExStyles, ShowWindowCommand> GetWindowStyles(WindowCustomStyle customCreationStyle, WindowState state)
        {
            var styles   = (WindowStyles)customCreationStyle.WindowStyles;
            var exStyles = (WindowExStyles)customCreationStyle.WindowExStyles;

            switch (state)
            {
            case WindowState.Normal:
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWNORMAL));

            case WindowState.Maximize:
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWMAXIMIZED));

            case WindowState.Fullscreen:
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWMAXIMIZED));
            }

            return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWNORMAL));
        }
Beispiel #38
0
        /// <summary>
        /// Dependency property event once the windows state value has changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            MdiChild mdiChild = (MdiChild)sender;

            WindowState previousWindowState = (WindowState)e.OldValue;
            WindowState windowState         = (WindowState)e.NewValue;

            if (mdiChild.Container == null ||
                previousWindowState == windowState)
            {
                return;
            }

            if (previousWindowState == WindowState.Maximized)
            {
                for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                {
                    if (mdiChild.Container.Children[i] != mdiChild &&
                        mdiChild.Container.Children[i].WindowState == WindowState.Maximized &&
                        mdiChild.Container.Children[i].MaximizeBox)
                    {
                        mdiChild.Container.Children[i].WindowState = WindowState.Normal;
                    }
                }

                ScrollViewer sv = (ScrollViewer)((Grid)mdiChild.Container.Content).Children[1];
                sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

                if (mdiChild.Buttons != null)
                {
                    mdiChild.Buttons.Children.Clear();
                }
                try
                {
                    mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton);
                    mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton);
                    mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton);
                }
                catch { }
            }

            if (previousWindowState == WindowState.Minimized)
            {
                mdiChild.minimizedPosition = mdiChild.Position;
            }

            switch (windowState)
            {
            case WindowState.Normal:
            {
                mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y);

                if (mdiChild._minimizedWidth > 0 && mdiChild._minimizedHeight > 0)
                {
                    mdiChild.MinWidth  = mdiChild._minimizedWidth;
                    mdiChild.MinHeight = mdiChild._minimizedHeight;
                }

                mdiChild.Width  = mdiChild.originalDimension.Width;
                mdiChild.Height = mdiChild.originalDimension.Height;
            }
            break;

            case WindowState.Minimized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                //double newLeft, newTop;
                //if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0)
                //{
                //    newLeft = mdiChild.minimizedPosition.X;
                //    newTop = mdiChild.minimizedPosition.Y;
                //}
                //else
                //{
                //    int minimizedWindows = 0;
                //    for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                //        if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                //            minimizedWindows++;
                //    int capacity = Convert.ToInt32(mdiChild.Container.InnerWidth) / mdiChild.MinimizedWidth,
                //        row = minimizedWindows / capacity + 1,
                //        col = minimizedWindows % capacity;
                //    newTop = mdiChild.Container.InnerHeight - mdiChild.MinimizedHeight * row;
                //    newLeft = mdiChild.MinimizedWidth * col;
                //}

                //mdiChild.Position = new Point(newLeft, newTop);

                int minimizedWindows = 0;
                for (int i = 0; i < mdiChild.Container.Children.Count; i++)
                {
                    if (mdiChild.Container.Children[i] != mdiChild && mdiChild.Container.Children[i].WindowState == WindowState.Minimized)
                    {
                        minimizedWindows++;
                    }
                }
                int cols  = (int)(mdiChild.Container.InnerWidth / mdiChild.MinimizedWidth);
                int count = 0;
                foreach (var item in mdiChild.Container.Children)
                {
                    if (item.WindowState == WindowState.Minimized)
                    {
                        item.Position = new Point((int)(count % cols) * item.MinimizedWidth, mdiChild.Container.InnerHeight - ((int)((int)(count / cols) + 1)) * item.MinimizedHeight);
                        count++;
                    }
                }

                mdiChild._minimizedWidth  = (int)mdiChild.MinWidth;
                mdiChild._minimizedHeight = (int)mdiChild.MinHeight;

                mdiChild.MinWidth  = mdiChild.MinimizedWidth;
                mdiChild.MinHeight = mdiChild.MinimizedHeight;

                mdiChild.Width  = mdiChild.MinimizedWidth;
                mdiChild.Height = mdiChild.MinimizedHeight;
            }
            break;

            case WindowState.Maximized:
            {
                if (previousWindowState == WindowState.Normal)
                {
                    mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight);
                }

                try
                {
                    StackPanel sp = new StackPanel {
                        Orientation = Orientation.Horizontal
                    };
                    mdiChild.Buttons = sp;
                    if (mdiChild.Container.Theme != ThemeType.Metro)
                    {
                        if (mdiChild.buttonsPanel != null)
                        {
                            mdiChild.buttonsPanel.Children.Clear();
                        }
                        sp.Children.Add(mdiChild.minimizeButton);
                        sp.Children.Add(mdiChild.maximizeButton);
                        sp.Children.Add(mdiChild.closeButton);
                    }
                }
                catch { }

                mdiChild.Position = new Point(0, 0);

                if (mdiChild._minimizedWidth > 0 && mdiChild._minimizedHeight > 0)
                {
                    mdiChild.MinWidth  = mdiChild._minimizedWidth;
                    mdiChild.MinHeight = mdiChild._minimizedHeight;
                }

                mdiChild.Width  = mdiChild.Container.InnerWidth;
                mdiChild.Height = mdiChild.Container.InnerHeight;

                if (mdiChild.Container.AllowWindowStateMax)
                {
                    MdiContainer mdiContainer = mdiChild.Container;
                    mdiContainer.AllowWindowStateMax = false;

                    for (int i = 0; i < mdiContainer.Children.Count; i++)
                    {
                        if (mdiContainer.Children[i] != mdiChild)
                        {
                            if (mdiContainer.Children[i].WindowState == WindowState.Normal &&
                                mdiContainer.Children[i].MaximizeBox)
                            {
                                mdiContainer.Children[i].WindowState = WindowState.Maximized;
                            }
                            else if (mdiContainer.Children[i].WindowState == WindowState.Maximized)
                            {
                                mdiContainer.Children[i].Height = mdiContainer.InnerHeight;
                            }
                        }
                    }

                    ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1];
                    sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                    sv.VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden;

                    mdiChild.Focus();
                    mdiContainer.InvalidateSize();
                    mdiContainer.AllowWindowStateMax = true;
                }
            }
            break;
            }
            mdiChild.RaiseEvent(new RoutedEventArgs(WindowStateChangedEvent));
        }
 public static void SetWindowState(this IWindowService service, WindowState state)
 {
     WindowServiceExtensions.VerifyService(service);
     service.WindowState = DXWindowStateConverter.ToDXWindowState(state);
 }
Beispiel #40
0
 private void MaximizeWindow(object o)
 {
     CurrentWindowState = CurrentWindowState == WindowState.Normal ? WindowState.Maximized : WindowState.Normal;
 }
Beispiel #41
0
 protected virtual void OnDesignerWindowStatePropertyChanged(WindowState oldValue, WindowState newValue)
 {
     if (DesignerProperties.GetIsInDesignMode(this))
     {
         Visibility = newValue == Orm.Toolkit.WindowState.Open ? Visibility.Visible : Visibility.Collapsed;
     }
 }
Beispiel #42
0
 private void MinimizeWindow(object o)
 {
     CurrentWindowState = WindowState.Minimized;
 }
Beispiel #43
0
        protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd);

            const double wheelDelta = 120.0;
            uint         timestamp  = unchecked ((uint)UnmanagedMethods.GetMessageTime());

            RawInputEventArgs e = null;

            WindowsMouseDevice.Instance.CurrentWindow = this;

            switch ((UnmanagedMethods.WindowsMessage)msg)
            {
            case UnmanagedMethods.WindowsMessage.WM_ACTIVATE:
                var wa = (UnmanagedMethods.WindowActivate)(ToInt32(wParam) & 0xffff);

                switch (wa)
                {
                case UnmanagedMethods.WindowActivate.WA_ACTIVE:
                case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE:
                    Activated?.Invoke();
                    break;

                case UnmanagedMethods.WindowActivate.WA_INACTIVE:
                    Deactivated?.Invoke();
                    break;
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_CLOSE:
                bool?preventClosing = Closing?.Invoke();
                if (preventClosing == true)
                {
                    return(IntPtr.Zero);
                }
                break;

            case UnmanagedMethods.WindowsMessage.WM_DESTROY:
                //Window doesn't exist anymore
                _hwnd = IntPtr.Zero;
                //Remove root reference to this class, so unmanaged delegate can be collected
                s_instances.Remove(this);
                Closed?.Invoke();
                //Free other resources
                Dispose();
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DPICHANGED:
                var dpi            = ToInt32(wParam) & 0xffff;
                var newDisplayRect = Marshal.PtrToStructure <UnmanagedMethods.RECT>(lParam);
                Position = new Point(newDisplayRect.left, newDisplayRect.top);
                _scaling = dpi / 96.0;
                ScalingChanged?.Invoke(_scaling);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyDown,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_KEYUP:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyUp,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_CHAR:
                // Ignore control chars
                if (ToInt32(wParam) >= 32)
                {
                    e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp,
                                                  new string((char)ToInt32(wParam), 1));
                }

                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN
                            ? RawMouseEventType.LeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN
                                ? RawMouseEventType.RightButtonDown
                                : RawMouseEventType.MiddleButtonDown,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP
                            ? RawMouseEventType.LeftButtonUp
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP
                                ? RawMouseEventType.RightButtonUp
                                : RawMouseEventType.MiddleButtonUp,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE:
                if (!_trackingMouse)
                {
                    var tm = new UnmanagedMethods.TRACKMOUSEEVENT
                    {
                        cbSize      = Marshal.SizeOf <UnmanagedMethods.TRACKMOUSEEVENT>(),
                        dwFlags     = 2,
                        hwndTrack   = _hwnd,
                        dwHoverTime = 0,
                    };

                    UnmanagedMethods.TrackMouseEvent(ref tm);
                }

                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawMouseEventType.Move,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));

                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(0, (ToInt32(wParam) >> 16) / wheelDelta), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(-(ToInt32(wParam) >> 16) / wheelDelta, 0), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE:
                _trackingMouse = false;
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawMouseEventType.LeaveWindow,
                    new Point(), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN
                            ? RawMouseEventType.NonClientLeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN
                                ? RawMouseEventType.RightButtonDown
                                : RawMouseEventType.MiddleButtonDown,
                    new Point(0, 0), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_PAINT:
                UnmanagedMethods.PAINTSTRUCT ps;

                if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero)
                {
                    var f = Scaling;
                    var r = ps.rcPaint;
                    Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
                    UnmanagedMethods.EndPaint(_hwnd, ref ps);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_SIZE:
                var size = (UnmanagedMethods.SizeCommand)wParam;

                if (Resized != null &&
                    (size == UnmanagedMethods.SizeCommand.Restored ||
                     size == UnmanagedMethods.SizeCommand.Maximized))
                {
                    var clientSize = new Size(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16);
                    Resized(clientSize / Scaling);
                }

                var windowState = size == SizeCommand.Maximized ? WindowState.Maximized
                        : (size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal);

                if (windowState != _lastWindowState)
                {
                    _lastWindowState = windowState;
                    WindowStateChanged?.Invoke(windowState);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_MOVE:
                PositionChanged?.Invoke(new Point((short)(ToInt32(lParam) & 0xffff), (short)(ToInt32(lParam) >> 16)));
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_GETMINMAXINFO:

                MINMAXINFO mmi = Marshal.PtrToStructure <UnmanagedMethods.MINMAXINFO>(lParam);

                if (_minSize.Width > 0)
                {
                    mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (_minSize.Height > 0)
                {
                    mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0)
                {
                    mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0)
                {
                    mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                Marshal.StructureToPtr(mmi, lParam, true);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DISPLAYCHANGE:
                (Screen as ScreenImpl)?.InvalidateScreensCache();
                return(IntPtr.Zero);
            }

#if USE_MANAGED_DRAG
            if (_managedDrag.PreprocessInputEvent(ref e))
            {
                return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }
#endif

            if (e != null && Input != null)
            {
                Input(e);

                if (e.Handled)
                {
                    return(IntPtr.Zero);
                }
            }

            return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
        }
Beispiel #44
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="m"></param>
        public W_截圖(MainWindow m, e_截圖類型 e_type)
        {
            this.M = m;

            //取得螢幕總其實坐標、總大小
            int_螢幕起始坐標_x = 0;
            foreach (var screen in System.Windows.Forms.Screen.AllScreens)  //列出所有螢幕資訊
            {
                if (screen.Bounds.X < int_螢幕起始坐標_x)
                {
                    int_螢幕起始坐標_x = screen.Bounds.X;
                }
                if (screen.Bounds.Y < int_螢幕起始坐標_y)
                {
                    int_螢幕起始坐標_y = screen.Bounds.Y;
                }

                int yy = screen.Bounds.Y + screen.Bounds.Height;
                if (yy > d_螢幕_h)
                {
                    d_螢幕_h = yy;
                }

                int xx = screen.Bounds.X + screen.Bounds.Width;
                if (xx > d_螢幕_w)
                {
                    d_螢幕_w = xx;
                }
            }
            d_螢幕_w -= int_螢幕起始坐標_x;
            d_螢幕_h -= int_螢幕起始坐標_y;



            if (M.ShowInTaskbar && M.WindowState != WindowState.Minimized)
            {
                //截圖前記錄視窗狀態
                ws_全螢幕前的狀態 = M.WindowState;
                d_記錄視窗位子   = M.Top;


                //避免全螢幕導致視窗無法隱藏
                M.fun_鎖定視窗(true);
                M.WindowStyle = System.Windows.WindowStyle.None;//無邊框
                M.WindowState = WindowState.Normal;
                M.Top         = -5000;
            }


            this.Closed += (object sender, EventArgs e) => {
                if (M.ShowInTaskbar && M.WindowState != WindowState.Minimized)
                {
                    M.Top         = d_記錄視窗位子;
                    M.WindowState = ws_全螢幕前的狀態;
                    M.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
                    M.fun_鎖定視窗(false);
                }
            };



            bimg = CaptureScreen();//全螢幕截圖

            InitializeComponent();
            this.Top = -5000;
            this.Show();

            st_按鈕群.Visibility = Visibility.Hidden;



            /*var tim = new System.Windows.Forms.Timer();
             * tim.Interval = 100;
             * tim.Tick += (sender, e) => {*/
            func_初始化(e_type);

            /*tim.Stop();
             * };
             * tim.Start();*/
        }
Beispiel #45
0
        private void _SetRoundingRegion(WINDOWPOS?wp)
        {
            const int MONITOR_DEFAULTTONEAREST = 0x00000002;

            // We're early - WPF hasn't necessarily updated the state of the window.
            // Need to query it ourselves.
            WINDOWPLACEMENT wpl = NativeMethods.GetWindowPlacement(_hwnd);

            if (wpl.showCmd == SW.SHOWMAXIMIZED)
            {
                int left;
                int top;

                if (wp.HasValue)
                {
                    left = wp.Value.x;
                    top  = wp.Value.y;
                }
                else
                {
                    Rect r = _GetWindowRect();
                    left = (int)r.Left;
                    top  = (int)r.Top;
                }

                IntPtr hMon = NativeMethods.MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);

                MONITORINFO mi    = NativeMethods.GetMonitorInfo(hMon);
                RECT        rcMax = mi.rcWork;
                // The location of maximized window takes into account the border that Windows was
                // going to remove, so we also need to consider it.
                rcMax.Offset(-left, -top);

                IntPtr hrgn = NativeMethods.CreateRectRgnIndirect(rcMax);
                NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
            }
            else
            {
                int width;
                int height;

                // Use the size if it's specified.
                if (null != wp && !Utility.IsFlagSet(wp.Value.flags, (int)SWP.NOSIZE))
                {
                    width  = wp.Value.cx;
                    height = wp.Value.cy;
                }
                else if (null != wp && (_lastRoundingState == _window.WindowState))
                {
                    return;
                }
                else
                {
                    Rect r = _GetWindowRect();
                    width  = (int)r.Width;
                    height = (int)r.Height;
                }

                _lastRoundingState = _window.WindowState;

                IntPtr hrgn = IntPtr.Zero;
                if (RoundCorners && 0 != RoundCornersRadius)
                {
                    Point radius = DpiHelper.LogicalPixelsToDevice(new Point(RoundCornersRadius, RoundCornersRadius));
                    hrgn = NativeMethods.CreateRoundRectRgn(0, 0, width, height, (int)radius.X, (int)radius.Y);
                }
                else
                {
                    hrgn = NativeMethods.CreateRectRgn(0, 0, width, height);
                }

                NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
            }
        }
Beispiel #46
0
        IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
        {
            switch (message)
            {
                #region Size / Move / Style events

            case WindowMessage.ACTIVATE:
                // See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification):
                // wParam: The low-order word specifies whether the window is being activated or deactivated.
                bool new_focused_state = Focused;
                if (IntPtr.Size == 4)
                {
                    focused = (wParam.ToInt32() & 0xFFFF) != 0;
                }
                else
                {
                    focused = (wParam.ToInt64() & 0xFFFF) != 0;
                }

                if (new_focused_state != Focused)
                {
                    FocusedChanged(this, EventArgs.Empty);
                }
                break;

            case WindowMessage.ENTERMENULOOP:
            case WindowMessage.ENTERSIZEMOVE:
                // Entering the modal size/move loop: we don't want rendering to
                // stop during this time, so we register a timer callback to continue
                // processing from time to time.
                StartTimer(handle);
                break;

            case WindowMessage.EXITMENULOOP:
            case WindowMessage.EXITSIZEMOVE:
                // ExitingmModal size/move loop: the timer callback is no longer
                // necessary.
                StopTimer(handle);
                break;

            case WindowMessage.ERASEBKGND:
                return(new IntPtr(1));

            case WindowMessage.WINDOWPOSCHANGED:
                unsafe
                {
                    WindowPosition *pos = (WindowPosition *)lParam;
                    if (window != null && pos->hwnd == window.WindowHandle)
                    {
                        Point new_location = new Point(pos->x, pos->y);
                        if (Location != new_location)
                        {
                            bounds.Location = new_location;
                            Move(this, EventArgs.Empty);
                        }

                        Size new_size = new Size(pos->cx, pos->cy);
                        if (Size != new_size)
                        {
                            bounds.Width  = pos->cx;
                            bounds.Height = pos->cy;

                            Win32Rectangle rect;
                            Functions.GetClientRect(handle, out rect);
                            client_rectangle = rect.ToRectangle();

                            Functions.SetWindowPos(child_window.WindowHandle, IntPtr.Zero, 0, 0, ClientRectangle.Width, ClientRectangle.Height,
                                                   SetWindowPosFlags.NOZORDER | SetWindowPosFlags.NOOWNERZORDER |
                                                   SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING);

                            if (suppress_resize <= 0)
                            {
                                Resize(this, EventArgs.Empty);
                            }
                        }

                        // Ensure cursor remains grabbed
                        if (!CursorVisible)
                        {
                            GrabCursor();
                        }
                    }
                }
                break;

            case WindowMessage.STYLECHANGED:
                unsafe
                {
                    if (wParam.ToInt64() == (long)GWL.STYLE)
                    {
                        WindowStyle style = ((StyleStruct *)lParam)->New;
                        if ((style & WindowStyle.Popup) != 0)
                        {
                            windowBorder = WindowBorder.Hidden;
                        }
                        else if ((style & WindowStyle.ThickFrame) != 0)
                        {
                            windowBorder = WindowBorder.Resizable;
                        }
                        else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0)
                        {
                            windowBorder = WindowBorder.Fixed;
                        }
                    }
                }

                // Ensure cursor remains grabbed
                if (!CursorVisible)
                {
                    GrabCursor();
                }

                break;

            case WindowMessage.SIZE:
                SizeMessage state     = (SizeMessage)wParam.ToInt64();
                WindowState new_state = windowState;
                switch (state)
                {
                case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ?
                                                       WindowState.Maximized : WindowState.Normal; break;

                case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break;

                case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ?
                                                        WindowState.Fullscreen : WindowState.Maximized;
                    break;
                }

                if (new_state != windowState)
                {
                    windowState = new_state;
                    WindowStateChanged(this, EventArgs.Empty);
                }

                // Ensure cursor remains grabbed
                if (!CursorVisible)
                {
                    GrabCursor();
                }

                break;

                #endregion

                #region Input events

            case WindowMessage.CHAR:
                if (IntPtr.Size == 4)
                {
                    key_press.KeyChar = (char)wParam.ToInt32();
                }
                else
                {
                    key_press.KeyChar = (char)wParam.ToInt64();
                }

                KeyPress(this, key_press);
                break;

            case WindowMessage.MOUSEMOVE:
                Point point = new Point(
                    (short)((uint)lParam.ToInt32() & 0x0000FFFF),
                    (short)(((uint)lParam.ToInt32() & 0xFFFF0000) >> 16));
                mouse.Position = point;

                if (mouse_outside_window)
                {
                    // Once we receive a mouse move event, it means that the mouse has
                    // re-entered the window.
                    mouse_outside_window = false;
                    EnableMouseTracking();

                    MouseEnter(this, EventArgs.Empty);
                }
                break;

            case WindowMessage.MOUSELEAVE:
                mouse_outside_window = true;
                // Mouse tracking is disabled automatically by the OS

                MouseLeave(this, EventArgs.Empty);
                break;

            case WindowMessage.MOUSEWHEEL:
                // This is due to inconsistent behavior of the WParam value on 64bit arch, whese
                // wparam = 0xffffffffff880000 or wparam = 0x00000000ff100000
                mouse.WheelPrecise += ((long)wParam << 32 >> 48) / 120.0f;
                break;

            case WindowMessage.LBUTTONDOWN:
                Functions.SetCapture(window.WindowHandle);
                mouse[MouseButton.Left] = true;
                break;

            case WindowMessage.MBUTTONDOWN:
                Functions.SetCapture(window.WindowHandle);
                mouse[MouseButton.Middle] = true;
                break;

            case WindowMessage.RBUTTONDOWN:
                Functions.SetCapture(window.WindowHandle);
                mouse[MouseButton.Right] = true;
                break;

            case WindowMessage.XBUTTONDOWN:
                Functions.SetCapture(window.WindowHandle);
                mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) !=
                      (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = true;
                break;

            case WindowMessage.LBUTTONUP:
                Functions.ReleaseCapture();
                mouse[MouseButton.Left] = false;
                break;

            case WindowMessage.MBUTTONUP:
                Functions.ReleaseCapture();
                mouse[MouseButton.Middle] = false;
                break;

            case WindowMessage.RBUTTONUP:
                Functions.ReleaseCapture();
                mouse[MouseButton.Right] = false;
                break;

            case WindowMessage.XBUTTONUP:
                Functions.ReleaseCapture();
                mouse[((wParam.ToInt32() & 0xFFFF0000) >> 16) !=
                      (int)MouseKeys.XButton1 ? MouseButton.Button1 : MouseButton.Button2] = false;
                break;

            // Keyboard events:
            case WindowMessage.KEYDOWN:
            case WindowMessage.KEYUP:
            case WindowMessage.SYSKEYDOWN:
            case WindowMessage.SYSKEYUP:
                bool pressed =
                    message == WindowMessage.KEYDOWN ||
                    message == WindowMessage.SYSKEYDOWN;

                // Shift/Control/Alt behave strangely when e.g. ShiftRight is held down and ShiftLeft is pressed
                // and released. It looks like neither key is released in this case, or that the wrong key is
                // released in the case of Control and Alt.
                // To combat this, we are going to release both keys when either is released. Hacky, but should work.
                // Win95 does not distinguish left/right key constants (GetAsyncKeyState returns 0).
                // In this case, both keys will be reported as pressed.

                bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
                switch ((VirtualKeys)wParam)
                {
                case VirtualKeys.SHIFT:
                    // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit
                    // to distinguish between left and right keys. Moreover, pressing both keys and releasing one
                    // may result in both keys being held down (but not always).
                    // The only reliable way to solve this was reported by BlueMonkMN at the forums: we should
                    // check the scancodes. It looks like GLFW does the same thing, so it should be reliable.

                    // Note: we release both keys when either shift is released.
                    // Otherwise, the state of one key might be stuck to pressed.
                    if (ShiftRightScanCode != 0 && pressed)
                    {
                        unchecked
                        {
                            if (((lParam.ToInt64() >> 16) & 0xFF) == ShiftRightScanCode)
                            {
                                keyboard[Input.Key.ShiftRight] = pressed;
                            }
                            else
                            {
                                keyboard[Input.Key.ShiftLeft] = pressed;
                            }
                        }
                    }
                    else
                    {
                        // Windows 9x and NT4.0 or key release event.
                        keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed;
                    }
                    return(IntPtr.Zero);

                case VirtualKeys.CONTROL:
                    if (extended)
                    {
                        keyboard[Input.Key.ControlRight] = pressed;
                    }
                    else
                    {
                        keyboard[Input.Key.ControlLeft] = pressed;
                    }
                    return(IntPtr.Zero);

                case VirtualKeys.MENU:
                    if (extended)
                    {
                        keyboard[Input.Key.AltRight] = pressed;
                    }
                    else
                    {
                        keyboard[Input.Key.AltLeft] = pressed;
                    }
                    return(IntPtr.Zero);

                case VirtualKeys.RETURN:
                    if (extended)
                    {
                        keyboard[Key.KeypadEnter] = pressed;
                    }
                    else
                    {
                        keyboard[Key.Enter] = pressed;
                    }
                    return(IntPtr.Zero);

                default:
                    if (!KeyMap.ContainsKey((VirtualKeys)wParam))
                    {
                        Debug.Print("Virtual key {0} ({1}) not mapped.", (VirtualKeys)wParam, (long)lParam);
                        break;
                    }
                    else
                    {
                        keyboard[KeyMap[(VirtualKeys)wParam]] = pressed;
                    }
                    return(IntPtr.Zero);
                }
                break;

            case WindowMessage.SYSCHAR:
                return(IntPtr.Zero);

            case WindowMessage.KILLFOCUS:
                keyboard.ClearKeys();
                break;

                #endregion

                #region Creation / Destruction events

            case WindowMessage.CREATE:
                CreateStruct cs = (CreateStruct)Marshal.PtrToStructure(lParam, typeof(CreateStruct));
                if (cs.hwndParent == IntPtr.Zero)
                {
                    bounds.X      = cs.x;
                    bounds.Y      = cs.y;
                    bounds.Width  = cs.cx;
                    bounds.Height = cs.cy;

                    Win32Rectangle rect;
                    Functions.GetClientRect(handle, out rect);
                    client_rectangle = rect.ToRectangle();

                    invisible_since_creation = true;
                }
                break;

            case WindowMessage.CLOSE:
                System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs();

                Closing(this, e);

                if (!e.Cancel)
                {
                    DestroyWindow();
                    break;
                }

                return(IntPtr.Zero);

            case WindowMessage.DESTROY:
                exists = false;

                Functions.UnregisterClass(ClassName, Instance);
                window.Dispose();
                child_window.Dispose();

                Closed(this, EventArgs.Empty);

                break;

                #endregion
            }

            return(Functions.DefWindowProc(handle, message, wParam, lParam));
        }
Beispiel #47
0
 /// <summary>
 /// Sets window state
 /// </summary>
 public virtual void SetWindowState(WindowState windowState)
 {
 }
 void ICurrentWindowService.SetWindowState(WindowState state)
 {
     ActualWindow.Do(x => x.WindowState = state);
 }
Beispiel #49
0
 public static void SetWindowState(IntPtr hWnd, WindowState windowState)
 {
     ShowWindow(hWnd, (int)windowState);
 }
Beispiel #50
0
 public GameBuilder SetWindowState(WindowState state)
 {
     _game.WindowState = state;
     return(this);
 }
Beispiel #51
0
        protected virtual Tuple <WindowStyles, WindowExStyles, ShowWindowCommand> GetWindowStyles(WindowState state)
        {
            if (_options.UseCustomStyle && _options != null && _options.CustomStyle.IsValid())
            {
                return(GetWindowStyles(_options.CustomStyle, state));
            }

            var styles   = WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS;
            var exStyles = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE;

            if (_options.DisableResizing)
            {
                styles  = WindowStyles.WS_OVERLAPPEDWINDOW & ~WindowStyles.WS_THICKFRAME | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS;
                styles &= ~WindowStyles.WS_MAXIMIZEBOX;
            }

            if (_options.DisableMinMaximizeControls)
            {
                styles &= ~WindowStyles.WS_MINIMIZEBOX;
                styles &= ~WindowStyles.WS_MAXIMIZEBOX;
            }

            if (_options.WindowFrameless)
            {
                styles  = WindowStyles.WS_POPUPWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS;
                styles |= WindowStyles.WS_SIZEBOX;
            }

            if (_options.KioskMode)
            {
                styles   &= ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME);
                exStyles &= ~(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_STATICEDGE);
            }

            switch (state)
            {
            case WindowState.Normal:
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWNORMAL));

            case WindowState.Maximize:
            {
                styles |= WindowStyles.WS_MAXIMIZE;
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWMAXIMIZED));
            }

            case WindowState.Fullscreen:
            {
                styles  |= WindowStyles.WS_MAXIMIZE;
                exStyles = WindowExStyles.WS_EX_TOOLWINDOW;
                return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWMAXIMIZED));
            }
            }

            return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommand>(styles, exStyles, ShowWindowCommand.SW_SHOWNORMAL));
        }
Beispiel #52
0
 public WindowStateAction(WindowState state)
 {
     State = state;
 }
Beispiel #53
0
 partial void AfterWindowStateChanged()
 {
     Settings.Default.Main_WindowState = WindowState.ToString();
 }
Beispiel #54
0
 /// <summary> Sets window state. Maximise / Minimize / Restore. </summary>
 /// <param name="state"> The state to set. </param>
 /// <returns> True if it succeeds, false if it fails. </returns>
 public bool SetWindowState(WindowState state)
 {
     // TODO required for frameless Maccocoa mode
     return(false);
 }
 /// <summary>
 ///     Executes the minimize command.
 /// </summary>
 /// <param name="param">not used.</param>
 private void ExecuteMinimizeCommand(object param)
 {
     this.WindowState = WindowState.Minimized;
 }
 public void Close()
 {
     WindowState = WindowState.Closed;
 }
Beispiel #57
0
        private void Initialize(Game game)
        {
            Game = game;

            GraphicsContext.ShareContexts = true;

            window = new NativeWindow();
            window.WindowBorder = WindowBorder.Resizable;
            window.Closing     += new EventHandler <CancelEventArgs>(OpenTkGameWindow_Closing);
            window.Resize      += OnResize;
            window.KeyDown     += new EventHandler <OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
            window.KeyUp       += new EventHandler <OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyUp);

            window.KeyPress += OnKeyPress;

            var assembly = Assembly.GetEntryAssembly();
            var t        = Type.GetType("Mono.Runtime");

            Title = assembly != null?AssemblyHelper.GetDefaultWindowTitle() : "MonoGame Application";

            // In case when DesktopGL dll is compiled using .Net, and you
            // try to load it using Mono, it will cause a crash because of this.
            try
            {
                if (t == null && assembly != null)
                {
                    window.Icon = Icon.ExtractAssociatedIcon(assembly.Location);
                }
                else
                {
                    using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(string.Format("{0}.Icon.ico", Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace)) ??
                                        Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Xna.Framework.monogame.ico")) {
                        if (stream != null)
                        {
                            window.Icon = new Icon(stream);
                        }
                    }
                }
            }
            catch { }

            updateClientBounds = false;
            clientBounds       = new Rectangle(window.ClientRectangle.X, window.ClientRectangle.Y,
                                               window.ClientRectangle.Width, window.ClientRectangle.Height);
            windowState = window.WindowState;

            _windowHandle = window.WindowInfo.Handle;

            keys = new List <Keys>();

            // mouse
            // TODO review this when opentk 1.1 is released
#if DESKTOPGL || ANGLE
            Mouse.setWindows(this);
#else
            Mouse.UpdateMouseInfo(window.Mouse);
#endif

            // Default no resizing
            AllowUserResizing = false;

            // Default mouse cursor hidden
            SetMouseVisible(false);
        }
 public void Show()
 {
     WindowState = WindowState.Open;
 }
Beispiel #59
0
 /// <summary>Initializes a new instance of the <see cref="WindowManager" /> class.</summary>
 public WindowManager()
 {
     windowState = WindowState.Normal;
     resolution  = new Vector2(1024, 640);
     current     = this;
 }
 protected virtual void OnWindowStateChanged(WindowState windowState) => WindowStateChanged?.Invoke(windowState);