I'm working on an application which prints a report using the Microsoft XPS Document Writer driver. If the user attempts to overwrite a file which is open, the driver pops up an error dialog that the user doesn't have permission to save. However, on one QA's machine, the popup dialog never shows up. I want the application to popup its own error dialog, but only if the driver's error dialog doesn't popup. How do I detect whether or not the driver's error dialog popped up??
Don't let the error propogate that far?
Ask for the name of the file, detect it's (non)existance, show your own error, pass the document to the printer.
To test whether a Window exists, you might use something like the FindWindow function or the EnumWindows function and EnumChildWindows function.
I don't think this is something that you can get 100% right. Barring some API you don't know about, the only way to tell if the dialog showed up is to screen scrape. That is, look at the active set of windows and see if one has the title / message indicating the error dialog popped up.
That approach has several problems though. The first is that it generates false positives. You could be tricked by a similar dialog withu a similar name.
Also there's no guarantee your code would run before the user closed the dialog. Hence you could end up deciding the dialog didn't show up in cases where it actually did.