Ookii-dialogs-wpf: Pass Win32 Window Handle to ShowDialog()

Created on 28 Oct 2020  ·  9Comments  ·  Source: ookii-dialogs/ookii-dialogs-wpf

I'd like to pass a Win32 Window Handle (e. g. from Microsoft Word, Excel or Outlook) into TaskDialog.ShowDialog(). For this, it seems to be sufficient to make TaskDialog.ShowDialog(IntPtr owner) public instead of private.

What do you think about making this method public? I could provide a PR if you want.

Thanks!

All 9 comments

Hi @mu88, in principle I'm OK with that change if there are scenarios where GetActiveWindow returns the handle to an incorrect window IntPtr - is that the case?

Are using the TaskDialog from within an Excel add-in or similar?

If so, does passing a null to Task.ShowDialog(Window) get wrong owner handle?

Thanks for getting back so quickly, @augustoproiete !

We're developing a WPF application. This application communicates with Excel via COM and retrieves Excel's window handle as IntPtr via Process.MainWindowHandle. Now we want to show a custom TaskDialog within Excel - so the dialog's owner has to be Excel's window handle. So in our case, there is no WPF window that can act as owner since Excel is not based on WPF.

I gave it a try by calling private TaskDialogButton ShowDialog(IntPtr owner) via reflection and it works like a charme.

Sounds good. I'll take PR then if you're up for it.

Bonus points if you can add the same overload to the other dialogs too, for consistency.

Yes I'll go for this PR

Closed via #19

Can you please create a new version for NuGet, @augustoproiete ?

Sure @mu88. I'll push a new vesion to nuget.org by tomorrow evening

@mu88 NuGet package published to nuget.org - https://www.nuget.org/packages/Ookii.Dialogs.Wpf/1.2.0

Thank you @augustoproiete ! I've integrated the new package and it works like a charm 🥳

Was this page helpful?
0 / 5 - 0 ratings