Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
dracho
16 discussion posts
This code contains what I need, but I'm not sure how to modify it to suit my needs. It cycles between resizing and moving the active window to the left third, middle third, and right third.

I want separate buttons for middle third and right third. I have left third already.

Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
// - Active window when run by hotkey
// - Window Location target when run by a Window Location rule
// - TitleBar Button owner when run by a TitleBar Button
// - Jump List owner when run from a Taskbar Jump List
// - Currently focused window if none of these match

public static class DisplayFusionFunction
{
           public static void Run(IntPtr windowHandle)
           {          
                     //check to see if there was an error, if there was, exit function
                     if (windowHandle == IntPtr.Zero)
                                return; 

                     //get the position of the window in the monitor, and the current monitor
                     Rectangle windowRect = BFS.Window.GetBounds(windowHandle);
                     Rectangle monitorRect = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);                     

                     int iFinalWinX = monitorRect.X;
                     int iFinalWinY = monitorRect.Y;
                     int iFinalWinW = monitorRect.Width / 3;
                     int iFinalWinH = monitorRect.Height; 

                     if(        windowRect.X == iFinalWinX  
                     /*        && windowRect.Y == iFinalWinY
                                &&      windowRect.Width == iFinalWinW
                                &&      windowRect.Height == iFinalWinH )                  {
                                iFinalWinX = monitorRect.X + iFinalWinW;  
                     } else if (windowRect.X == iFinalWinX + iFinalWinW) */
                     { iFinalWinX = monitorRect.X + 2*iFinalWinW;
                     } else if (windowRect.X == iFinalWinX + 2*iFinalWinW) {
                                iFinalWinX = monitorRect.X;
                     }                                

                     BFS.Window.SetSizeAndLocation(windowHandle, iFinalWinX, iFinalWinY, iFinalWinW, iFinalWinH );
           }
}
Nov 29, 2018  • #1
User Image
dracho
16 discussion posts
P.S. I almost forgot, I would also love a cycle-type button, similar to the one I posted above, that resizes to 50% vertical and moves to the top, then moves to the bottom when clicked again, etc. Once I understand the code above a bit better, I should be able to do this on my own, unless you feel so inclined to help further. :) Thanks.
Nov 29, 2018  • #2
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Were you able to get the separate buttons working with the Custom Functions you were mentioning in the other thread?

For the other script are you wanting it to cycle between 50% height, 100% width on the top, and the same on the bottom?
Nov 30, 2018  • #3
User Image
dracho
16 discussion posts
Ideally, I would like to understand the code better so that I can tweak things to my liking.

In the code snippet I pasted, could you (or someone) add comments to explain where the 33% width is determined, where the location of the window is determined, and how the cycling works between three locations?

In the end, I'll want a single button that cycles between these 3 functions: Size to 33% Width and Center Horizontally on Monitor (this is included in the code snippet, when the button is clicked twice), Size and Move Window to Top of Monitor, and Size and Move to Bottom (these two are built-in).

I will also want a button that cycles between these 2 functions: Size and Move Window (50%) to Left Side of Monitor, and Size and Move Window (33%) to Left Side of Monitor (again, this is included in the code snippet, when the button is clicked once).

Finally, I want a button that is the inverse of the one mentioned above - focusing on the right side instead of the left.

Thanks very much! :)

(EDIT: Reworded description of first button to properly represent the order in which I want to click it - first Center, then Top, then Bottom.)
Nov 30, 2018 (modified Nov 30, 2018)  • #4
Keith Lammers (BFS)'s profile on WallpaperFusion.com
The 33% is determined on line 25 by dividing the monitor width by 3:

int iFinalWinW = monitorRect.Width / 3;

The windowRect near the top is what gets the current window size, and further down it gets compared to the target size determined by iFinalWinX/Y/W/H.

The script you want to write would be pretty complicated, but is possible to do. Basically, you'd need to know your desired size/locations, then compare the current size to figure out if it's already at one of them and load the next size. In reality, that's trickier than it sounds :)
Nov 30, 2018  • #5
User Image
dracho
16 discussion posts
Ok, thanks for the reply.

I can make my request much simpler. I would be very happy to have a button that performs only one function: Size the window to 33% width and move it to the Right side of the screen.

Using the code that you will hopefully graciously give me, I should be able to make my own button that does the exact same thing; only one function (no cycling) that will size to 33% and move to the Left side.

Thank you much!
Dec 8, 2018  • #6
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, try this out:

Code

using System;
using System.Drawing;

public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // Set the window width percentage here
        double windowWidthPercent = 0.33;
        
        // Get the monitor bounds
        Rectangle monitorBounds = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle);
        
        // Create the target window bounds
        Rectangle targetWindowBounds = new Rectangle();
        
        // Set the target window width to the screen width * the windowWidthPercent
        targetWindowBounds.Width = Convert.ToInt32(monitorBounds.Width * windowWidthPercent);
        
        // Set the target window height to 100% of the screen height
        targetWindowBounds.Height = monitorBounds.Height;
        
        // Set the target X value to monitor X + monitor width - window width
        targetWindowBounds.X = (monitorBounds.X + monitorBounds.Width) - targetWindowBounds.Width;
        
        // Set the target Y value to the top of the monitor
        targetWindowBounds.Y = monitorBounds.Y;
        
        // Resize and move the window
        BFS.Window.SetSizeAndLocation(windowHandle, targetWindowBounds.X,  targetWindowBounds.Y, targetWindowBounds.Width, targetWindowBounds.Height);
    }
}


The left side is much easier, you just need to change the calculation to:

targetWindowBounds.X = monitorBounds.X;

And if you want to do the middle, do this:

targetWindowBounds.X = monitorBounds.X + targetWindowBounds.Width;

Hope that helps!
Dec 10, 2018  • #7
User Image
dracho
16 discussion posts
Just wanted to say thanks again. I think I've settled on 7 buttons- Left 33%, 50%, 66%, Right 33%, 50%, 66%, and "Portrait Squeeze" that sizes the window perfectly on my portait monitor without overlapping my Rainmeter skins. :)

I've still got a lot to tweak, but I'm making steady progress. WIP screenshot just for kicks :)
• Attachment: 2018-12-17_07-02-10.jpg [1,382,257 bytes]
2018-12-17_07-02-10.jpg
2018-12-17_07-02-10.jpg
Dec 18, 2018  • #8
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Excellent, glad to hear it!
Dec 18, 2018  • #9
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Make sure to backup your settings (Settings > Options > Export) when you're done, just so you don't lose all of that work!
Dec 18, 2018  • #10
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)