From 338a8b929259a16a127e7a57316e87f0d396dcd0 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Thu, 23 Aug 2018 12:03:55 -0400 Subject: [PATCH 1/2] refactoring close_window() allow by pid, window.h [ci skip] --- window/window.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/window/window.h b/window/window.h index 12951c6..f7c1b77 100644 --- a/window/window.h +++ b/window/window.h @@ -20,6 +20,7 @@ bool IsAxEnabled(bool options); MData GetActive(void); void initWindow(); char* get_title_by_hand(MData m_data); +void close_window_by_Id(MData m_data); //int findwindow() @@ -538,15 +539,28 @@ void SetTopMost(bool state){ #endif } +void close_main_window (){ + // Check if the window is valid + if (!IsValid()) { return; } + + close_window_by_Id(mData); +} + +void close_window_by_PId(uintptr pid, uintptr isHwnd){ + MData win = set_hand_pid(pid, isHwnd); + close_window_by_Id(win); +} + + // CloseWindow -void CloseWin(void){ +void close_window_by_Id(MData m_data){ // Check window validity if (!IsValid()) {return;} #if defined(IS_MACOSX) AXUIElementRef b = NULL; // Retrieve the close button of this window - if (AXUIElementCopyAttributeValue(mData.AxID, + if (AXUIElementCopyAttributeValue(m_data.AxID, kAXCloseButtonAttribute, (CFTypeRef*) &b) == kAXErrorSuccess && b != NULL) { // Simulate button press on the close button @@ -562,11 +576,11 @@ void CloseWin(void){ XDismissErrors(); // Close the window - XDestroyWindow(rDisplay, mData.XWin); + XDestroyWindow(rDisplay, m_data.XWin); #elif defined(IS_WINDOWS) - PostMessage(mData.HWnd, WM_CLOSE, 0, 0); + PostMessage(m_data.HWnd, WM_CLOSE, 0, 0); #endif } From 727ab062fbe69ff6e7c28379988c175f8bd24329 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Thu, 23 Aug 2018 12:06:42 -0400 Subject: [PATCH 2/2] update close_window() allow by pid --- robotgo.go | 17 +++++++++++++++-- window/goWindow.h | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/robotgo.go b/robotgo.go index 417ed68..5fe5824 100644 --- a/robotgo.go +++ b/robotgo.go @@ -1358,8 +1358,21 @@ func MaxWindow(pid int32, args ...interface{}) { } // CloseWindow close the window -func CloseWindow() { - C.close_window() +func CloseWindow(args ...int32) { + if len(args) <= 0 { + C.close_main_window() + return + } + + var hwnd, isHwnd int32 + if len(args) > 0 { + hwnd = args[0] + } + if len(args) > 1 { + isHwnd = args[1] + } + + C.close_window(C.uintptr(hwnd), C.uintptr(isHwnd)) } // SetHandle set the window handle diff --git a/window/goWindow.h b/window/goWindow.h index 526feb5..5638092 100644 --- a/window/goWindow.h +++ b/window/goWindow.h @@ -75,8 +75,8 @@ void max_window(uintptr pid, bool state, uintptr isHwnd){ #endif } -void close_window(void){ - CloseWin(); +void close_window(uintptr pid, uintptr isHwnd){ + close_window_by_PId(pid, isHwnd); } bool set_handle(uintptr handle){