Update to spice2x-25-10-07 (pre-apply)
> broken commit
This commit is contained in:
+31
-2
@@ -227,6 +227,7 @@ static inline std::vector<HWND> find_windows_beginning_with(const std::string &t
|
||||
return windows;
|
||||
}
|
||||
|
||||
// exists for compat only; prefer to use FindProcessWindowBeginsWith instead
|
||||
static inline HWND FindWindowBeginsWith(std::string title) {
|
||||
|
||||
// get all windows
|
||||
@@ -248,6 +249,28 @@ static inline HWND FindWindowBeginsWith(std::string title) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline HWND FindProcessWindowBeginsWith(const std::string &title) {
|
||||
// try foreground window first
|
||||
HWND fg_win = GetForegroundWindow();
|
||||
if (string_begins_with(get_window_title(fg_win), title)) {
|
||||
DWORD fg_pid;
|
||||
GetWindowThreadProcessId(fg_win, &fg_pid);
|
||||
if (fg_pid == GetCurrentProcessId()) {
|
||||
return fg_win;
|
||||
}
|
||||
}
|
||||
|
||||
// try different windows
|
||||
for (const auto window : find_windows_beginning_with(title)) {
|
||||
DWORD fg_pid;
|
||||
GetWindowThreadProcessId(window, &fg_pid);
|
||||
if (fg_pid == GetCurrentProcessId()) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline std::string get_last_error_string() {
|
||||
|
||||
// get error
|
||||
@@ -260,7 +283,8 @@ static inline std::string get_last_error_string() {
|
||||
LPSTR messageBuffer = nullptr;
|
||||
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
||||
nullptr,
|
||||
error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
@@ -269,7 +293,12 @@ static inline std::string get_last_error_string() {
|
||||
nullptr);
|
||||
|
||||
// return as string
|
||||
std::string message(messageBuffer, size);
|
||||
std::string message;
|
||||
if (size == 0) {
|
||||
message = fmt::format("(Win32 error {})", error);
|
||||
} else {
|
||||
message = fmt::format("{}(Win32 error {})", messageBuffer, error);
|
||||
}
|
||||
LocalFree(messageBuffer);
|
||||
|
||||
return message;
|
||||
|
||||
Reference in New Issue
Block a user