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
func GetTitle() string {
title := C.get_title()
func GetTitle(args ...int32) string {
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)
// fmt.Println("title...", gtittle)
return gtittle
}

View File

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

View File

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