Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
heyo
1 discussion post
Hi guys,
I wanted to create a script to open up specific folders and positioning them. The problem is that the BFS.Application.Start(..) function returns an appID that has something to do with the new explorer window but it does not correspond to the actual window. Because of this I can't get the windowHandle to position an resize the new window.

This is my current code I'm using.

Code

using System.IO;
using System.Threading;
private static int openFolder(string path, uint screen, int xn, int yn) {
        if (!Directory.Exists(path)) return 1;

        uint appId = BFS.Application.Start("C:\\Windows\\explorer.exe", path);
        
        int width = 795, height = 495;
        Rectangle bounds = BFS.Monitor.GetMonitorBoundsByID(screen);

        xn = 3 - xn; yn = 3 - yn;
        int x = bounds.Width - xn * width;
        int y = bounds.Height - yn * height;
        if (x < 0) x = 0;
        if (y < 0) y = 0;

        while (BFS.Application.IsAppRunningByAppID(appId))
            Thread.Sleep(250);
        
        IntPtr windowHandle = IntPtr.Zero;
        var allWindows = BFS.Window.GetAllWindowHandles();
        foreach (var wh in allWindows) {
            if (appId == BFS.Application.GetAppIDByWindow(wh)) {
                BFS.Dialog.ShowMessageError("aha1");
                windowHandle = wh;
                break;
            }
            else if ("TITLE_OF_THE_OPENEND_FOLDER" == BFS.Window.GetText(wh)) {
                BFS.Dialog.ShowMessageError("aha2 ai: " + BFS.Application.GetAppIDByWindow(wh));
                windowHandle = wh;
                break;
            }
        }
        
        BFS.Dialog.ShowMessageError("ai: " + appId + ", wh: " + windowHandle + "  " + allWindows.Length);
        setSizeLocMon(windowHandle, x, y, width, height, screen); //just BFS.Window.SetSizeAndLocation and MoveToMonitor
        return 0;
}


As long as this app is running the window still does not exist, as far as I noticed. That's why I'm checking if it still runs.

Code

while (BFS.Application.IsAppRunningByAppID(appId))
            Thread.Sleep(250);


Is there a solution to this problem?
Nov 27, 2017 (modified Nov 27, 2017)  • #1
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
The Windows Explorer process can be a little strange, and not really communicate what it's actually doing behind the scenes. This is because it might not actually start up another process to open a new Explorer window. I've modified the function you posted to use the current foreground windows instead of the app id. Here it is:

Code

private static int openFolder(string path, uint screen, int xn, int yn) {
    if (!Directory.Exists(path)) return 1;

    IntPtr foregroundWindow = BFS.Window.GetFocusedWindow();
    uint appId = BFS.Application.Start("C:\\Windows\\explorer.exe", path);
    
    int width = 795, height = 495;
    Rectangle bounds = BFS.Monitor.GetMonitorBoundsByID(screen);

    xn = 3 - xn; yn = 3 - yn;
    int x = bounds.Width - xn * width;
    int y = bounds.Height - yn * height;
    if (x < 0) x = 0;
    if (y < 0) y = 0;

    while (BFS.Window.GetFocusedWindow().Equals(foregroundWindow))
        Thread.Sleep(250);
    
    setSizeLocMon(BFS.Window.GetFocusedWindow(), x, y, width, height, screen); //just BFS.Window.SetSizeAndLocation and MoveToMonitor
    return 0;
}


I hope this works for you!
Nov 28, 2017  • #2
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)