ScreenManager
public static class ScreenManager
Defines a set of methods for managing windows on different screens.
Enums
Properties
Functions
- SendToPrimary()
- SendToSecondary()
- SwapScreen()
- SendToScreen()
- ExtendScreens()
- CloneScreens()
- SetInternal()
- SetExternal()
- SendProgramsMainWindowToScreen()
- SendProgramsWindowsToScreen()
- getProcessWindowByName()
- getScreenFromWindow()
- getWindowHandlesFromScreen()
- getWindowHandlesFromProgramName()
- AlignmentToOffset()
- getDPI()
- getDPIRatio()
Enums
DisplayConfigTopology
enum DisplayConfigTopology
represents different display modes
- Internal - Disconnect Projector
- Clone - Duplicate
- Extend
- External - Projector only
ScreenAlignment
enum ScreenAlignment
represents different screen alignments
- None
- Center
- Left
- Right
- Top
- Bottom
Example:
ScreenManager.SendToSecondary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);
Properties
SecondaryScreen
static Screen SecondaryScreen { get; }
will return the first screen which is not a primary screen or null if there is only one screen. this will work assuming the first screen that is not the primary screen is the second screen. works only on extended mode
PrimaryScreen
static Screen PrimaryScreen { get; }
will return the primary screen
CurrentTopology
static DisplayConfigTopology CurrentTopology { get; set; }
DisplayConfigTopology of current state
Example:
ScreenManager.CurrentTopology = ScreenManager.DisplayConfigTopology.External;
NumberOfDisplays
static uint NumberOfDisplays
The number of displays, even on clone or internal/external
Functions
SendToPrimary()
static bool SendToPrimary(Window window, ScreenAlignment align)
static bool SendToPrimary(Window window, int offsetX = 0, int offsetY = 0)
static bool SendToPrimary(IntPtr hwnd, ScreenAlignment align)
static bool SendToPrimary(IntPtr hwnd, int offsetX = 0, int offsetY = 0)
Sends a window to the primary screen
Parameters:
- Window window/IntPtr hwnd
- to send to the primary screen
- ScreenAlignment align / int offsetX+offsetY
- Screen alignment / offset
Return value
indicates success and failure
Example:
ScreenManager.SendToPrimary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);
SendToSecondary()
static bool SendToSecondary(Window window, ScreenAlignment align)
static bool SendToSecondary(Window window, int offsetX = 0, int offsetY = 0x)
static bool SendToSecondary(IntPtr hwnd, ScreenAlignment align)
static bool SendToSecondary(IntPtr hwnd, int offsetX = 0, int offsetY = 0)
Sends a window to the secondary screen
Parameters:
- Window window/IntPtr hwnd
- to send to the secondary screen
- ScreenAlignment align / int offsetX+offsetY
- Screen alignment / offset
Return value
indicates success and failure
Example:
ScreenManager.SendToSecondary(myWindow, ScreenAlignment.Center | ScreenAlignment.Right);
SwapScreen()
static bool SwapScreen(Window window, ScreenAlignment align)
static bool SwapScreen(Window window, int offsetX = 0, int offsetY = 0)
static bool SwapScreen(IntPtr hwnd, int offsetX = 0, int offsetY = 0)
static bool SwapScreen(IntPtr hwnd, ScreenAlignment align)
Sends a window to from primary screen to secondary or from secondary screen to primary screen.
Parameters:
- Window window/IntPtr hwnd
- window/window handle to send
- ScreenAlignment align / int offsetX+offsetY
- Screen alignment / offset
Return value
indicates success and failure. failure will denote when there aren't enough displays or the current screen topology is not extend and the extend mark is set to false
Example:
ScreenManager.SwapScreen(myWindow, ScreenAlignment.Bottom);
SendToScreen()
static bool SendToScreen(Window window, Screen screen, ScreenAlignment align)
static bool SendToScreen(Window window, Screen screen, int offsetX = 0, int offsetY = 0)
static bool SendToScreen(IntPtr hwnd, Screen screen, ScreenAlignment align)
static bool SendToScreen(IntPtr hwnd, Screen screen, int offsetX = 0, int offsetY = 0)
Sends a window to a screen.
Parameters:
- Window window/IntPtr hwnd
- window/window handle to send
- Screen screen
- to send to
- ScreenAlignment align / int offsetX+offsetY
- Screen alignment / offset
Return value
indicates success and failure.
Example:
ScreenManager.SendToScreen(myWindow, ScreenManager.SecondaryScreen, ScreenAlignment.Left);
ExtendScreens()
xstatic bool ExtendScreens()
Changes CurrentTopology to DisplayConfigTopology.Extend
Return value
indicates success and failure.
CloneScreens()
static bool CloneScreens()
Changes CurrentTopology to DisplayConfigTopology.Clone
Return value
indicates success and failure.
SetInternal()
static bool SetInternal()
Changes CurrentTopology to DisplayConfigTopology.Internal
Return value
indicates success and failure.
SetExternal()
static bool SetExternal()
Changes CurrentTopology to DisplayConfigTopology.External
Return value
indicates success and failure.
SendProgramsMainWindowToScreen()
static bool SendProgramsMainWindowToScreen(string progName, Screen screen, ScreenAlignment align)
Sends the main window of a program to screen
Parameters:
- string progName
- The name of the program
- Screen screen
- Screen to send the window to
- ScreenAlignment align
- alignment on screen
Return value
bool to indicate success or failure
SendProgramsWindowsToScreen()
static bool SendProgramsWindowsToScreen(string progName, Screen screen, ScreenAlignment align)
Sends all window of a program to a screen
Parameters:
- string progName
- The name of the program
- Screen screen
- Screen to send the window to
- ScreenAlignment align
- alignment on screen
Return value
bool to indicate success or failure
Example:
ScreenManager.SendProgramsWindowsToScreen("chrome", ScreenManager.SecondaryScreen, ScreenAlignment.Center);
getProcessWindowByName()
static IntPtr[] getProcessWindowByName(string proccessName)
Returns an array of window handles of all processes with the name [processName]
Parameters:
- string processName
- The name of the process
Return values
an array of window handles of all processes with the name [processName]
getScreenFromWindow()
static Screen getScreenFromWindow(Window window)
static Screen getScreenFromWindow(IntPtr hwnd)
Retrieves a Screen for the display that contains the largest portion of the window
Parameters:
- Window window
- to get screen from
Return values
The Screen for the display that contains the largest portion of the window
getWindowHandlesFromScreen()
static IntPtr[] getWindowHandlesFromScreen(Screen screen)
returns an array of window handles in a given screen
Parameters:
- Screen screen
- A screen
Return value
an array of window handles in given screen
getWindowHandlesFromProgramName()
static IntPtr[] getWindowHandlesFromProgramName(string progName))
returns an array of window handles associated with a program name
Parameters:
- String progName
- program name
Return value
an array of window handles associated with a program name
AlignmentToOffset()
static Point? AlignmentToOffset(Window window, Screen screen, ScreenAlignment alignment)
static Point? AlignmentToOffset(IntPtr hwnd, Screen screen, ScreenAlignment alignment)
Converts ScreenAlignment to Offset. alignment is depend on the window and the screen
Parameters:
- Window window/IntPtr hwnd
- WPF Window/window handle
- Screen screen
- Screen
- ScreenAlignment align
- alignment on screen
Return value
Point? - the offset or null in case of a problem
geDPI()
public static Point getDPI()
Returns the current dpi ((96.0,96.0) is default)
geDPIRatio()
public static Point getDPIRatio()
Returns the current dpi ratio ((96.0, 96.0) will be (1.0,1.0))