fix: filter cloaked windows (DwmGetWindowAttribute DWMWA_CLOAKED) to exclude background UWP apps
This commit is contained in:
parent
073ac283aa
commit
0cf6ab15d9
2 changed files with 17 additions and 0 deletions
|
|
@ -41,4 +41,5 @@ windows = { version = "0.54", features = [
|
|||
"Win32_UI_Shell",
|
||||
"Win32_System_Console",
|
||||
"Win32_System_ProcessStatus",
|
||||
"Win32_Graphics_Dwm",
|
||||
] }
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::collections::HashMap;
|
|||
mod win_impl {
|
||||
use super::*;
|
||||
use windows::Win32::Foundation::{BOOL, HWND, LPARAM};
|
||||
use windows::Win32::Graphics::Dwm::{DwmGetWindowAttribute, DWMWA_CLOAKED};
|
||||
use windows::Win32::UI::WindowsAndMessaging::{
|
||||
BringWindowToTop, EnumWindows, GetWindowTextW,
|
||||
IsWindowVisible, SetForegroundWindow, ShowWindow,
|
||||
|
|
@ -38,6 +39,18 @@ mod win_impl {
|
|||
list
|
||||
}
|
||||
|
||||
fn is_cloaked(hwnd: HWND) -> bool {
|
||||
let mut cloaked: u32 = 0;
|
||||
unsafe {
|
||||
DwmGetWindowAttribute(
|
||||
hwnd,
|
||||
DWMWA_CLOAKED,
|
||||
&mut cloaked as *mut u32 as *mut _,
|
||||
std::mem::size_of::<u32>() as u32,
|
||||
).is_err() == false && cloaked != 0
|
||||
}
|
||||
}
|
||||
|
||||
fn hwnd_title(hwnd: HWND) -> String {
|
||||
let mut buf = [0u16; 512];
|
||||
let len = unsafe { GetWindowTextW(hwnd, &mut buf) };
|
||||
|
|
@ -98,6 +111,9 @@ mod win_impl {
|
|||
if !visible {
|
||||
continue;
|
||||
}
|
||||
if is_cloaked(*hwnd) {
|
||||
continue;
|
||||
}
|
||||
let title = hwnd_title(*hwnd);
|
||||
if title.is_empty() {
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue