-
Notifications
You must be signed in to change notification settings - Fork 455
feat(Win32-Front): 截图时尝试窗口前置 #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5bf30fe
feat(Win32):截图前做一次窗口检查
HarcoChen 9df467a
refactor(Win32): 将ensure_window作为base
HarcoChen 893d0d3
chore(format): 补一个格式化
HarcoChen 5cebbdd
Merge branch 'main' into fix/win32-front
HarcoChen 0891cdf
refactor(win32): 移除过度包装,精简延时逻辑
HarcoChen 2675b89
窗口置顶警告代替失败
zmdyy0318 ffaf9e5
修复ai建议
zmdyy0318 63dc380
Potential fix for pull request finding
zmdyy0318 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,59 @@ | ||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <thread> | ||
|
|
||
| #include "MaaUtils/SafeWindows.hpp" | ||
|
|
||
| #include "Common/Conf.h" | ||
|
|
||
| MAA_CTRL_UNIT_NS_BEGIN | ||
|
|
||
| inline void ensure_foreground_and_topmost(HWND hwnd) | ||
| { | ||
| if (!hwnd) { | ||
| return; | ||
| } | ||
|
|
||
| // 如果窗口不在前台,先将其置顶 | ||
| if (hwnd != GetForegroundWindow()) { | ||
| // 将窗口移到 Z 序顶部 | ||
| SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
|
|
||
| // 尝试设置为前台窗口 | ||
| SetForegroundWindow(hwnd); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
|
|
||
| // 再次检查,如果仍然不在前台,再次置顶 | ||
| if (hwnd != GetForegroundWindow()) { | ||
| SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| inline bool ensure_foreground_with_cooldown(HWND hwnd) | ||
| { | ||
| constexpr DWORD kForegroundRecoveryInterval = 5000; | ||
| static DWORD last_foreground_attempt = 0; | ||
|
|
||
|
zmdyy0318 marked this conversation as resolved.
|
||
| if (!hwnd || !IsWindow(hwnd)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (hwnd == GetForegroundWindow()) { | ||
| return true; | ||
| } | ||
|
|
||
| DWORD now = GetTickCount(); | ||
| if (last_foreground_attempt != 0 && now - last_foreground_attempt < kForegroundRecoveryInterval) { | ||
| return hwnd == GetForegroundWindow(); | ||
| } | ||
|
|
||
| last_foreground_attempt = now; | ||
| ensure_foreground_and_topmost(hwnd); | ||
|
zmdyy0318 marked this conversation as resolved.
|
||
| return hwnd == GetForegroundWindow(); | ||
| } | ||
|
|
||
| MAA_CTRL_UNIT_NS_END | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -27,4 +27,3 @@ class DesktopDupWindowScreencap : public DesktopDupScreencap | |
| }; | ||
|
|
||
| MAA_CTRL_UNIT_NS_END | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -25,4 +25,3 @@ class ScreenDCScreencap : public ScreencapBase | |
| }; | ||
|
|
||
| MAA_CTRL_UNIT_NS_END | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.