From ee25e577e58f15ff6caa551bdd9c96e626ee89f7 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sun, 26 Jun 2022 10:23:17 -0700 Subject: [PATCH] add get the HWND by PID support --- robotgo.go | 5 +++++ screen/goScreen.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/robotgo.go b/robotgo.go index f73c593..420c22c 100644 --- a/robotgo.go +++ b/robotgo.go @@ -236,6 +236,11 @@ func getNumDisplays() int { return int(C.get_num_displays()) } +// GetHwndByPId get the hwnd by pid +func GetHwndByPId(pid int) int { + return int(C.get_hwnd_by_pid(C.uintptr(pid))) +} + // SysScale get the sys scale func SysScale(displayId ...int) float64 { display := displayIdx(displayId...) diff --git a/screen/goScreen.h b/screen/goScreen.h index 2a2bc88..b9c0a16 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -97,6 +97,15 @@ uint32_t get_num_displays() { #endif } +uintptr get_hwnd_by_pid(uintptr pid) { + #if defined(IS_WINDOWS) + HWND hwnd = GetHwndByPId(pid); + return (uintptr)hwnd; + #else + return 0; + #endif +} + void bitmap_dealloc(MMBitmapRef bitmap) { if (bitmap != NULL) { destroyMMBitmap(bitmap);