Add Getpid

This commit is contained in:
vCaesar 2017-01-18 20:34:35 +08:00
parent cb6aa1075e
commit bbc0c8e2a7
3 changed files with 47 additions and 0 deletions

View File

@ -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)
}

View File

@ -57,3 +57,8 @@ char* aGetTitle(){
// printf("title::::%s\n",title );
return title;
}
int32 aGetPID(void){
int pid=WGetPID();
return pid;
}

View File

@ -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
}