strokeplug.net - vscode

发布时间 2023-03-24 16:04:53作者: ploolq
function getWindowByProcessName(pName) {
    if(!pName || pName.lenght < 1) return;

    let wnds = sp.AllApplications();
    let result = new Array();
    for(let i =0;i< wnds.Length;++i) {
        let cur = wnds[i];
        
        if(cur.Process.ProcessName == pName) {
            result.push(cur);
        }
    }

    result.sort((a, b) => { return a.Title.localeCompare(b.Title); });//ordered
    return result;
}


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

    const total = windArray.length;

    for(let i =total-1; i>=0;--i) {
        windArray[i].BringToFront();
        windArray[i].Maximize()
        sp.Sleep(5);// order keep
    }
}

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

    const total = windArray.length;
    for(let i =0; i<total;++i) {
        windArray[i].Minimize()
    }
}

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

    for(let i =0;i< windArray.length;++i) {
        windArray[i].SendClose()
    }
}


function sortWin32Window(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;
    }
}


https://learn.microsoft.com/en-us/dotnet/api