update getTitle func and .h name

This commit is contained in:
vcaesar 2018-08-21 12:47:31 -04:00
parent e565e4feb7
commit 873e9d30dc
3 changed files with 26 additions and 13 deletions

View File

@ -1385,10 +1385,23 @@ func GetBHandle() int {
} }
// GetTitle get the window title // GetTitle get the window title
func GetTitle() string { func GetTitle(args ...int32) string {
title := C.get_title() if len(args) <= 0 {
title := C.get_main_title()
gtittle := C.GoString(title)
return gtittle
}
var hwnd, isHwnd int32
if len(args) > 0 {
hwnd = args[0]
}
if len(args) > 1 {
isHwnd = args[1]
}
title := C.get_title(C.uintptr(hwnd), C.uintptr(isHwnd))
gtittle := C.GoString(title) gtittle := C.GoString(title)
// fmt.Println("title...", gtittle)
return gtittle return gtittle
} }

View File

@ -129,8 +129,8 @@ MData get_active(){
return mdata; return mdata;
} }
char* get_title(){ char* get_title(uintptr pid, uintptr isHwnd){
char* title = GetTitle(); char* title = get_title_by_pid(pid, isHwnd);
// printf("title::::%s\n", title ); // printf("title::::%s\n", title );
return title; return title;
} }

View File

@ -18,6 +18,7 @@ bool IsValid();
bool IsAxEnabled(bool options); bool IsAxEnabled(bool options);
MData GetActive(void); MData GetActive(void);
void initWindow(); void initWindow();
char* get_title_by_hand(MData m_data);
//int findwindow() //int findwindow()
@ -545,7 +546,6 @@ void CloseWin(void){
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
PostMessage(mData.HWnd, WM_CLOSE, 0, 0); PostMessage(mData.HWnd, WM_CLOSE, 0, 0);
#endif #endif
} }
@ -554,27 +554,27 @@ char* get_main_title(){
} }
char* get_title_by_pid(uintptr pid, uintptr isHwnd){ char* get_title_by_pid(uintptr pid, uintptr isHwnd){
MData m_data; MData win;
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
m_data.AxID = AXUIElementCreateApplication(pid); win.AxID = AXUIElementCreateApplication(pid);
#elif defined(USE_X11) #elif defined(USE_X11)
m_data.XWin = (Window)pid; win.XWin = (Window)pid;
#elif defined(IS_WINDOWS) #elif defined(IS_WINDOWS)
if (isHwnd == 0) { if (isHwnd == 0) {
m_data.HWnd= GetHwndByPId(pid); win.HWnd = GetHwndByPId(pid);
} else { } else {
m_data.HWnd = (HWND)pid; win.HWnd = (HWND)pid;
} }
#endif #endif
get_title_by_hand(m_data); get_title_by_hand(win);
} }
char* get_title_by_hand(MData 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.";}
#if defined(IS_MACOSX) #if defined(IS_MACOSX)
CFStringRef data = NULL; CFStringRef data = NULL;