-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
291 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "../MaaToolKitDef.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
MaaSize MAA_TOOLKIT_API MaaToolKitFindWindow(MaaStringView class_name, MaaStringView window_name); | ||
MaaSize MAA_TOOLKIT_API MaaToolKitSearchWindow(MaaStringView class_name, MaaStringView window_name); | ||
MaaWin32Hwnd MAA_TOOLKIT_API MaaToolKitGetWindow(MaaSize index); | ||
MaaWin32Hwnd MAA_TOOLKIT_API MaaToolKitGetCursorWindow(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "MaaToolKit/Win32/MaaToolKitWin32Window.h" | ||
|
||
#include <string_view> | ||
|
||
#include "Utils/Logger.h" | ||
#include "Win32Window/Win32WindowFinder.h" | ||
|
||
auto& win32_mgr = MAA_TOOLKIT_WIN32_NS::Win32WindowFinder::get_instance(); | ||
|
||
MaaSize MaaToolKitFindWindow(MaaStringView class_name, MaaStringView window_name) | ||
{ | ||
LogInfo << VAR(class_name) << VAR(window_name); | ||
|
||
return win32_mgr.find_window(class_name, window_name); | ||
} | ||
|
||
MaaSize MaaToolKitSearchWindow(MaaStringView class_name, MaaStringView window_name) | ||
{ | ||
LogInfo << VAR(class_name) << VAR(window_name); | ||
|
||
return win32_mgr.search_window(class_name, window_name); | ||
} | ||
|
||
MaaWin32Hwnd MaaToolKitGetWindow(MaaSize index) | ||
{ | ||
return win32_mgr.found_window().at(index); | ||
} | ||
|
||
MaaWin32Hwnd MaaToolKitGetCursorWindow() | ||
{ | ||
LogInfo; | ||
|
||
return win32_mgr.get_cursor_window(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef _WIN32 | ||
|
||
#include "Win32WindowFinder.h" | ||
|
||
#include "Utils/Logger.h" | ||
|
||
MAA_TOOLKIT_WIN32_NS_BEGIN | ||
|
||
std::ostream& operator<<(std::ostream& os, const Win32WindowFinder::Window& w) | ||
{ | ||
os << VAR_VOIDP_RAW(w.hwnd) << VAR_RAW(w.class_name) << VAR_RAW(w.window_name); | ||
return os; | ||
} | ||
|
||
size_t Win32WindowFinder::find_window(std::string_view class_name, std::string_view window_name) | ||
{ | ||
LogError << "Not implemented" << VAR(class_name) << VAR(window_name); | ||
return 0; | ||
} | ||
|
||
size_t Win32WindowFinder::search_window(std::string_view class_name, std::string_view window_name) | ||
{ | ||
LogError << "Not implemented" << VAR(class_name) << VAR(window_name); | ||
return 0; | ||
} | ||
|
||
MaaWin32Hwnd Win32WindowFinder::get_cursor_window() const | ||
{ | ||
LogError << "Not implemented"; | ||
return nullptr; | ||
} | ||
|
||
std::vector<Win32WindowFinder::Window> Win32WindowFinder::list_windows() const | ||
{ | ||
LogError << "Not implemented"; | ||
return {}; | ||
} | ||
|
||
MAA_TOOLKIT_WIN32_NS_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "Conf/Conf.h" | ||
|
||
#include <string_view> | ||
#include <vector> | ||
|
||
#include "MaaToolKit/MaaToolKitDef.h" | ||
|
||
class MaaWin32WindowAPI | ||
{ | ||
public: | ||
virtual ~MaaWin32WindowAPI() = default; | ||
|
||
virtual size_t find_window(std::string_view class_name, std::string_view window_name) = 0; | ||
virtual size_t search_window(std::string_view class_name, std::string_view window_name) = 0; | ||
virtual std::vector<MaaWin32Hwnd> found_window() const = 0; | ||
virtual MaaWin32Hwnd get_cursor_window() const = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifdef _WIN32 | ||
|
||
#include "Win32WindowFinder.h" | ||
|
||
#include "Utils/Logger.h" | ||
#include "Utils/Platform.h" | ||
|
||
MAA_TOOLKIT_WIN32_NS_BEGIN | ||
|
||
std::ostream& operator<<(std::ostream& os, const Win32WindowFinder::Window& w) | ||
{ | ||
os << VAR_VOIDP_RAW(w.hwnd) << VAR_RAW(w.class_name) << VAR_RAW(w.window_name); | ||
return os; | ||
} | ||
|
||
size_t Win32WindowFinder::find_window(std::string_view class_name, std::string_view window_name) | ||
{ | ||
auto windows = list_windows(); | ||
|
||
windows_.clear(); | ||
for (const auto& w : windows) { | ||
bool same_class = class_name.empty() || w.class_name == class_name; | ||
bool same_window = window_name.empty() || w.window_name == window_name; | ||
if (same_class && same_window) { | ||
windows_.emplace_back(w.hwnd); | ||
} | ||
} | ||
return windows_.size(); | ||
} | ||
|
||
size_t Win32WindowFinder::search_window(std::string_view class_name, std::string_view window_name) | ||
{ | ||
auto windows = list_windows(); | ||
|
||
windows_.clear(); | ||
for (const auto& w : windows) { | ||
bool same_class = class_name.empty() || w.class_name.find(class_name) != std::string::npos; | ||
bool same_window = window_name.empty() || w.window_name.find(window_name) != std::string::npos; | ||
if (same_class && same_window) { | ||
windows_.emplace_back(w.hwnd); | ||
} | ||
} | ||
return windows_.size(); | ||
} | ||
|
||
MaaWin32Hwnd Win32WindowFinder::get_cursor_window() const | ||
{ | ||
POINT pt; | ||
if (!GetCursorPos(&pt)) { | ||
return nullptr; | ||
} | ||
|
||
HWND hwnd = WindowFromPoint(pt); | ||
if (hwnd == NULL) { | ||
return nullptr; | ||
} | ||
|
||
return reinterpret_cast<MaaWin32Hwnd>(hwnd); | ||
} | ||
|
||
std::vector<Win32WindowFinder::Window> Win32WindowFinder::list_windows() const | ||
{ | ||
std::vector<Window> windows; | ||
|
||
for (HWND hwnd = GetTopWindow(NULL); hwnd != NULL; hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)) { | ||
if (!IsWindowVisible(hwnd)) { | ||
continue; | ||
} | ||
|
||
std::string class_name(256, '\0'); | ||
GetClassName(hwnd, class_name.data(), static_cast<int>(class_name.size())); | ||
|
||
std::string window_name(256, '\0'); | ||
GetWindowText(hwnd, window_name.data(), static_cast<int>(window_name.size())); | ||
|
||
windows.emplace_back(Window { .hwnd = reinterpret_cast<MaaWin32Hwnd>(hwnd), | ||
.class_name = std::move(class_name), | ||
.window_name = std::move(window_name) }); | ||
} | ||
|
||
#ifdef MAA_DEBUG | ||
LogInfo << "Window list:" << windows; | ||
#endif | ||
|
||
return windows; | ||
} | ||
|
||
MAA_TOOLKIT_WIN32_NS_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "Win32WindowAPI.h" | ||
|
||
#include "Utils/Platform.h" | ||
#include "Utils/SingletonHolder.hpp" | ||
|
||
MAA_TOOLKIT_WIN32_NS_BEGIN | ||
|
||
class Win32WindowFinder : public MaaWin32WindowAPI, public SingletonHolder<Win32WindowFinder> | ||
{ | ||
public: | ||
struct Window | ||
{ | ||
MaaWin32Hwnd hwnd; | ||
std::string class_name; | ||
std::string window_name; | ||
}; | ||
|
||
public: | ||
virtual ~Win32WindowFinder() = default; | ||
|
||
virtual size_t find_window(std::string_view class_name, std::string_view window_name) override; | ||
virtual size_t search_window(std::string_view class_name, std::string_view window_name) override; | ||
virtual std::vector<MaaWin32Hwnd> found_window() const override { return windows_; } | ||
|
||
virtual MaaWin32Hwnd get_cursor_window() const override; | ||
|
||
private: | ||
std::vector<Window> list_windows() const; | ||
|
||
private: | ||
std::vector<MaaWin32Hwnd> windows_; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const Win32WindowFinder::Window& window); | ||
|
||
MAA_TOOLKIT_WIN32_NS_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.