stroke lib

发布时间 2023-04-27 17:00:48作者: ploolq
function getWindows(name) {
    let wnds = sp.AllApplications();
    const proName = name;
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }
    return result;
}


function sortWindowByTitle(windArray){
    if(!!!windArray || windArray.length<1) return;

    windArray.sort(function(a,b){return a.Title.localeCompare(b.Title)});
}

function ArrangeWindow(windArray) {
    if(!!!windArray || windArray.length<1) return;

    const total = windArray.length;
    const curScreen = windArray[0].Screen;
    const sWidth = curScreen.WorkingArea.Width;
    const sHeight = curScreen.WorkingArea.Height;

    const cellW = Math.floor(sWidth/2);
    const cellH = Math.floor(sHeight/Math.floor((total+1)/2));


    for(let i =0; i<total;++i) {
        sp.Sleep(1);

        var position = windArray[i].Position;
        position.Left = (i%2)*cellW;
        position.Top = Math.floor((i)/2.0)*cellH;

        position.Right = position.Left + cellW;
        position.Bottom = position.Top + cellH;

        windArray[i].Position = position;

         
        //sp.MessageBox("", windArray[i].Title);
    }
}

function showWindw(windArray) {
    if(!!!windArray || windArray.length<1) return;

    const total = windArray.length;
    for(let i =0; i<total;++i) {
        sp.Sleep(50);
        windArray[i].BringToFront();
        windArray[i].Activate();
    }
}

function see(name){
    let windArray = getWindows(name);
    if(!!!windArray || windArray.length<1){
       //sp.MessageBox("", " no window:" + name);
    }
    else {
        //sp.MessageBox("", windArray.length);
        sortWindowByTitle(windArray);
        ArrangeWindow(windArray);
        showWindw(windArray);
    }
}

see("Code");
function getExplorerWindows() {
    let wnds = sp.AllApplications();
    const proName = "explorer";
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }

    return result;
}

function sortExplorer(windArray) {
    if(!!!windArray || windArray.length<1) return;
    const total = windArray.length;
    const curScreen = windArray[0].Screen;
    const sWidth = curScreen.WorkingArea.Width;
    const sHeight = curScreen.WorkingArea.Height;

    const cellW = Math.floor(sWidth/2);
    const cellH = Math.floor(sHeight/Math.floor((total+1)/2));


    let result = "";
    for(let i =0; i<total;++i) {
        let rect =   windArray[i].Rectangle;
        windArray[i].BringToFront()
        rect.Width =cellW;
        rect.Height = cellH;
        rect.X = (i%2)*cellW;
        rect.Y = Math.floor((i)/2.0)*cellH;
        windArray[i].Rectangle = rect;
    }
}


function showExplorer(){
    let windArray = getExplorerWindows();
    if(!!!windArray || windArray.length<1){
        sp.RunProgram(sp.ExpandEnvironmentVariables("%SystemRoot%")+"\\explorer.exe", "", "", "", false, false, false);
    }
    else {
        sortExplorer(getExplorerWindows());
    }
}

showExplorer();
function getExplorerWindows() {
    let wnds = sp.AllApplications();
    const proName = "explorer";
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        //sp.MessageBox(cur.Process.ProcessName, "Result");
        if(cur.Process.ProcessName == proName) {
            result.push(cur);
        }
    }

    return result;
}

function closeExporer() {
    let todo = getExplorerWindows();
    for(let i =0;i< todo.length;++i) {
        todo[i].SendClose()
    }
}

closeExporer();