I've been using MSDN for the documentation, and I've also found EnumChildWindows, the rust documentation is a stub. My question is what the behavior of EnumWindows actually is. I've been under the impression that it enumerates calling the provided function with every top level (application) window but right now all I'm getting is default ime.
HWNDS_LENGTH is just a magic number for the size of a static array used to store the id for each window at startup. This should never be more than four in use. HWNDS_COLLECTION is a static array used to store all window ids found at startup. These are minor details that only exist to receive the ids from the callback (I know this is working because I successfully read the title of one window).
const HWNDS_LENGTH: usize = 20; // Never going to use all this
static mut HWNDS_COLLECTION: [Option<HWND>; HWNDS_LENGTH] = [None; HWNDS_LENGTH];
My callback fills in the array, backwards, with the window ids leaving the front empty (None). This returns true always so I don't think that a false return value would cause enumeration to stop early.
unsafe extern "system" fn enumeration_callback(hwnd: HWND, _: LPARAM) -> BOOL {
for i in HWNDS_LENGTH..0 {
match HWNDS_COLLECTION[i] {
Some(_) => {}
None => {HWNDS_COLLECTION[i] = Some(hwnd); break}
}
}
HWNDS_COLLECTION[0] = Some(hwnd);
BOOL::from(true)
}
tracked_windows is the vector that all window ids are copied into from the static memory. Other than that what is at concern is just the call to EnumWindows and unpacking of the ids. There's a lot more code to this but it's proprietary and application specific.
fn main() -> () {
let mut tracked_windows = vec![];
unsafe {
EnumWindows(Some(enumeration_callback), LPARAM(*&0)).expect("Failed to get windows");
for x in HWNDS_COLLECTION {
match x {
None => {}
Some(y) => {
match query_window(y) {
true => {tracked_windows.push(y)}
false => {}
}
}
}
}
}
}
I tried adding a print statement into the callback to print the title of the window as it was collected and it only received one, this would imply to me that it's enumerating over the single top level window which I don't see being useful at all and not what is implied by the documentation. I want to know what this function does. I'd like to know what I'm doing or what I need to do but those are not the question that I'm asking and aren't useful.
enumwindows does not detect windows looks like a duplicate from the title, but the solution there was simply returning false which my code does not (unless BOOL::from(true) somehow gets interpreted as false due to magic).