StringBuilder sb = new StringBuilder (100);
if (WAWindows.GetClassName(window, sb, sb.Capacity) != IntPtr .Zero
&& sb.ToString().StartsWith( "Chrome_" ))
return true ;
* This source code was highlighted with Source Code Highlighter .
private static Screen GetScreenToMove(Screen screen, Keys keys)
{
foreach (Screen scr in Screen.AllScreens)
{
if (!scr.Equals(screen))
{
switch (keys)
{
case Keys.Left:
if (scr.WorkingArea.Right == screen.WorkingArea.Left
&& scr.WorkingArea.Top == scr.WorkingArea.Top)
return scr;
break ;
case Keys.Right:
if (scr.WorkingArea.Left == screen.WorkingArea.Right
&& scr.WorkingArea.Top == scr.WorkingArea.Top)
return scr;
break ;
case Keys.Down:
if (scr.WorkingArea.Top == screen.WorkingArea.Bottom
&& scr.WorkingArea.Left == scr.WorkingArea.Left)
return scr;
break ;
case Keys.Up:
if (scr.WorkingArea.Bottom == screen.WorkingArea.Top
&& scr.WorkingArea.Left == scr.WorkingArea.Left)
return scr;
break ;
}
}
}
return null ;
}
* This source code was highlighted with Source Code Highlighter .
Then you just need to send the window to the selected screen, I send the window according to proportions, that is: if the window occupied 50% of the screen, it will occupy the same amount on the new screen.private static bool IsFullScreenWindow(WAWindows.Rect rect, Screen scr)
{
return rect.Left == scr.Bounds.Left && rect.Top == scr.Bounds.Top
&& rect.Width == scr.Bounds.Width && rect.Height == scr.Bounds.Height;
}
* This source code was highlighted with Source Code Highlighter .
Another interesting fact is that when I moved the FullScreen windows around the screens, then at some point they just get lost, I realized that the window remains on the old screen, and I give it the new screen the size and position. Solution: when setting the dimensions, I first have to set the dimensions a couple of pixels wide and less than the screen height (so that the window is located exactly on this screen), and then restore to FullScreen sizes, it looks like this// Fix for full screen windows
if (isFullScreenWindow)
WAWindows.SetWindowPos(window, WAWindows.HwndTop, x + 1, y + 1, cx - 2, cy - 2, WAWindows.SwpShowWindow);
WAWindows.SetWindowPos(window, WAWindows.HwndTop, x, y, cx, cy, WAWindows.SwpShowWindow);
* This source code was highlighted with Source Code Highlighter .
Another unpleasant moment was that when the window on one screen is maximized, we move it to another screen, and then restore it to Normal, it flies to the previous screen, because there it was maximized and the window remembered that size and location, so we had to such cases write the following FIX:// Fixed problem with restore on other screen
Screen newScreen = Screen.FromHandle(window);
if (!newScreen.Equals(screen))
{
if (WAWindows.GetWindowRect(window, out rect))
MoveToNewScreen(window, newScreen, screen, rect, isResizableWindow, false );
}
* This source code was highlighted with Source Code Highlighter .
It seems to be all the unpleasant moments I encountered. If you have any suggestions or comments, I will listen to them with pleasure.Source: https://habr.com/ru/post/58527/
All Articles