如何获取Windows应用程序的位置和区域(例如“ Google Chrome”)? [关闭]

How can I get pid and Handle, then get the position?

I don't have a clue about that. Please ignore the following code.

package main

import (
    "fmt"

    "syscall"
)

func main () {
    if err := syscall.Setregid(int(233), int(233)); err != nil {
        fmt.Println("setregid:", err)
    }
}

Despite the code you posted (which would only work under Linux), everybody seems to be assuming that you asking how it can be done under Windows.

As @remy-lebeau mentioned you can use FindWindow() and GetWindowRect() to achieve this:

package main

import (
    "fmt"
    "syscall"
    "unsafe"
)

type HWND uintptr

type RECT struct {
    Left, Top, Right, Bottom int32
}

var (
    user32, _     = syscall.LoadLibrary("user32.dll")
    findWindowW, _ = syscall.GetProcAddress(user32, "FindWindowW")
    getWindowRect, _ = syscall.GetProcAddress(user32, "GetWindowRect")
)

//HWND WINAPI FindWindow(
//  _In_opt_ LPCTSTR lpClassName,
//  _In_opt_ LPCTSTR lpWindowName
//);
func FindWindowByTitle(title string) HWND {
    ret, _, _ := syscall.Syscall(
        findWindowW,
        2,
        0,
        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))),
        0,
    )
    return HWND(ret)
}

//BOOL WINAPI GetWindowRect(
//  _In_  HWND   hWnd,
//  _Out_ LPRECT lpRect
//);
func GetWindowDimensions(hwnd HWND) *RECT {
    var rect RECT

    syscall.Syscall(
        getWindowRect,
        2,
        uintptr(hwnd),
        uintptr(unsafe.Pointer(&rect)),
        0,
    )

    return &rect
}

func main() {
    defer syscall.FreeLibrary(user32)

    hwnd := FindWindowByTitle("New Tab - Google Chrome")
    fmt.Printf("Return: %d
", hwnd)

    if hwnd > 0 {
        rect := GetWindowDimensions(hwnd)
        fmt.Printf("Return: %v
", rect)
    }
}

Be aware that for brevity no error handling is done.