Working with windows as in Windows 7: update
The program for working with windows in Windows, the ideas and conveniences were borrowed from Windows 7. The program allows you to use the hot keys to move the window on the screen, place it in the stages of maximization, a regular window, and the main thing is to place windows maximized to half the screen. Works with Vista and WinXP (both x86 and x64).
Some errors were fixed in the new version of the program:
a) Dialog windows (those that cannot resize) were not minimized.
b) The program did not work with the Google Chrome window (more on this below).
And also the main features are added to move the window between screens .
You can download the new version from here .
First, a few words about the problem with Chrome. I did not find her. My version of chrome is 2.0.160.0, I tried it in Vista. But still, I made a separate assembly , in which I added such a check in the method for checking the window for IsResizableWindow
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 still wants to move the window to, then I had to do it forehead, go over all the screens, and those that touch (the contact side depends on the key pressed) and send it, here is the screen location code:
But there was a problem with FullScreen applications, namely, if, for example, the film was expanded to full screen and tried to transfer this window to another screen - nothing happened, it turned out that this window was not defined as having a WsSizeBox, so I had to recognize them in the following way (here can someone tell me something more competent):
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 to it. The essence is as follows:
1) At the initial maximization (with the help of a hotkey), the window does not
maximize, but changes to the specified size,
2) Secondary maximization already causes real maximization.
The reverse is the same.
Why this is needed:
On wide monitors with high resolution, full window maximization is
often not needed at all, but you
still have to enlarge the window to a certain size.
This functionality seemed to me not so necessary, at least I definitely won’t use it, if most people need it, I will include it somehow in my project.
First, a few words about the problem with Chrome. I did not find her. My version of chrome is 2.0.160.0, I tried it in Vista. But still, I made a separate assembly , in which I added such a check in the method for checking the window for IsResizableWindow
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 still wants to move the window to, then I had to do it forehead, go over all the screens, and those that touch (the contact side depends on the key pressed) and send it, here is 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 taking into account the 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, the film was expanded to full screen and tried to transfer this window to another screen - nothing happened, it turned out that this window was not defined as having a WsSizeBox, so I had to recognize them in the following way (here can someone tell me something more competent):
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 FullScreen windows across the screens, at some point they simply get lost, I realized that the window remains on the old screen, and I set the size and position of the new screen for it. Solution: when setting the dimensions, I have to first set the dimensions to a couple of pixels wide and less than the screen height (so that the window fits exactly on this screen only), and then restore it to FullScreen size, 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, then it flies to the previous screen, because there it was maximized and the window remembered that size and location, therefore it had to In such cases, write such a 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.
This is like all the unpleasant moments that 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 to it. The essence is as follows:
1) At the initial maximization (with the help of a hotkey), the window does not
maximize, but changes to the specified size,
2) Secondary maximization already causes real maximization.
The reverse is the same.
Why this is needed:
On wide monitors with high resolution, full window maximization is
often not needed at all, but you
still have to enlarge the window to a certain size.
This functionality seemed to me not so necessary, at least I definitely won’t use it, if most people need it, I will include it somehow in my project.