From bbc0c8e2a783aa498732d3d5fc1b297c4e37c5a2 Mon Sep 17 00:00:00 2001 From: vCaesar Date: Wed, 18 Jan 2017 20:34:35 +0800 Subject: [PATCH] Add Getpid --- robotgo.go | 6 ++++++ window/goWindow.h | 5 +++++ window/window.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/robotgo.go b/robotgo.go index 9367c89..96cdf7b 100644 --- a/robotgo.go +++ b/robotgo.go @@ -777,3 +777,9 @@ func GetTitle() string { // Println("title...", gtittle) return gtittle } + +//GetPID Get the process id +func GetPID() int { + pid := C.aGetPID() + return int(pid) +} diff --git a/window/goWindow.h b/window/goWindow.h index fe0617b..4a7d3ca 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -57,3 +57,8 @@ char* aGetTitle(){ // printf("title::::%s\n",title ); return title; } + +int32 aGetPID(void){ + int pid=WGetPID(); + return pid; +} diff --git a/window/window.h b/window/window.h index 3e9da69..0c082b2 100644 --- a/window/window.h +++ b/window/window.h @@ -867,3 +867,39 @@ char *GetTitle(){ #endif } +int32 WGetPID(void){ + // Check window validity + if (!IsValid()) return 0; + +#if defined(IS_MACOSX) + + pid_t pid = 0; + // Attempt to retrieve the window pid + if (AXUIElementGetPid(mData.AxID, &pid) + == kAXErrorSuccess) return pid; + + return 0; + +#elif defined(USE_X11) + + // Ignore X errors + XDismissErrors(); + + // Get the window PID + long* result = (long*) + GetWindowProperty(mData, WM_PID,NULL); + + // Check result and convert it + if (result == NULL) return 0; + int32 pid = (int32) *result; + XFree (result); return pid; + +#elif defined(IS_WINDOWS) + + DWORD id = 0; + GetWindowThreadProcessId (mData.HWnd, &id); + return id; + +#endif +} +