1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation
8 using System.Activities.Presentation.View;
9 using System.Windows.Interop;
10 using System.Windows.Input;
11 using System.ComponentModel;
12 using Microsoft.Tools.Common;
14 internal class DialogWindow : Window
16 public static readonly DependencyProperty ContextProperty =
17 DependencyProperty.Register("Context",
18 typeof(EditingContext),
19 typeof(DialogWindow));
21 string helpKeyword = HelpKeywords.HomePage;
23 public EditingContext Context
25 get { return (EditingContext)GetValue(ContextProperty); }
26 set { SetValue(ContextProperty, value); }
29 protected string HelpKeyword
33 return this.helpKeyword;
37 this.helpKeyword = value;
41 protected override void OnSourceInitialized(EventArgs e)
43 base.OnSourceInitialized(e);
45 this.HideMinMaxButton();
46 this.ShowContextHelpButton();
48 this.AddWindowsHook(OnHookedWindowMessage);
49 this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Help, new ExecutedRoutedEventHandler(OnHelpExecuted)));
50 this.Closing += new CancelEventHandler(OnWindowClosing);
53 static IntPtr OnHookedWindowMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
55 if (msg == Win32Interop.WM_SYSCOMMAND && wParam.ToInt64() == (long)Win32Interop.SC_CONTEXTHELP)
57 var rootVisual = HwndSource.FromHwnd(hwnd).RootVisual;
58 var focusedElement = FocusManager.GetFocusedElement(rootVisual);
59 if (focusedElement == null)
61 focusedElement = rootVisual as IInputElement;
63 ApplicationCommands.Help.Execute(null, focusedElement);
67 // According to MSDN, zero should be returned after handling WM_SYSCOMMAND.
68 // If this message is unhandled, it's still safe to return zero
69 // because WPF framework (HwndSource) will return zero anyway if the
70 // message is unhandled.
74 void OnWindowClosing(object sender, CancelEventArgs e)
76 // Note: Do NOT remove the hook if the close operation needs to be canceled.
77 this.RemoveWindowsHook(OnHookedWindowMessage);
80 void OnHelpExecuted(Object sender, ExecutedRoutedEventArgs e)
82 if (this.Context != null)
84 IIntegratedHelpService help = this.Context.Services.GetService<IIntegratedHelpService>();
87 help.ShowHelpFromKeyword(this.helpKeyword);
91 System.Diagnostics.Process.Start(SR.DefaultHelpUrl);