mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-30 22:13:54 +00:00
optimize get title code, Fixed #165 and typo
This commit is contained in:
parent
f8d7ecde45
commit
73866c8273
21
robotgo.go
21
robotgo.go
@ -1498,25 +1498,26 @@ func GetBHandle() int {
|
||||
return ghwnd
|
||||
}
|
||||
|
||||
func cgetTitle(hwnd, isHwnd int32) string {
|
||||
title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd))
|
||||
gtitle := C.GoString(title)
|
||||
|
||||
return gtitle
|
||||
}
|
||||
|
||||
// GetTitle get the window title
|
||||
func GetTitle(args ...int32) string {
|
||||
if len(args) <= 0 {
|
||||
title := C.get_main_title()
|
||||
gtittle := C.GoString(title)
|
||||
return gtittle
|
||||
gtitle := C.GoString(title)
|
||||
return gtitle
|
||||
}
|
||||
|
||||
var hwnd, isHwnd int32
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
}
|
||||
if len(args) > 1 {
|
||||
isHwnd = args[1]
|
||||
return internalGetTitle(args[0], args[1])
|
||||
}
|
||||
title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd))
|
||||
gtittle := C.GoString(title)
|
||||
|
||||
return gtittle
|
||||
return internalGetTitle(args[0])
|
||||
}
|
||||
|
||||
// GetPID get the process id
|
||||
|
@ -22,6 +22,17 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
return internalGetBounds(pid, hwnd)
|
||||
}
|
||||
|
||||
// internalGetTitle get the window title
|
||||
func internalGetTitle(pid int32, args ...int32) string {
|
||||
var isHwnd int32
|
||||
if len(args) > 0 {
|
||||
isHwnd = args[0]
|
||||
}
|
||||
gtitle := cgetTitle(pid, isHwnd)
|
||||
|
||||
return gtitle
|
||||
}
|
||||
|
||||
// ActivePID active the window by PID,
|
||||
//
|
||||
// If args[0] > 0 on the Windows platform via a window handle to active
|
||||
|
@ -41,6 +41,24 @@ func GetBounds(pid int32, args ...int) (int, int, int, int) {
|
||||
return internalGetBounds(int32(xid), hwnd)
|
||||
}
|
||||
|
||||
// internalGetTitle get the window title
|
||||
func internalGetTitle(pid int32, args ...int) string {
|
||||
var hwnd int
|
||||
if len(args) > 0 {
|
||||
hwnd = args[0]
|
||||
|
||||
return cgetTitle(pid, hwnd)
|
||||
}
|
||||
|
||||
xid, err := GetXId(xu, pid)
|
||||
if err != nil {
|
||||
log.Println("GetXidFromPid errors is: ", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return cgetTitle(int32(xid), hwnd)
|
||||
}
|
||||
|
||||
// ActivePIDC active the window by PID,
|
||||
// If args[0] > 0 on the unix platform via a xid to active
|
||||
func ActivePIDC(pid int32, args ...int) {
|
||||
|
Loading…
Reference in New Issue
Block a user