📜 ⬆️ ⬇️

Working with windows as in Windows 7: update

The program for working with windows in Windows, ideas and conveniences were borrowed from Windows 7. The program allows using the hot keys to move the window around the screen, place it in the maximization stages, the usual window, as well as the most basic - place the windows maximized on half the screen. Works with Vista and WinXP (both x86 and x64).

In the new version of the program some bugs were fixed:
a) Dialog boxes (those that cannot resize) have not been minimized.
b) The program did not work with the Google Chrome window (more on this in more detail below).
As well as the main added ability to move the window between screens .
Download the new version from here .

First, a few words about the problem with Chrome. I did not find it. I have a version of chromium 2.0.160.0, I tried it in Vista. But still, I made a separate assembly , in which in the window check method on IsResizableWindow I added such a check
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 .

It seems to work.

Now about moving the window between the screens. The task was not so difficult. The first thing to do is to determine which monitor the user wants to move the window to, I had to go to the forehead, run through all the screens, and those that are in contact (the side of contact depends on the key pressed) and send there, here’s the screen location code:
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.
But there was a problem with FullScreen applications, namely, if, for example, a movie was maximized and tried to transfer this window to another screen, nothing happened, it turned out that this window was not defined as having WsSizeBox, so I had to recognize them in the following way ( can someone tell me something more literate):
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.
')
PS I also received a letter with a proposal and a patch from Andir R with the following words:

Added the possibility of double maximization. The essence is as follows:
1) During initial maximization (using hotkey), the window is not
maximized, and changed to a given size,
2) Secondary maximization already causes true maximization.

In the reverse order acts similarly.

Why do you need it:
On widescreen monitors with high resolution, the window is maximized;
Often, not needed at all, but to increase the window to certain
sizes still have to.

It seemed to me that this functionality is not so necessary, at least I will not use it for sure, if I need it to the majority of the people, I will include it in my project somehow.

Source: https://habr.com/ru/post/58527/


All Articles