[API Proposal] System.Windows.WindowStartupMonitor
See original GitHub issueIn times of multi monitor setup I would like to propose a new API that allows us to set the startup monitor of the window. I am open for naming changes. The reason is that many developers would prefer to use/keep the WindowStartupLocation.CenterScreen
but only change the monitor from “the monitor on which the mouse is currently located” to a fixed monitor.
The way to do this ourselves is tedious. Enumerating all screens, calculating the center, use WinAPIs to move the window. WindowStartupMonitor
could be an integer which stands for the index of the monitor. By default it could be -1
which means “the monitor on which the mouse is currently located”.
Ideas? Suggestions?
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:18 (18 by maintainers)
Top Results From Across the Web
SplashScreen Class (System.Windows)
Use the SplashScreen class to show an image in a startup window, or splash screen, when a WPF application starts. Call the Show...
Read more >Positioning Objects on Multiple Display Monitors
A window or menu that is on more than one monitor causes visual disruption for a viewer. To minimize this problem, the system...
Read more >STARTUPINFOW (processthreadsapi.h) - Win32 apps
Specifies the window station, desktop, standard handles, and appearance of the main window for a process at creation time. (Unicode)
Read more >Windows API index - Win32 apps
The Windows UI API creates and uses windows to display output, prompt for user input, and carry out the other tasks that support...
Read more >The Display-Aware Application (Windows)
You can design your application to determine the display configuration when the user starts it, and to detect changes after startup.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Exactly what I was talking about in terms of messing with the OS window management 😃 and this is just more of it.
Since that is already the case though I am changing my position here and would entertain the idea of adding some API to make it simpler. The issue of monitory identity, however, remains. WPF does not use the WinForm’s
Screen
class. The numbering via the “Identify Monitors” features in Settings is an implementation detail and also uses values like “1|2”. I don’t see any guarantees for HMONITOR to be stable or for EnumDisplayMonitors to enumerate monitors in the same order. I am guessing that might be one of the reasons for theScreen
class to cache the results and throw them away when the monitors change.If by “monitor” you mean HMONITOR, then yes, you can easily give the existing code a different HMONITOR. The difficult part is finding the HMONITOR that you want.
If you want the user to specify the monitor (or have the window open at the same monitor it was on last time), it looks like using either monitor name or the
MonitorFromPoint
could do the trick. Name could be useful for scenarios like “I want the monitor with HDR, regardless on which side it is”, but it would require to basically duplicate all theScreen
class functionality for developers to find out the current monitor’s name. TheMonitorFromPoint
on the other hand I would think is more promising. For example,Window
could have an overridable method that would return a point on the monitor it should appear on, defaulting to the mouse cursor point. Would that address your scenario?The problem is that unless you want a primary monitor or the monitor the window was last on, it takes non-trivial code to figure out which screen you want. For example, imagine an application like PowerPoint, where you want to show the presentation on a different monitor than the current window is. You still need to find out which monitor the current window is on and which is the other monitor available. If you want to display a window on the left monitor, you have to enumerate the monitor rectangles and figure out which one is on the left. Even if you assumed that EnumDisplayMonitors returns always the same order, I don’t really see a scenario where you would supply a random index without doing some non-trivial work of finding out what the index should be.
No. And for WPF applications as I said in the very first post, if
CenterScreen
is used WPF automatically chooses the monitor where the cursor is. So even IF Windows does that by default (which it does NOT), it wouldn’t work for WPF. My API proposal allows both, launching + centered on a specific screen.