mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-05 16:23:55 +00:00
commit
50b4b5c734
34
robotgo.go
34
robotgo.go
@ -1286,6 +1286,40 @@ func GetActive() C.MData {
|
|||||||
return mdata
|
return mdata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MinWindow set the window min
|
||||||
|
func MinWindow(pid int32, args ...interface{}) {
|
||||||
|
var (
|
||||||
|
state = true
|
||||||
|
hwnd int
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
state = args[0].(bool)
|
||||||
|
}
|
||||||
|
if len(args) > 1 {
|
||||||
|
hwnd = args[1].(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
C.min_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaxWindow set the window max
|
||||||
|
func MaxWindow(pid int32, args ...interface{}) {
|
||||||
|
var (
|
||||||
|
state = true
|
||||||
|
hwnd int
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
state = args[0].(bool)
|
||||||
|
}
|
||||||
|
if len(args) > 1 {
|
||||||
|
hwnd = args[1].(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
C.max_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
|
||||||
|
}
|
||||||
|
|
||||||
// CloseWindow close the window
|
// CloseWindow close the window
|
||||||
func CloseWindow() {
|
func CloseWindow() {
|
||||||
C.close_window()
|
C.close_window()
|
||||||
|
@ -14,3 +14,10 @@ func FindWindow(str string) win.HWND {
|
|||||||
|
|
||||||
return hwnd
|
return hwnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHWND get foreground window hwnd
|
||||||
|
func GetHWND() win.HWND {
|
||||||
|
hwnd := win.GetForegroundWindow()
|
||||||
|
|
||||||
|
return hwnd
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "alert_c.h"
|
#include "alert_c.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "win32.h"
|
||||||
|
|
||||||
int show_alert(const char *title, const char *msg,
|
int show_alert(const char *title, const char *msg,
|
||||||
const char *defaultButton, const char *cancelButton){
|
const char *defaultButton, const char *cancelButton){
|
||||||
@ -57,6 +58,44 @@ bool is_valid(){
|
|||||||
// return z;
|
// return z;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
void min_window(uintptr pid, bool state, uintptr isHwnd){
|
||||||
|
#if defined(IS_MACOSX)
|
||||||
|
// return 0;
|
||||||
|
AXUIElementRef axID = AXUIElementCreateApplication(pid);
|
||||||
|
|
||||||
|
AXUIElementSetAttributeValue(axID, kAXMinimizedAttribute,
|
||||||
|
state ? kCFBooleanTrue : kCFBooleanFalse);
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
// Ignore X errors
|
||||||
|
XDismissErrors();
|
||||||
|
// SetState((Window)pid, STATE_MINIMIZE, state);
|
||||||
|
#elif defined(IS_WINDOWS)
|
||||||
|
if (isHwnd == 0) {
|
||||||
|
HWND hwnd = GetHwndByPId(pid);
|
||||||
|
win_min(hwnd, state);
|
||||||
|
} else {
|
||||||
|
win_min((HWND)pid, state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void max_window(uintptr pid, bool state, uintptr isHwnd){
|
||||||
|
#if defined(IS_MACOSX)
|
||||||
|
// return 0;
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
XDismissErrors();
|
||||||
|
// SetState((Window)pid, STATE_MINIMIZE, false);
|
||||||
|
// SetState((Window)pid, STATE_MAXIMIZE, state);
|
||||||
|
#elif defined(IS_WINDOWS)
|
||||||
|
if (isHwnd == 0) {
|
||||||
|
HWND hwnd = GetHwndByPId(pid);
|
||||||
|
win_max(hwnd, state);
|
||||||
|
} else {
|
||||||
|
win_max((HWND)pid, state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void close_window(void){
|
void close_window(void){
|
||||||
CloseWin();
|
CloseWin();
|
||||||
}
|
}
|
||||||
@ -86,34 +125,6 @@ void set_active(const MData win){
|
|||||||
SetActive(win);
|
SetActive(win);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(IS_WINDOWS)
|
|
||||||
typedef struct{
|
|
||||||
HWND hWnd;
|
|
||||||
DWORD dwPid;
|
|
||||||
}WNDINFO;
|
|
||||||
|
|
||||||
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam){
|
|
||||||
WNDINFO* pInfo = (WNDINFO*)lParam;
|
|
||||||
DWORD dwProcessId = 0;
|
|
||||||
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
|
||||||
|
|
||||||
if (dwProcessId == pInfo->dwPid) {
|
|
||||||
pInfo->hWnd = hWnd;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND GetHwndByPId(DWORD dwProcessId){
|
|
||||||
WNDINFO info = {0};
|
|
||||||
info.hWnd = NULL;
|
|
||||||
info.dwPid = dwProcessId;
|
|
||||||
EnumWindows(EnumWindowsProc, (LPARAM)&info);
|
|
||||||
// printf("%d\n", info.hWnd);
|
|
||||||
return info.hWnd;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void active_PID(uintptr pid, uintptr isHwnd){
|
void active_PID(uintptr pid, uintptr isHwnd){
|
||||||
MData win;
|
MData win;
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
|
46
window/win32.h
Normal file
46
window/win32.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// #include "../base/os.h"
|
||||||
|
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
typedef struct{
|
||||||
|
HWND hWnd;
|
||||||
|
DWORD dwPid;
|
||||||
|
}WNDINFO;
|
||||||
|
|
||||||
|
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam){
|
||||||
|
WNDINFO* pInfo = (WNDINFO*)lParam;
|
||||||
|
DWORD dwProcessId = 0;
|
||||||
|
GetWindowThreadProcessId(hWnd, &dwProcessId);
|
||||||
|
|
||||||
|
if (dwProcessId == pInfo->dwPid) {
|
||||||
|
pInfo->hWnd = hWnd;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND GetHwndByPId(DWORD dwProcessId){
|
||||||
|
WNDINFO info = {0};
|
||||||
|
info.hWnd = NULL;
|
||||||
|
info.dwPid = dwProcessId;
|
||||||
|
EnumWindows(EnumWindowsProc, (LPARAM)&info);
|
||||||
|
// printf("%d\n", info.hWnd);
|
||||||
|
return info.hWnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// window
|
||||||
|
void win_min(HWND hwnd, bool state){
|
||||||
|
if (state) {
|
||||||
|
ShowWindow(hwnd, SW_MINIMIZE);
|
||||||
|
} else {
|
||||||
|
ShowWindow(hwnd, SW_RESTORE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void win_max(HWND hwnd, bool state){
|
||||||
|
if (state) {
|
||||||
|
ShowWindow(hwnd, SW_MAXIMIZE);
|
||||||
|
} else {
|
||||||
|
ShowWindow(hwnd, SW_RESTORE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user