ookii-dialogs / ookii-dialogs-wpf

Awesome dialogs for Windows Desktop applications built with Microsoft .NET (WPF)
BSD 3-Clause "New" or "Revised" License
1.14k stars 85 forks source link

Pass Win32 Window Handle to ShowDialog() #18

Closed mu88 closed 3 years ago

mu88 commented 3 years ago

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!

augustoproiete commented 3 years ago

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?

mu88 commented 3 years ago

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.

augustoproiete commented 3 years ago

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.

mu88 commented 3 years ago

Yes I'll go for this PR

augustoproiete commented 3 years ago

Closed via #19

mu88 commented 3 years ago

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

augustoproiete commented 3 years ago

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

augustoproiete commented 3 years ago

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

mu88 commented 3 years ago

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