microsoft / Windows.UI.Composition-Win32-Samples

Windows.UI.Composition Win32 Samples
MIT License
459 stars 186 forks source link

Cannot catch errors in CreateCaptureItemForWindow #126

Open rjx-ray opened 8 months ago

rjx-ray commented 8 months ago

Whillst developing our app we are sometimes mistakenly passing a handle for a window that cannot be captured through to CreateCaptureItemForWindow (eg a child window). I am trying to catch and debug such errors, but the catch never works, instead I get an exception. This is my current code and the exception:

image

We hope to eliminate all such errors but if it happens in future we would like to catch rather than crash.

How can I do that?

I'm using VS2022 under Windows 11 V23H2

robmikh commented 8 months ago

There was a bug in earlier versions of Windows which would cause this behavior. However it should be patched in the latest Windows 10 and 11 releases.

Which version of Windows are you seeing this on? Could you provide the OS build number from the About section in the Settings app?

robmikh commented 8 months ago

Oh sorry, I didn't see the last sentence. This shouldn't happen in Win11... I'll see if I can repro.

rjx-ray commented 8 months ago

Thanks for looking at this. I need to build my own list of windows that can be captured, using IsAltTabWindow to filter the enumeration. But some are sneaking through, eg this Chrome popup image and this spy++ properties window.

image

They are not shown by GraphicsCapturePicker, is that filtering on a different basis? I'm concerned that I'm just playing whack-a-mole right now.

I'm thinking about also filtering out popups, but do you think that might exclude any windows that should be be included?