Maybe like this:
[DllImport( "user32" )]
static extern bool IsWindowEnabled( IntPtr hWnd );
. . .
bool is_dialog_opened = Process.GetProcessesByName( "WINWORD" ).Any( p => !IsWindowEnabled( p.MainWindowHandle ) );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
If a dialog is open in Word then certain methods will fail, example below. We can get round this if there is a document open wrapping the call into an error handler but if no documents are open this cannot be done (I don't want to randomly open a temporary new document to test because if a dialog is open we cannot close the new document it for the same reason).
Microsoft.Office.Interop.Word.WdProtectionType ProtectionType = document.ProtectionType;
This is a problem because we do not want to open a document if we cannot control things like ProtectionType (these are confidential clinical documents so control is critical).
Dialogs are a window (not a Microsoft.Office.Interop.Word.Window) and Dialog objects do not have a "state" and there does not appear to be a collection of open dialogs.
The parent handle of a Dialog appears to be Desktop so iterating through all windows and checking the title can't work because Dialogs share the same title in some cases as other applcation's windows, eg "File Save".
After weeks of research and testing and posting some other forums I am fairly sure that there really is no way to check for open Dialogs unless there is an existing document open in Word.
Does anyone know how to check for open Dialogs or am I correct and it is impossible?
Regards,
Charles
Maybe like this:
[DllImport( "user32" )]
static extern bool IsWindowEnabled( IntPtr hWnd );
. . .
bool is_dialog_opened = Process.GetProcessesByName( "WINWORD" ).Any( p => !IsWindowEnabled( p.MainWindowHandle ) );