mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
refactoring get_title() allow by pid, window.h [ci skip]
This commit is contained in:
parent
6bf53298d1
commit
e565e4feb7
@ -549,7 +549,29 @@ void CloseWin(void){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *GetTitle(){
|
char* get_main_title(){
|
||||||
|
get_title_by_hand(mData);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* get_title_by_pid(uintptr pid, uintptr isHwnd){
|
||||||
|
MData m_data;
|
||||||
|
|
||||||
|
#if defined(IS_MACOSX)
|
||||||
|
m_data.AxID = AXUIElementCreateApplication(pid);
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
m_data.XWin = (Window)pid;
|
||||||
|
#elif defined(IS_WINDOWS)
|
||||||
|
if (isHwnd == 0) {
|
||||||
|
m_data.HWnd= GetHwndByPId(pid);
|
||||||
|
} else {
|
||||||
|
m_data.HWnd = (HWND)pid;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
get_title_by_hand(m_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* get_title_by_hand(MData m_data){
|
||||||
// Check if the window is valid
|
// Check if the window is valid
|
||||||
if (!IsValid()) {return "IsValid failed.";}
|
if (!IsValid()) {return "IsValid failed.";}
|
||||||
|
|
||||||
@ -558,7 +580,7 @@ char *GetTitle(){
|
|||||||
CFStringRef data = NULL;
|
CFStringRef data = NULL;
|
||||||
|
|
||||||
// Determine the current title of the window
|
// Determine the current title of the window
|
||||||
if (AXUIElementCopyAttributeValue(mData.AxID,
|
if (AXUIElementCopyAttributeValue(m_data.AxID,
|
||||||
kAXTitleAttribute, (CFTypeRef*) &data)
|
kAXTitleAttribute, (CFTypeRef*) &data)
|
||||||
== kAXErrorSuccess && data != NULL) {
|
== kAXErrorSuccess && data != NULL) {
|
||||||
char conv[512];
|
char conv[512];
|
||||||
@ -581,7 +603,7 @@ char *GetTitle(){
|
|||||||
XDismissErrors();
|
XDismissErrors();
|
||||||
|
|
||||||
// Get window title (UTF-8)
|
// Get window title (UTF-8)
|
||||||
result = GetWindowProperty(mData, WM_NAME,NULL);
|
result = GetWindowProperty(m_data, WM_NAME,NULL);
|
||||||
|
|
||||||
// Check result value
|
// Check result value
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
@ -593,7 +615,7 @@ char *GetTitle(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get window title (ASCII)
|
// Get window title (ASCII)
|
||||||
result = GetWindowProperty(mData, XA_WM_NAME,NULL);
|
result = GetWindowProperty(m_data, XA_WM_NAME,NULL);
|
||||||
|
|
||||||
// Check result value
|
// Check result value
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
@ -608,8 +630,8 @@ char *GetTitle(){
|
|||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
|
|
||||||
return GetWindowText(
|
return GetWindowText(
|
||||||
mData.HWnd, mData.Title, 512) > 0 ?
|
m_data.HWnd, m_data.Title, 512) > 0 ?
|
||||||
mData.Title : "";
|
m_data.Title : "";
|
||||||
// return GetWindowText
|
// return GetWindowText
|
||||||
// (mData.HWnd, name, 512) > 0 ?
|
// (mData.HWnd, name, 512) > 0 ?
|
||||||
// _UTF8Encode(name) : "null";
|
// _UTF8Encode(name) : "null";
|
||||||
|
Loading…
Reference in New Issue
Block a user