Skip to content

Commit 9cf455e

Browse files
committed
fix(win32): window pos恢复位置检查是否出屏幕了
fix MaaEnd/MaaEnd#1794
1 parent e48b97d commit 9cf455e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

source/MaaWin32ControlUnit/Input/MessageInput.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ void MessageInput::restore_window_pos()
114114
}
115115
std::this_thread::sleep_for(std::chrono::milliseconds(10));
116116

117-
if (!SetWindowPos(hwnd_, nullptr, saved_window_rect_.left, saved_window_rect_.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) {
117+
LONG left = saved_window_rect_.left;
118+
LONG top = saved_window_rect_.top;
119+
120+
if (!MonitorFromRect(&saved_window_rect_, MONITOR_DEFAULTTONULL)) {
121+
LogWarn << "saved window position is off-screen, restoring to top-left"
122+
<< VAR(saved_window_rect_.left) << VAR(saved_window_rect_.top);
123+
left = 0;
124+
top = 0;
125+
}
126+
127+
if (!SetWindowPos(hwnd_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE)) {
118128
LogError << "SetWindowPos failed during restore" << VAR(hwnd_) << VAR(GetLastError());
119129
}
120130
window_pos_saved_ = false;

0 commit comments

Comments
 (0)