StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Patrick97  
#1 Posted : Saturday, June 12, 2021 8:34:57 AM(UTC)
Patrick97

Rank: Member

Reputation:

Groups: Approved
Joined: 5/18/2020(UTC)
Posts: 15

Thanks: 6 times
Hi everyone, I'm trying to create a script which could allow to open two or three windows (e.g. sp.Run("C:\\D\\PrgInternet"), .... without overlapping each other.
The ideal for me would be something like this:

2 windows case scenario:
1st window opens and goes to the left part of the screen (50%)
2nd windows opens and goest to the (remaining) left part of the screen (50%)


3 windows case scenario:
1st window opens and goes to the left part of the screen (33%)
2nd windows opens and goes to the central part of the screen (33%)
3rd windows opens and goes to the right part of the screen (33%)

I tried to associate the "movement" of the windows to some shortcuts (I use AquaSnap to do that, e.g. Alt + A -> windows to the right part of the screen, ....) but I failed.

If there is a way, It would be wonderful, and it would save me a lot of "clicks"...

thanks
Rob  
#2 Posted : Monday, June 14, 2021 6:22:04 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
So the only part of this which is slightly complicated is launching and identifying the windows. Moving/sizing them is very simple.

This will move a window to the left half of the screen where the window resides:
Code:
// If window is maximized, restore first
if(action.Window.Maximized) {
    action.Window.Restore();
}

// Split screen into 2 columns, 1 row (50/50 in the middle)
// This uses the screen where the window mostly resides
// .WorkingArea excludes the taskbar and any other fixed bars
var screenRegions = sp.GetRegions(action.Window.Screen.WorkingArea, 2, 1);

// Get the column Rectangle of the first column (left half of screen)
// RectRegion.Rect is a RectangleF (float), so it needs to be converted
// to a whole number only Rectangle first
var leftColRectangle = Rectangle.Round(screenRegions.First(r => r.Column == 1).Rect);

// Move/size the window to rectangle for column 1
action.Window.Rectangle = leftColRectangle;

This would do the right half of the screen:
Code:
// If window is maximized, restore first
if(action.Window.Maximized) {
    action.Window.Restore();
}

// Split screen into 2 columns, 1 row (50/50 in the middle)
// This uses the screen where the window mostly resides
// .WorkingArea excludes the taskbar and any other fixed bars
var screenRegions = sp.GetRegions(action.Window.Screen.WorkingArea, 2, 1);

// Get the column Rectangle of the first column (right half of screen)
// RectRegion.Rect is a RectangleF (float), so it needs to be converted
// to a whole number only Rectangle first
var rightColRectangle = Rectangle.Round(screenRegions.First(r => r.Column == 2).Rect);

// Move/size the window to rectangle for column 2
action.Window.Rectangle = rightColRectangle;

This splits the screen into 3 columns and moves the window to the middle one:
Code:
// If window is maximized, restore first
if(action.Window.Maximized) {
    action.Window.Restore();
}

// Split screen into 3 columns, 1 row (33/33/33)
// This uses the screen where the window mostly resides
// .WorkingArea excludes the taskbar and any other fixed bars
var screenRegions = sp.GetRegions(action.Window.Screen.WorkingArea, 3, 1);

// Get the column Rectangle of the second column (middle section of screen)
// RectRegion.Rect is a RectangleF (float), so it needs to be converted
// to a whole number only Rectangle first
var middleColRectangle = Rectangle.Round(screenRegions.First(r => r.Column == 2).Rect);

// Move/size the window to rectangle for column 2
action.Window.Rectangle = middleColRectangle;


However, like I said launching 3 apps and repositioning them is a little trickier, as you need to wait for them to open and make sure you properly identify each one. It can be done, but without very specific details, it's not something I can easily put together.
thanks 1 user thanked Rob for this useful post.
Patrick97 on 6/15/2021(UTC)
Patrick97  
#3 Posted : Tuesday, June 15, 2021 9:22:43 AM(UTC)
Patrick97

Rank: Member

Reputation:

Groups: Approved
Joined: 5/18/2020(UTC)
Posts: 15

Thanks: 6 times
Thank you very much for your kind answer.

I am totally a newbie with this great software, and I have very scarse knowledge of PC stuff, so perhaps I haven't made mysefl perfectly clear with my question. I try to explain with further details:

- I would like to create a script for opening 2 (and 3, with another script) windows at the same time, and I would like that the 2 windows (or 3) occupy the whole screen:

2 windows: one at the right of the screen (50% of the screen), the other at the left (remaining 50%).
3 windows: one at the right (33%), one at the center (33%), the other at the right (remainig 33%)

- The windows could be already opened (in the taskbar), or closed. The ideal would be that the script worked even if they (or some of them) could be even displayed in the screen "somewhere", but not in the wanted position.

- The windows are folder windows, not .exe file. E.g.:

- C:\D\Photo
- C:\D\Music\2021
- C:\D\Doc\Patrick

I hope I have explained in a better way what I wish... if there is a way of creating a script which could do those task it wuold be awesome.

P.S.: I tried to understand the script you wrote, but they are way too complicated for me to understand; moreover I do not see where I could put the 2 (or) 3 directories of the folders in order to make them working.

