strokeplug.net - vscode

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].Activate()
        windArray[i].BringToFront();
        windArray[i].Maximize()
        sp.Sleep(5);// order keep
    }
}

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) {
        sp.Sleep(5);
        let rect =   windArray[i].Rectangle;
        windArray[i].Activate()
        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 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()
    }
}

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

posted @ 2023-03-24 15:59  fndefbwefsowpvqfx  阅读(13)  评论(0编辑  收藏  举报