Thanks again.
Rob  
#4 Posted : Tuesday, June 15, 2021 1:50:39 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This works for me, as you can see it is a bit complicated. I may not always be available to put together complex scripts like this, so spend some time reading through it and try to make your other 50/50 on your own :)

I will help you if you're having trouble, but I like to empower people to learn!

Code:
// Initialize window variables
var wndPhotos = null;
var wndMusic = null;
var wndDocs = null;

// I made this code a function since it could be executed twice, 
// to prevent having a copy of the code in the script
function FindWindows() 
{
    // Get all main windows and loop through each one
    var allApps = sp.AllApplications();
    for (var i = 0, len = allApps.Length; i < len; i++) 
    {
        // If the window is owned by Explorer.exe
        if(allApps[i].Process.MainModule.ModuleName.toLowerCase() == "explorer.exe") 
        {
            // Get the folder path of the explorer window
            var explorerPath = sp.GetActiveExplorerPath(allApps[i].HWnd);
            // Assign window variables if path matches
            switch(explorerPath) 
            {
                case "C:\\D\\Photo":
                    wndPhotos = allApps[i];
                    break;
                case "C:\\D\\Music\\2021":
                    wndMusic = allApps[i];
                    break;
                case "C:\\D\\Doc\\Patrick":
                    wndDocs = allApps[i];
                    break;
            }
        }
    }
}

// Call function to find any windows already open
FindWindows();

// If any of them are not found, check each one and open
if(wndPhotos == null || wndMusic == null || wndDocs == null) 
{
    if(wndPhotos == null) {
        sp.Run("C:\\D\\Photo");
    }
    if(wndMusic == null) {
        sp.Run("C:\\D\\Music\\2021");
    }
    if(wndDocs == null) {
        sp.Run("C:\\D\\Doc\\Patrick");
    }

    // Pause 350 milliseconds to let windows open
    // Increase or decrease as needed
    sp.Sleep(350);

    // Call function to find windows again
    FindWindows();
}

// If any window is maximized, restore first
if(wndPhotos.Maximized) 
{
    wndPhotos.Restore();
}
if(wndMusic.Maximized) 
{
    wndMusic.Restore();
}
if(wndDocs.Maximized) 
{
    wndDocs.Restore();
}

// Bring all of them to the foreground
wndPhotos.Activate();
wndMusic.Activate();
wndDocs.Activate();

// Split screen into 3 columns, 1 row (33/33/33)
// This uses the screen where the mouse cursor is located
// .WorkingArea excludes the taskbar and any other fixed bars
var screenRegions = sp.GetRegions(Screen.FromPoint(sp.GetCurrentMousePoint()).WorkingArea, 3, 1);

// Move the windows to the new locations
// RectRegion.Rect is a RectangleF (float), so it needs to be converted
// to a whole number only Rectangle first
wndPhotos.Rectangle = Rectangle.Round(screenRegions.First(r => r.Column == 1).Rect)
wndMusic.Rectangle = Rectangle.Round(screenRegions.First(r => r.Column == 2).Rect)
wndDocs.Rectangle = Rectangle.Round(screenRegions.First(r => r.Column == 3).Rect)
thanks 1 user thanked Rob for this useful post.
Patrick97 on 6/15/2021(UTC)
Patrick97  
#5 Posted : Tuesday, June 15, 2021 3:22:12 PM(UTC)
Patrick97

Rank: Member

Reputation:

Groups: Approved
Joined: 5/18/2020(UTC)
Posts: 15

Thanks: 6 times
Thanks... "a bit complicated" is "a bit" an understatement for me... as I said, I approached this software and its mechanism only a few days ago, and my knowledge of PC is basically... "around zero".

I will try this script, and I'll try to understand its logics and its rules...

thanks again, and A BIG CIAO AND GRAZIE From Italy!
Gilers  
#6 Posted : Wednesday, December 28, 2022 7:33:37 AM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

hello rob
Your contribution has helped me, thank you very much, but it's almost there and needs your help.
I tried to divide the screen into 3 rows and 4 columns and put 12 google browsers in each area. 1,2,3,4 are all successful. But it fails at 5. Prompt the following error, can you help me solve it?
I read your code carefully, but still don't know how to implement, please help me, thanks.

This is the error message
UserPostedImage

Here is my script
UserPostedImage

Edited by user Wednesday, December 28, 2022 7:37:02 AM(UTC)  | Reason: Not specified

Gilers  
#7 Posted : Wednesday, December 28, 2022 11:23:21 AM(UTC)
Gilers

Rank: Member

Reputation:

Groups: Approved
Joined: 4/27/2020(UTC)
Posts: 18
Korea, Republic Of

I found the solution on other posts.
UserPostedImage


This allows you to move not only to columns, but also to rows.

But if I have more than 12 windows, I want to arrange them to the second screen, how to achieve this?
Rob  
#8 Posted : Wednesday, December 28, 2022 6:15:09 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Try specifying a location on your overall desktop (all screens) to target the other screen:
Code:
// This point (coordinates) are on my second screen
var pt = new Point(1921, 0);

var screenRegions = sp.GetRegions(System.Windows.Forms.Screen.FromPoint(pt).WorkingArea, 4, 3);
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.